Merge pull request 'Restore the ability to view tags without a release' (#2498) from algernon/forgejo:b/tag-view-fix into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2498
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-02-27 15:43:07 +00:00
commit d29e9374c7
3 changed files with 42 additions and 2 deletions

View file

@ -279,6 +279,8 @@ func SingleRelease(ctx *context.Context) {
releases, err := getReleaseInfos(ctx, &repo_model.FindReleasesOptions{
ListOptions: db.ListOptions{Page: 1, PageSize: 1},
RepoID: ctx.Repo.Repository.ID,
// Include tags in the search too.
IncludeTags: true,
TagNames: []string{ctx.Params("*")},
// only show draft releases for users who can write, read-only users shouldn't see draft releases.
IncludeDrafts: writeAccess,

View file

@ -5,9 +5,9 @@
<div class="gt-df">
<div class="gt-f1 gt-df gt-ac">
<h2 class="ui compact small menu header small-menu-items">
<a class="{{if .PageIsReleaseList}}active {{end}}item" href="{{.RepoLink}}/releases">{{ctx.Locale.PrettyNumber .NumReleases}} {{ctx.Locale.TrN .NumReleases "repo.release" "repo.releases"}}</a>
<a class="{{if and .PageIsReleaseList (not .PageIsSingleTag)}}active {{end}}item" href="{{.RepoLink}}/releases">{{ctx.Locale.PrettyNumber .NumReleases}} {{ctx.Locale.TrN .NumReleases "repo.release" "repo.releases"}}</a>
{{if $canReadCode}}
<a class="{{if .PageIsTagList}}active {{end}}item" href="{{.RepoLink}}/tags">{{ctx.Locale.PrettyNumber .NumTags}} {{ctx.Locale.TrN .NumTags "repo.tag" "repo.tags"}}</a>
<a class="{{if or .PageIsTagList .PageIsSingleTag}}active {{end}}item" href="{{.RepoLink}}/tags">{{ctx.Locale.PrettyNumber .NumTags}} {{ctx.Locale.TrN .NumTags "repo.tag" "repo.tags"}}</a>
{{end}}
</h2>
</div>

View file

@ -1,9 +1,11 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"net/http"
"net/url"
"testing"
@ -20,6 +22,42 @@ import (
"github.com/stretchr/testify/assert"
)
func TestTagViewWithoutRelease(t *testing.T) {
defer tests.PrepareTestEnv(t)()
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
defer func() {
releases, err := db.Find[repo_model.Release](db.DefaultContext, repo_model.FindReleasesOptions{
IncludeTags: true,
TagNames: []string{"no-release"},
RepoID: repo.ID,
})
assert.NoError(t, err)
for _, release := range releases {
_, err = db.DeleteByID[repo_model.Release](db.DefaultContext, release.ID)
assert.NoError(t, err)
}
}()
err := release.CreateNewTag(git.DefaultContext, owner, repo, "master", "no-release", "release-less tag")
assert.NoError(t, err)
// Test that the page loads
req := NewRequestf(t, "GET", "/%s/releases/tag/no-release", repo.FullName())
resp := MakeRequest(t, req, http.StatusOK)
// Test that the tags sub-menu is active
htmlDoc := NewHTMLParser(t, resp.Body)
htmlDoc.AssertElement(t, ".small-menu-items .active.item[href*='/tags']", true)
// Test that the release sub-menu isn't active
releaseLink := htmlDoc.Find(".small-menu-items .item[href*='/releases']")
assert.False(t, releaseLink.HasClass("active"))
}
func TestCreateNewTagProtected(t *testing.T) {
defer tests.PrepareTestEnv(t)()