mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-24 05:33:40 +09:00
chore: repo compare link (#39088)
Signed-off-by: silverwind <me@silverwind.io> Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -65,14 +65,24 @@ func (prc *PullRequestContext) CanCreateNewPull() bool {
|
||||
}
|
||||
|
||||
// CompareHeadRef formats the head side of a compare link, "owner/repo:branch" is only needed when a fork can share its base repo's owner
|
||||
func CompareHeadRef(headRepo *repo_model.Repository, headBranch string) string {
|
||||
return util.Iif(setting.Repository.AllowForkIntoSameOwner, headRepo.FullName(), headRepo.OwnerName) + ":" + headBranch
|
||||
func CompareHeadRef(baseRepo, headRepo *repo_model.Repository, headBranch string) string {
|
||||
if baseRepo.ID == headRepo.ID /* same repo */ {
|
||||
return headBranch
|
||||
} else if baseRepo.OwnerID == headRepo.OwnerID /* same owner */ {
|
||||
return headRepo.FullName() + ":" + headBranch
|
||||
}
|
||||
// not the same owner: if there can be multiple forks in one owner, we still need the full name
|
||||
if setting.Repository.AllowForkIntoSameOwner {
|
||||
return headRepo.FullName() + ":" + headBranch
|
||||
}
|
||||
// if there is only one fork in the different owner, we only need the owner's name for the head ref
|
||||
return headRepo.OwnerName + ":" + headBranch
|
||||
}
|
||||
|
||||
func (prc *PullRequestContext) MakeDefaultCompareLink(headBranch string) string {
|
||||
return prc.baseRepo.Link() + "/compare/" +
|
||||
util.PathEscapeSegments(prc.DefaultTargetBranch()) + "..." +
|
||||
util.PathEscapeSegments(util.Iif(prc.SameRepo(), headBranch, CompareHeadRef(prc.headRepo, headBranch)))
|
||||
util.PathEscapeSegments(CompareHeadRef(prc.baseRepo, prc.headRepo, headBranch))
|
||||
}
|
||||
|
||||
func (prc *PullRequestContext) DefaultTargetBranch() string {
|
||||
|
||||
Reference in New Issue
Block a user