From fc635f101487f4ac940382c3e61acec829408491 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 27 Feb 2024 13:15:44 +0100 Subject: [PATCH 1/2] Restore the ability to view tags without a release The `repo.SingleRelease` handler was broken by gitea#29149, as the switch to `getReleaseInfos` stopped returning tags without an associated release. This resulted in the web UI showing a 404 when trying to view a tag without a release. This restores the functionality by explicitly including tags in the search, and also adds tests to exercise the fix. Signed-off-by: Gergely Nagy --- routers/web/repo/release.go | 2 ++ tests/integration/repo_tag_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index 33e7f739f..1998bd8cc 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -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, diff --git a/tests/integration/repo_tag_test.go b/tests/integration/repo_tag_test.go index 7e7790647..d2c416060 100644 --- a/tests/integration/repo_tag_test.go +++ b/tests/integration/repo_tag_test.go @@ -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,34 @@ 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()) + MakeRequest(t, req, http.StatusOK) +} + func TestCreateNewTagProtected(t *testing.T) { defer tests.PrepareTestEnv(t)() From c9b410fb354f23b14b30373cc6ca62f9052ed5cf Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 27 Feb 2024 13:19:18 +0100 Subject: [PATCH 2/2] Highlight the correct small menu item when viewing a tag When viewing a tag that isn't associated with a release, highlight the "N Tags" sub-menu item, rather than the "M releases" one. Signed-off-by: Gergely Nagy --- templates/repo/release_tag_header.tmpl | 4 ++-- tests/integration/repo_tag_test.go | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/templates/repo/release_tag_header.tmpl b/templates/repo/release_tag_header.tmpl index f474fb89e..6f3d28e7a 100644 --- a/templates/repo/release_tag_header.tmpl +++ b/templates/repo/release_tag_header.tmpl @@ -5,9 +5,9 @@
diff --git a/tests/integration/repo_tag_test.go b/tests/integration/repo_tag_test.go index d2c416060..60c73ae63 100644 --- a/tests/integration/repo_tag_test.go +++ b/tests/integration/repo_tag_test.go @@ -47,7 +47,15 @@ func TestTagViewWithoutRelease(t *testing.T) { // Test that the page loads req := NewRequestf(t, "GET", "/%s/releases/tag/no-release", repo.FullName()) - MakeRequest(t, req, http.StatusOK) + 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) {