feat(gitea): add issue comment list API
Some checks failed
Security Scan / security (push) Failing after 12s
Test / test (push) Successful in 2m8s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-01 09:07:55 +00:00
parent 5bb8e61708
commit 0d80388d18
2 changed files with 46 additions and 0 deletions

View file

@ -133,6 +133,31 @@ func (c *Client) CreateIssue(owner, repo string, opts gitea.CreateIssueOption) (
return issue, nil 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. // ListPullRequests returns pull requests for the given repository.
// Usage: ListPullRequests(...) // Usage: ListPullRequests(...)
func (c *Client) ListPullRequests(owner, repo string, state string) ([]*gitea.PullRequest, error) { func (c *Client) ListPullRequests(owner, repo string, state string) ([]*gitea.PullRequest, error) {

View file

@ -190,6 +190,27 @@ func TestClient_ListIssueCommentsIter_Good_Paginates_Good(t *testing.T) {
assert.Equal(t, "comment 51", bodies[50]) 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) { func TestClient_CreateIssue_Good(t *testing.T) {
client, srv := newTestClient(t) client, srv := newTestClient(t)
defer srv.Close() defer srv.Close()