Add DeleteRepoTag function (#461)

add DeleteRepoTag()

fixes #441

add test

didnt run them yet 🙃

Co-authored-by: Norwin Roosen <git@nroo.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/461
Reviewed-by: 6543 <6543@obermui.de>
Reviewed-by: khmarbaise <khmarbaise@noreply.gitea.io>
Co-Authored-By: Norwin <noerw@noreply.gitea.io>
Co-Committed-By: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
Norwin 2020-12-10 02:08:22 +08:00 committed by 6543
parent fa7edc6f46
commit 68eec69f47
3 changed files with 23 additions and 1 deletions

View file

@ -124,7 +124,7 @@ func (c *Client) EditRelease(user, repo string, id int64, form EditReleaseOption
return r, resp, err
}
// DeleteRelease delete a release from a repository
// DeleteRelease delete a release from a repository, keeping its tag
func (c *Client) DeleteRelease(user, repo string, id int64) (*Response, error) {
_, resp, err := c.getResponse("DELETE",
fmt.Sprintf("/repos/%s/%s/releases/%d", user, repo, id),
@ -132,6 +132,17 @@ func (c *Client) DeleteRelease(user, repo string, id int64) (*Response, error) {
return resp, err
}
// DeleteReleaseTag deletes a tag from a repository, if no release refers to it.
func (c *Client) DeleteReleaseTag(user, repo string, tag string) (*Response, error) {
if err := c.checkServerVersionGreaterThanOrEqual(version1_14_0); err != nil {
return nil, err
}
_, resp, err := c.getResponse("DELETE",
fmt.Sprintf("/repos/%s/%s/releases/tags/%s", user, repo, tag),
nil, nil)
return resp, err
}
// fallbackGetReleaseByTag is fallback for old gitea installations ( < 1.13.0 )
func (c *Client) fallbackGetReleaseByTag(user, repo string, tag string) (*Release, *Response, error) {
for i := 1; ; i++ {

View file

@ -74,6 +74,16 @@ func TestRelease(t *testing.T) {
assert.NoError(t, err)
rl, _, _ = c.ListReleases(repo.Owner.UserName, repo.Name, ListReleasesOptions{})
assert.Len(t, rl, 0)
tags, _, err := c.ListRepoTags(repo.Owner.UserName, repo.Name, ListRepoTagsOptions{})
assert.NoError(t, err)
assert.Len(t, tags, 1)
// DeleteReleaseTag
_, err = c.DeleteReleaseTag(repo.Owner.UserName, repo.Name, r.TagName)
assert.NoError(t, err)
tags, _, err = c.ListRepoTags(repo.Owner.UserName, repo.Name, ListRepoTagsOptions{})
assert.NoError(t, err)
assert.Len(t, tags, 0)
// Test Response if try to get not existing release
_, resp, err := c.GetRelease(repo.Owner.UserName, repo.Name, 1234)

View file

@ -41,6 +41,7 @@ var (
version1_11_0, _ = version.NewVersion("1.11.0")
version1_12_0, _ = version.NewVersion("1.12.0")
version1_13_0, _ = version.NewVersion("1.13.0")
version1_14_0, _ = version.NewVersion("1.14.0")
)
// checkServerVersionGreaterThanOrEqual is internally used to speed up things and ignore issues with prerelease