summaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authorJonathan Tran <jonnytran@gmail.com>2021-05-07 17:10:05 -0400
committerGitHub <noreply@github.com>2021-05-07 23:10:05 +0200
commit9557b8603aa05458a9b262d254a809d083657e62 (patch)
tree25abc1db9983b7cc3ccc1c7e1d3e75a015022d91 /routers/repo
parent4900881924b3762e10b01d67565035faf7cb02da (diff)
downloadgitea-9557b8603aa05458a9b262d254a809d083657e62.tar.gz
gitea-9557b8603aa05458a9b262d254a809d083657e62.zip
Add selecting tags on the compare page (#15723)
* Add selecting tags on the compare page * Remove unused condition and change indentation * Fix tag tab in dropdown to be black * Add compare tag integration test Co-authored-by: Jonathan Tran <jon@allspice.io>
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/compare.go53
1 files changed, 37 insertions, 16 deletions
diff --git a/routers/repo/compare.go b/routers/repo/compare.go
index a658374d9b..d02ea0b160 100644
--- a/routers/repo/compare.go
+++ b/routers/repo/compare.go
@@ -391,7 +391,7 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
if rootRepo != nil &&
rootRepo.ID != headRepo.ID &&
rootRepo.ID != baseRepo.ID {
- perm, branches, err := getBranchesForRepo(ctx.User, rootRepo)
+ perm, branches, tags, err := getBranchesAndTagsForRepo(ctx.User, rootRepo)
if err != nil {
ctx.ServerError("GetBranchesForRepo", err)
return nil, nil, nil, nil, "", ""
@@ -399,19 +399,20 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
if perm {
ctx.Data["RootRepo"] = rootRepo
ctx.Data["RootRepoBranches"] = branches
+ ctx.Data["RootRepoTags"] = tags
}
}
// If we have a ownForkRepo and it's different from:
// 1. The computed base
- // 2. The computed hea
+ // 2. The computed head
// 3. The rootRepo (if we have one)
// then get the branches from it.
if ownForkRepo != nil &&
ownForkRepo.ID != headRepo.ID &&
ownForkRepo.ID != baseRepo.ID &&
(rootRepo == nil || ownForkRepo.ID != rootRepo.ID) {
- perm, branches, err := getBranchesForRepo(ctx.User, ownForkRepo)
+ perm, branches, tags, err := getBranchesAndTagsForRepo(ctx.User, ownForkRepo)
if err != nil {
ctx.ServerError("GetBranchesForRepo", err)
return nil, nil, nil, nil, "", ""
@@ -419,6 +420,7 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
if perm {
ctx.Data["OwnForkRepo"] = ownForkRepo
ctx.Data["OwnForkRepoBranches"] = branches
+ ctx.Data["OwnForkRepoTags"] = tags
}
}
@@ -572,25 +574,29 @@ func PrepareCompareDiff(
return false
}
-func getBranchesForRepo(user *models.User, repo *models.Repository) (bool, []string, error) {
+func getBranchesAndTagsForRepo(user *models.User, repo *models.Repository) (bool, []string, []string, error) {
perm, err := models.GetUserRepoPermission(repo, user)
if err != nil {
- return false, nil, err
+ return false, nil, nil, err
}
if !perm.CanRead(models.UnitTypeCode) {
- return false, nil, nil
+ return false, nil, nil, nil
}
gitRepo, err := git.OpenRepository(repo.RepoPath())
if err != nil {
- return false, nil, err
+ return false, nil, nil, err
}
defer gitRepo.Close()
branches, _, err := gitRepo.GetBranches(0, 0)
if err != nil {
- return false, nil, err
+ return false, nil, nil, err
}
- return true, branches, nil
+ tags, err := gitRepo.GetTags()
+ if err != nil {
+ return false, nil, nil, err
+ }
+ return true, branches, tags, nil
}
// CompareDiff show different from one commit to another commit
@@ -608,14 +614,29 @@ func CompareDiff(ctx *context.Context) {
return
}
- if ctx.Data["PageIsComparePull"] == true {
- headBranches, _, err := headGitRepo.GetBranches(0, 0)
- if err != nil {
- ctx.ServerError("GetBranches", err)
- return
- }
- ctx.Data["HeadBranches"] = headBranches
+ baseGitRepo := ctx.Repo.GitRepo
+ baseTags, err := baseGitRepo.GetTags()
+ if err != nil {
+ ctx.ServerError("GetTags", err)
+ return
+ }
+ ctx.Data["Tags"] = baseTags
+ headBranches, _, err := headGitRepo.GetBranches(0, 0)
+ if err != nil {
+ ctx.ServerError("GetBranches", err)
+ return
+ }
+ ctx.Data["HeadBranches"] = headBranches
+
+ headTags, err := headGitRepo.GetTags()
+ if err != nil {
+ ctx.ServerError("GetTags", err)
+ return
+ }
+ ctx.Data["HeadTags"] = headTags
+
+ if ctx.Data["PageIsComparePull"] == true {
pr, err := models.GetUnmergedPullRequest(headRepo.ID, ctx.Repo.Repository.ID, headBranch, baseBranch)
if err != nil {
if !models.IsErrPullRequestNotExist(err) {