Add DeleteTag & Correct DeleteReleaseByTag (#488)
* Add DeleteTag + Tests * Correct DeleteReleaseByTag func + Tests this is because of https://github.com/go-gitea/gitea/pull/14563 witch fixed unreleased inconsistency Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/488 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: khmarbaise <khmarbaise@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-committed-by: 6543 <6543@obermui.de>
This commit is contained in:
parent
fd7e38f7b5
commit
c5a981333c
4 changed files with 73 additions and 9 deletions
|
@ -133,8 +133,8 @@ func (c *Client) DeleteRelease(user, repo string, id int64) (*Response, error) {
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteReleaseTag deletes a tag from a repository, if no release refers to it.
|
// DeleteReleaseByTag deletes a release frm a repository by tag
|
||||||
func (c *Client) DeleteReleaseTag(user, repo string, tag string) (*Response, error) {
|
func (c *Client) DeleteReleaseByTag(user, repo string, tag string) (*Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_14_0); err != nil {
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_14_0); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,16 +74,22 @@ func TestRelease(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
rl, _, _ = c.ListReleases(repo.Owner.UserName, repo.Name, ListReleasesOptions{})
|
rl, _, _ = c.ListReleases(repo.Owner.UserName, repo.Name, ListReleasesOptions{})
|
||||||
assert.Len(t, rl, 0)
|
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
|
// CreateRelease
|
||||||
_, err = c.DeleteReleaseTag(repo.Owner.UserName, repo.Name, r.TagName)
|
_, _, err = c.CreateRelease(repo.Owner.UserName, repo.Name, CreateReleaseOption{
|
||||||
|
TagName: "aNewReleaseTag",
|
||||||
|
Target: "master",
|
||||||
|
Title: "Title of aNewReleaseTag",
|
||||||
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
tags, _, err = c.ListRepoTags(repo.Owner.UserName, repo.Name, ListRepoTagsOptions{})
|
|
||||||
|
// DeleteReleaseByTag
|
||||||
|
_, err = c.DeleteReleaseByTag(repo.Owner.UserName, repo.Name, "aNewReleaseTag")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, tags, 0)
|
rl, _, _ = c.ListReleases(repo.Owner.UserName, repo.Name, ListReleasesOptions{})
|
||||||
|
assert.Len(t, rl, 0)
|
||||||
|
_, err = c.DeleteReleaseByTag(repo.Owner.UserName, repo.Name, "aNewReleaseTag")
|
||||||
|
assert.Error(t, err)
|
||||||
|
|
||||||
// Test Response if try to get not existing release
|
// Test Response if try to get not existing release
|
||||||
_, resp, err := c.GetRelease(repo.Owner.UserName, repo.Name, 1234)
|
_, resp, err := c.GetRelease(repo.Owner.UserName, repo.Name, 1234)
|
||||||
|
|
|
@ -29,3 +29,14 @@ func (c *Client) ListRepoTags(user, repo string, opt ListRepoTagsOptions) ([]*Ta
|
||||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/tags?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &tags)
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/tags?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &tags)
|
||||||
return tags, resp, err
|
return tags, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteTag deletes a tag from a repository, if no release refers to it
|
||||||
|
func (c *Client) DeleteTag(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/tags/%s", user, repo, tag),
|
||||||
|
nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
47
gitea/repo_tag_test.go
Normal file
47
gitea/repo_tag_test.go
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTags(t *testing.T) {
|
||||||
|
log.Println("== TestTags ==")
|
||||||
|
c := newTestClient()
|
||||||
|
|
||||||
|
repo, _ := createTestRepo(t, "TestTags", c)
|
||||||
|
|
||||||
|
// Create Tags
|
||||||
|
createTestTag(t, c, repo, "tag1")
|
||||||
|
|
||||||
|
tags, _, err := c.ListRepoTags(repo.Owner.UserName, repo.Name, ListRepoTagsOptions{})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Len(t, tags, 1)
|
||||||
|
|
||||||
|
// DeleteReleaseTag
|
||||||
|
resp, err := c.DeleteTag(repo.Owner.UserName, repo.Name, "tag1")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 204, resp.StatusCode)
|
||||||
|
tags, _, err = c.ListRepoTags(repo.Owner.UserName, repo.Name, ListRepoTagsOptions{})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Len(t, tags, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// createTestTag use create release api since there exist no api to create tag only
|
||||||
|
// https://github.com/go-gitea/gitea/issues/14669
|
||||||
|
func createTestTag(t *testing.T, c *Client, repo *Repository, name string) {
|
||||||
|
rel, _, err := c.CreateRelease(repo.Owner.UserName, repo.Name, CreateReleaseOption{
|
||||||
|
TagName: name,
|
||||||
|
Target: "master",
|
||||||
|
Title: "TMP Release",
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
_, err = c.DeleteRelease(repo.Owner.UserName, repo.Name, rel.ID)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
Loading…
Reference in a new issue