1
1
mirror of https://github.com/go-gitea/gitea synced 2025-01-18 13:44:27 +00:00

Fix incorrect TagName/BranchName usages (#33279)

Add add a new test
This commit is contained in:
wxiaoguang 2025-01-15 17:34:55 +08:00 committed by GitHub
parent fcd096231a
commit f6dbf0e7b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 21 additions and 16 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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

View File

@ -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
@ -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 {
@ -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

View File

@ -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}}

View File

@ -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) {