Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Jan 15, 2025
1 parent fcd0962 commit 7866959
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
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
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

0 comments on commit 7866959

Please sign in to comment.