Skip to content

Commit f6dbf0e

Browse files
authored
Fix incorrect TagName/BranchName usages (#33279)
Add add a new test
1 parent fcd0962 commit f6dbf0e

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

routers/web/repo/release.go

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ func SingleRelease(ctx *context.Context) {
295295
}
296296

297297
ctx.Data["PageIsSingleTag"] = release.IsTag
298+
ctx.Data["SingleReleaseTagName"] = release.TagName
298299
if release.IsTag {
299300
ctx.Data["Title"] = release.TagName
300301
} else {

routers/web/repo/search.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func Search(ctx *context.Context) {
7070
res, err := git.GrepSearch(ctx, ctx.Repo.GitRepo, prepareSearch.Keyword, git.GrepOptions{
7171
ContextLineNumber: 1,
7272
IsFuzzy: prepareSearch.IsFuzzy,
73-
RefName: git.RefNameFromBranch(ctx.Repo.BranchName).String(), // BranchName should be default branch or the first existing branch
73+
RefName: git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch).String(), // BranchName should be default branch or the first existing branch
7474
PathspecList: indexSettingToGitGrepPathspecList(),
7575
})
7676
if err != nil {

routers/web/web.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ func registerRoutes(m *web.Router) {
15921592
m.Get("/watchers", repo.Watchers)
15931593
m.Get("/search", reqUnitCodeReader, repo.Search)
15941594
m.Post("/action/{action}", reqSignIn, repo.Action)
1595-
}, optSignIn, context.RepoAssignment, context.RepoRef())
1595+
}, optSignIn, context.RepoAssignment)
15961596

15971597
common.AddOwnerRepoGitLFSRoutes(m, optSignInIgnoreCsrf, lfsServerEnabled) // "/{username}/{reponame}/{lfs-paths}": git-lfs support
15981598

services/context/repo.go

-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ type Repository struct {
5656
// RefFullName is the full ref name that the user is viewing
5757
RefFullName git.RefName
5858
BranchName string // it is the RefFullName's short name if its type is "branch"
59-
TagName string // it is the RefFullName's short name if its type is "tag"
6059
TreePath string
6160

6261
// Commit it is always set to the commit for the branch or tag, or just the commit that the user is viewing
@@ -851,7 +850,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
851850
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
852851
} else if refType == git.RefTypeTag && ctx.Repo.GitRepo.IsTagExist(refShortName) {
853852
ctx.Repo.RefFullName = git.RefNameFromTag(refShortName)
854-
ctx.Repo.TagName = refShortName
855853

856854
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refShortName)
857855
if err != nil {
@@ -901,8 +899,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
901899

902900
ctx.Data["BranchName"] = ctx.Repo.BranchName
903901

904-
ctx.Data["TagName"] = ctx.Repo.TagName
905-
906902
ctx.Data["CommitID"] = ctx.Repo.CommitID
907903

908904
ctx.Data["CanCreateBranch"] = ctx.Repo.CanCreateBranch() // only used by the branch selector dropdown: AllowCreateNewRef

templates/repo/release_tag_header.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</a>
1818
{{end}}
1919
{{if and (not .PageIsTagList) .CanCreateRelease}}
20-
<a class="ui small primary button" href="{{$.RepoLink}}/releases/new{{if .PageIsSingleTag}}?tag={{.TagName}}{{end}}">
20+
<a class="ui small primary button" href="{{$.RepoLink}}/releases/new{{if .PageIsSingleTag}}?tag={{.SingleReleaseTagName}}{{end}}">
2121
{{ctx.Locale.Tr "repo.release.new_release"}}
2222
</a>
2323
{{end}}

tests/integration/release_test.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,25 @@ func TestViewReleaseListNoLogin(t *testing.T) {
173173
}, commitsToMain)
174174
}
175175

176-
func TestViewSingleReleaseNoLogin(t *testing.T) {
176+
func TestViewSingleRelease(t *testing.T) {
177177
defer tests.PrepareTestEnv(t)()
178178

179-
req := NewRequest(t, "GET", "/user2/repo-release/releases/tag/v1.0")
180-
resp := MakeRequest(t, req, http.StatusOK)
181-
182-
htmlDoc := NewHTMLParser(t, resp.Body)
183-
// check the "number of commits to main since this release"
184-
releaseList := htmlDoc.doc.Find("#release-list .ahead > a")
185-
assert.EqualValues(t, 1, releaseList.Length())
186-
assert.EqualValues(t, "3 commits", releaseList.First().Text())
179+
t.Run("NoLogin", func(t *testing.T) {
180+
req := NewRequest(t, "GET", "/user2/repo-release/releases/tag/v1.0")
181+
resp := MakeRequest(t, req, http.StatusOK)
182+
htmlDoc := NewHTMLParser(t, resp.Body)
183+
// check the "number of commits to main since this release"
184+
releaseList := htmlDoc.doc.Find("#release-list .ahead > a")
185+
assert.EqualValues(t, 1, releaseList.Length())
186+
assert.EqualValues(t, "3 commits", releaseList.First().Text())
187+
})
188+
t.Run("Login", func(t *testing.T) {
189+
session := loginUser(t, "user1")
190+
req := NewRequest(t, "GET", "/user2/repo1/releases/tag/delete-tag") // "delete-tag" is the only one with is_tag=true (although strange name)
191+
resp := session.MakeRequest(t, req, http.StatusOK)
192+
// the New Release button should contain the tag name
193+
assert.Contains(t, resp.Body.String(), `<a class="ui small primary button" href="/user2/repo1/releases/new?tag=delete-tag">`)
194+
})
187195
}
188196

189197
func TestViewReleaseListLogin(t *testing.T) {

0 commit comments

Comments
 (0)