feat(gitea): add issue comment list API
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
5bb8e61708
commit
0d80388d18
2 changed files with 46 additions and 0 deletions
|
|
@ -133,6 +133,31 @@ func (c *Client) CreateIssue(owner, repo string, opts gitea.CreateIssueOption) (
|
|||
return issue, nil
|
||||
}
|
||||
|
||||
// ListIssueComments returns all comments for an issue.
|
||||
// Usage: ListIssueComments(...)
|
||||
func (c *Client) ListIssueComments(owner, repo string, number int64) ([]*gitea.Comment, error) {
|
||||
var all []*gitea.Comment
|
||||
page := 1
|
||||
|
||||
for {
|
||||
comments, resp, err := c.api.ListIssueComments(owner, repo, number, gitea.ListIssueCommentOptions{
|
||||
ListOptions: gitea.ListOptions{Page: page, PageSize: commentPageSize},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, log.E("gitea.ListIssueComments", "failed to list comments", err)
|
||||
}
|
||||
|
||||
all = append(all, comments...)
|
||||
|
||||
if resp == nil || page >= resp.LastPage {
|
||||
break
|
||||
}
|
||||
page++
|
||||
}
|
||||
|
||||
return all, nil
|
||||
}
|
||||
|
||||
// ListPullRequests returns pull requests for the given repository.
|
||||
// Usage: ListPullRequests(...)
|
||||
func (c *Client) ListPullRequests(owner, repo string, state string) ([]*gitea.PullRequest, error) {
|
||||
|
|
|
|||
|
|
@ -190,6 +190,27 @@ func TestClient_ListIssueCommentsIter_Good_Paginates_Good(t *testing.T) {
|
|||
assert.Equal(t, "comment 51", bodies[50])
|
||||
}
|
||||
|
||||
func TestClient_ListIssueComments_Good_Paginates_Good(t *testing.T) {
|
||||
client, srv := newPaginatedCommentsClient(t)
|
||||
defer srv.Close()
|
||||
|
||||
comments, err := client.ListIssueComments("test-org", "org-repo", 1)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, comments, 51)
|
||||
assert.Equal(t, "comment 1", comments[0].Body)
|
||||
assert.Equal(t, "comment 50", comments[49].Body)
|
||||
assert.Equal(t, "comment 51", comments[50].Body)
|
||||
}
|
||||
|
||||
func TestClient_ListIssueComments_Bad_ServerError_Good(t *testing.T) {
|
||||
client, srv := newErrorServer(t)
|
||||
defer srv.Close()
|
||||
|
||||
_, err := client.ListIssueComments("test-org", "org-repo", 1)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "failed to list comments")
|
||||
}
|
||||
|
||||
func TestClient_CreateIssue_Good(t *testing.T) {
|
||||
client, srv := newTestClient(t)
|
||||
defer srv.Close()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue