Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect TagName/BranchName usages #33279

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions routers/web/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ func SingleRelease(ctx *context.Context) {
}

ctx.Data["PageIsSingleTag"] = release.IsTag
ctx.Data["SingleReleaseTagName"] = release.TagName
if release.IsTag {
ctx.Data["Title"] = release.TagName
} else {
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Search(ctx *context.Context) {
res, err := git.GrepSearch(ctx, ctx.Repo.GitRepo, prepareSearch.Keyword, git.GrepOptions{
ContextLineNumber: 1,
IsFuzzy: prepareSearch.IsFuzzy,
RefName: git.RefNameFromBranch(ctx.Repo.BranchName).String(), // BranchName should be default branch or the first existing branch
RefName: git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch).String(), // BranchName should be default branch or the first existing branch
PathspecList: indexSettingToGitGrepPathspecList(),
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ func registerRoutes(m *web.Router) {
m.Get("/watchers", repo.Watchers)
m.Get("/search", reqUnitCodeReader, repo.Search)
m.Post("/action/{action}", reqSignIn, repo.Action)
}, optSignIn, context.RepoAssignment, context.RepoRef())
}, optSignIn, context.RepoAssignment)

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

Expand Down
4 changes: 0 additions & 4 deletions services/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ type Repository struct {
// RefFullName is the full ref name that the user is viewing
RefFullName git.RefName
BranchName string // it is the RefFullName's short name if its type is "branch"
TagName string // it is the RefFullName's short name if its type is "tag"
TreePath string

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

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

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

ctx.Data["TagName"] = ctx.Repo.TagName

ctx.Data["CommitID"] = ctx.Repo.CommitID

ctx.Data["CanCreateBranch"] = ctx.Repo.CanCreateBranch() // only used by the branch selector dropdown: AllowCreateNewRef
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/release_tag_header.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</a>
{{end}}
{{if and (not .PageIsTagList) .CanCreateRelease}}
<a class="ui small primary button" href="{{$.RepoLink}}/releases/new{{if .PageIsSingleTag}}?tag={{.TagName}}{{end}}">
<a class="ui small primary button" href="{{$.RepoLink}}/releases/new{{if .PageIsSingleTag}}?tag={{.SingleReleaseTagName}}{{end}}">
{{ctx.Locale.Tr "repo.release.new_release"}}
</a>
{{end}}
Expand Down
26 changes: 17 additions & 9 deletions tests/integration/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,25 @@ func TestViewReleaseListNoLogin(t *testing.T) {
}, commitsToMain)
}

func TestViewSingleReleaseNoLogin(t *testing.T) {
func TestViewSingleRelease(t *testing.T) {
defer tests.PrepareTestEnv(t)()

req := NewRequest(t, "GET", "/user2/repo-release/releases/tag/v1.0")
resp := MakeRequest(t, req, http.StatusOK)

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

func TestViewReleaseListLogin(t *testing.T) {
Expand Down
Loading