From 0d80388d18ce68dc6ce45e29a32cda316bcba65a Mon Sep 17 00:00:00 2001 From: Virgil Date: Wed, 1 Apr 2026 09:07:55 +0000 Subject: [PATCH] feat(gitea): add issue comment list API Co-Authored-By: Virgil --- gitea/issues.go | 25 +++++++++++++++++++++++++ gitea/issues_test.go | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/gitea/issues.go b/gitea/issues.go index d8045a3..51dbfdb 100644 --- a/gitea/issues.go +++ b/gitea/issues.go @@ -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) { diff --git a/gitea/issues_test.go b/gitea/issues_test.go index fe8eb80..23f17b1 100644 --- a/gitea/issues_test.go +++ b/gitea/issues_test.go @@ -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()