diff options
author | Earl Warren <109468362+earl-warren@users.noreply.github.com> | 2023-08-24 12:36:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-24 10:36:10 +0000 |
commit | a9ce570298d4541bc1b5598dc080d9e4541de17b (patch) | |
tree | 41be5a2f94a0582c4d56a1ede7a7d57b820b91c8 /services/convert | |
parent | b21b63c61ac1038a1597acee45084896f5e39a3a (diff) | |
download | gitea-a9ce570298d4541bc1b5598dc080d9e4541de17b.tar.gz gitea-a9ce570298d4541bc1b5598dc080d9e4541de17b.zip |
add Upload URL to release API (#26663)
- Resolves https://codeberg.org/forgejo/forgejo/issues/580
- Return a `upload_field` to any release API response, which points to
the API URL for uploading new assets.
- Adds unit test.
- Adds integration testing to verify URL is returned correctly and that
upload endpoint actually works
---------
Co-authored-by: Gusted <postmaster@gusted.xyz>
Diffstat (limited to 'services/convert')
-rw-r--r-- | services/convert/release.go | 1 | ||||
-rw-r--r-- | services/convert/release_test.go | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/services/convert/release.go b/services/convert/release.go index d8aa46d432..bfff53e62f 100644 --- a/services/convert/release.go +++ b/services/convert/release.go @@ -22,6 +22,7 @@ func ToAPIRelease(ctx context.Context, repo *repo_model.Repository, r *repo_mode HTMLURL: r.HTMLURL(), TarURL: r.TarURL(), ZipURL: r.ZipURL(), + UploadURL: r.APIUploadURL(), IsDraft: r.IsDraft, IsPrerelease: r.IsPrerelease, CreatedAt: r.CreatedUnix.AsTime(), diff --git a/services/convert/release_test.go b/services/convert/release_test.go new file mode 100644 index 0000000000..201b27e16d --- /dev/null +++ b/services/convert/release_test.go @@ -0,0 +1,28 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package convert + +import ( + "testing" + + "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/models/unittest" + + "github.com/stretchr/testify/assert" +) + +func TestRelease_ToRelease(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + + repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) + release1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Release{ID: 1}) + release1.LoadAttributes(db.DefaultContext) + + apiRelease := ToAPIRelease(db.DefaultContext, repo1, release1) + assert.NotNil(t, apiRelease) + assert.EqualValues(t, 1, apiRelease.ID) + assert.EqualValues(t, "https://try.gitea.io/api/v1/repos/user2/repo1/releases/1", apiRelease.URL) + assert.EqualValues(t, "https://try.gitea.io/api/v1/repos/user2/repo1/releases/1/assets", apiRelease.UploadURL) +} |