Add DeleteIssue() (#598)

Fixes: #596

Signed-off-by: Earl Warren <contact@earl-warren.org>

Co-authored-by: Earl Warren <contact@earl-warren.org>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/598
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: Norwin <noerw@noreply.gitea.io>
Reviewed-by: 6543 <6543@obermui.de>
Co-authored-by: earl-warren <contact@earl-warren.org>
Co-committed-by: earl-warren <contact@earl-warren.org>
This commit is contained in:
earl-warren 2022-09-16 05:45:01 +08:00 committed by 6543
parent 7aeaaa45e1
commit aef4e5e2bd
2 changed files with 27 additions and 2 deletions

View file

@ -289,6 +289,17 @@ func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption)
return issue, resp, err
}
// DeleteIssue delete a issue from a repository
func (c *Client) DeleteIssue(user, repo string, id int64) (*Response, error) {
if err := escapeValidatePathSegments(&user, &repo); err != nil {
return nil, err
}
_, resp, err := c.getResponse("DELETE",
fmt.Sprintf("/repos/%s/%s/issues/%d", user, repo, id),
nil, nil)
return resp, err
}
func (c *Client) issueBackwardsCompatibility(issue *Issue) {
if c.checkServerVersionGreaterThanOrEqual(version1_12_0) != nil {
c.mutex.RLock()

View file

@ -22,6 +22,7 @@ func TestIssue(t *testing.T) {
time.Sleep(100 * time.Millisecond)
editIssues(t, c)
listIssues(t, c)
deleteIssue(t, c)
}
func createIssue(t *testing.T, c *Client) {
@ -47,6 +48,18 @@ func createIssue(t *testing.T, c *Client) {
createTestIssue(t, c, repo.Name, "", "you never know", nil, nil, mile.ID, nil, true, true)
}
func deleteIssue(t *testing.T, c *Client) {
log.Println("== TestDeleteIssues ==")
user, _, err := c.GetMyUserInfo()
assert.NoError(t, err)
repo, _ := createTestRepo(t, "IssueTestsRepo", c)
issue := createTestIssue(t, c, repo.Name, "Deleteable Issue", "", nil, nil, 0, nil, false, false)
_, err = c.DeleteIssue(user.UserName, repo.Name, issue.Index)
assert.NoError(t, err)
}
func editIssues(t *testing.T, c *Client) {
log.Println("== TestEditIssues ==")
il, _, err := c.ListIssues(ListIssueOption{KeyWord: "soon"})
@ -104,7 +117,7 @@ func listIssues(t *testing.T, c *Client) {
assert.Len(t, issues, 3)
}
func createTestIssue(t *testing.T, c *Client, repoName, title, body string, assignees []string, deadline *time.Time, milestone int64, labels []int64, closed, shouldFail bool) {
func createTestIssue(t *testing.T, c *Client, repoName, title, body string, assignees []string, deadline *time.Time, milestone int64, labels []int64, closed, shouldFail bool) *Issue {
user, _, err := c.GetMyUserInfo()
assert.NoError(t, err)
issue, _, e := c.CreateIssue(user.UserName, repoName, CreateIssueOption{
@ -118,7 +131,7 @@ func createTestIssue(t *testing.T, c *Client, repoName, title, body string, assi
})
if shouldFail {
assert.Error(t, e)
return
return nil
}
assert.NoError(t, e)
assert.NotEmpty(t, issue)
@ -137,4 +150,5 @@ func createTestIssue(t *testing.T, c *Client, repoName, title, body string, assi
} else {
assert.Empty(t, issue.Closed)
}
return issue
}