[FEAT]Add Option to hide Release Archive links (#3139)

This adds a new options to releases to hide the links to the automatically generated archives. This is useful, when the automatically generated Archives are broken e.g. because of Submodules.

![grafik](/attachments/5686edf6-f318-4175-8459-89c33973b181)
![grafik](/attachments/74a8bf92-2abb-47a0-876d-d41024770d0b)

Note:
This juts hides the Archives from the UI. Users can still download 5the Archive if they know t correct URL.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3139
Reviewed-by: Otto <otto@codeberg.org>
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
Co-authored-by: JakobDev <jakobdev@gmx.de>
Co-committed-by: JakobDev <jakobdev@gmx.de>
This commit is contained in:
JakobDev 2024-04-24 15:15:55 +00:00 committed by Earl Warren
parent 6bcaf4f875
commit 1bce2dc5c5
14 changed files with 220 additions and 106 deletions

View file

@ -133,14 +133,18 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
assert.Equal(t, newRelease.TagName, release.TagName)
assert.Equal(t, newRelease.Title, release.Title)
assert.Equal(t, newRelease.Note, release.Note)
assert.False(t, newRelease.HideArchiveLinks)
hideArchiveLinks := true
req = NewRequestWithJSON(t, "PATCH", urlStr, &api.EditReleaseOption{
TagName: release.TagName,
Title: release.Title,
Note: "updated",
IsDraft: &release.IsDraft,
IsPrerelease: &release.IsPrerelease,
Target: release.Target,
TagName: release.TagName,
Title: release.Title,
Note: "updated",
IsDraft: &release.IsDraft,
IsPrerelease: &release.IsPrerelease,
Target: release.Target,
HideArchiveLinks: &hideArchiveLinks,
}).AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
@ -152,6 +156,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
}
unittest.AssertExistsAndLoadBean(t, rel)
assert.EqualValues(t, rel.Note, newRelease.Note)
assert.True(t, newRelease.HideArchiveLinks)
}
func TestAPICreateReleaseToDefaultBranch(t *testing.T) {

View file

@ -9,15 +9,19 @@ import (
"testing"
"time"
auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/translation"
"code.gitea.io/gitea/tests"
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title string, preRelease, draft bool) {
@ -307,3 +311,34 @@ func TestDownloadReleaseAttachment(t *testing.T) {
session := loginUser(t, "user2")
session.MakeRequest(t, req, http.StatusOK)
}
func TestReleaseHideArchiveLinksUI(t *testing.T) {
defer tests.PrepareTestEnv(t)()
release := unittest.AssertExistsAndLoadBean(t, &repo_model.Release{TagName: "v2.0"})
require.NoError(t, release.LoadAttributes(db.DefaultContext))
session := loginUser(t, release.Repo.OwnerName)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
zipURL := fmt.Sprintf("%s/archive/%s.zip", release.Repo.Link(), release.TagName)
tarGzURL := fmt.Sprintf("%s/archive/%s.tar.gz", release.Repo.Link(), release.TagName)
resp := session.MakeRequest(t, NewRequest(t, "GET", release.HTMLURL()), http.StatusOK)
body := resp.Body.String()
assert.Contains(t, body, zipURL)
assert.Contains(t, body, tarGzURL)
hideArchiveLinks := true
req := NewRequestWithJSON(t, "PATCH", release.APIURL(), &api.EditReleaseOption{
HideArchiveLinks: &hideArchiveLinks,
}).AddTokenAuth(token)
MakeRequest(t, req, http.StatusOK)
resp = session.MakeRequest(t, NewRequest(t, "GET", release.HTMLURL()), http.StatusOK)
body = resp.Body.String()
assert.NotContains(t, body, zipURL)
assert.NotContains(t, body, tarGzURL)
}