diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-07-08 11:19:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-08 05:19:00 +0200 |
commit | 6375419468edc95fdfac94aac3b0e10b23743557 (patch) | |
tree | e104617051a314fa33e62ebcf7c149d0d0434b82 /models/repo | |
parent | e0a780d75b79233ceb97116b9ae8563a9942aff9 (diff) | |
download | gitea-6375419468edc95fdfac94aac3b0e10b23743557.tar.gz gitea-6375419468edc95fdfac94aac3b0e10b23743557.zip |
Newly pushed branches hints on repository home page (#25715)
This PR will display a pull request creation hint on the repository home
page when there are newly created branches with no pull request. Only
the recent 6 hours and 2 updated branches will be displayed.
Inspired by #14003
Replace #14003
Resolves #311
Resolves #13196
Resolves #23743
co-authored by @kolaente
Diffstat (limited to 'models/repo')
-rw-r--r-- | models/repo/repo.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/models/repo/repo.go b/models/repo/repo.go index b7c02057c2..3d1f2dcfa8 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -528,6 +528,18 @@ func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) strin return fmt.Sprintf("%s/%s/compare/%s...%s", url.PathEscape(repo.OwnerName), url.PathEscape(repo.Name), util.PathEscapeSegments(oldCommitID), util.PathEscapeSegments(newCommitID)) } +func (repo *Repository) ComposeBranchCompareURL(baseRepo *Repository, branchName string) string { + if baseRepo == nil { + baseRepo = repo + } + var cmpBranchEscaped string + if repo.ID != baseRepo.ID { + cmpBranchEscaped = fmt.Sprintf("%s/%s:", url.PathEscape(repo.OwnerName), url.PathEscape(repo.Name)) + } + cmpBranchEscaped = fmt.Sprintf("%s%s", cmpBranchEscaped, util.PathEscapeSegments(branchName)) + return fmt.Sprintf("%s/compare/%s...%s", baseRepo.Link(), util.PathEscapeSegments(baseRepo.DefaultBranch), cmpBranchEscaped) +} + // IsOwnedBy returns true when user owns this repository func (repo *Repository) IsOwnedBy(userID int64) bool { return repo.OwnerID == userID |