0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-28 02:14:06 -05:00

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 <forgejo@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2024-02-27 13:15:44 +01:00
parent 3fa4962a88
commit fc635f1014
No known key found for this signature in database
2 changed files with 32 additions and 0 deletions

View file

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

View file

@ -1,9 +1,11 @@
// Copyright 2021 The Gitea Authors. All rights reserved. // 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 // SPDX-License-Identifier: MIT
package integration package integration
import ( import (
"net/http"
"net/url" "net/url"
"testing" "testing"
@ -20,6 +22,34 @@ import (
"github.com/stretchr/testify/assert" "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) { func TestCreateNewTagProtected(t *testing.T) {
defer tests.PrepareTestEnv(t)() defer tests.PrepareTestEnv(t)()