feat(forge): add issue label getter
Some checks failed
Security Scan / security (push) Failing after 16s
Test / test (push) Failing after 54s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 13:56:22 +00:00
parent e0ff9d2c28
commit fe8c7e5982
3 changed files with 31 additions and 1 deletions

View file

@ -88,7 +88,7 @@ The `gitea/` package mirrors this using `GITEA_URL`/`GITEA_TOKEN` and `gitea.*`
|------|-----------| |------|-----------|
| `client.go` | `New`, `NewFromConfig`, `GetCurrentUser`, `ForkRepo`, `CreatePullRequest` | | `client.go` | `New`, `NewFromConfig`, `GetCurrentUser`, `ForkRepo`, `CreatePullRequest` |
| `repos.go` | `ListOrgRepos`, `ListOrgReposIter`, `ListUserRepos`, `ListUserReposIter`, `GetRepo`, `CreateOrgRepo`, `DeleteRepo`, `MigrateRepo` | | `repos.go` | `ListOrgRepos`, `ListOrgReposIter`, `ListUserRepos`, `ListUserReposIter`, `GetRepo`, `CreateOrgRepo`, `DeleteRepo`, `MigrateRepo` |
| `issues.go` | `ListIssues`, `ListIssuesIter`, `GetIssue`, `CreateIssue`, `EditIssue`, `AssignIssue`, `ListPullRequests`, `ListPullRequestsIter`, `GetPullRequest`, `CreateIssueComment`, `ListIssueComments`, `ListIssueCommentsIter`, `CloseIssue` | | `issues.go` | `ListIssues`, `ListIssuesIter`, `GetIssue`, `CreateIssue`, `EditIssue`, `AssignIssue`, `ListPullRequests`, `ListPullRequestsIter`, `GetPullRequest`, `CreateIssueComment`, `GetIssueLabels`, `ListIssueComments`, `ListIssueCommentsIter`, `CloseIssue` |
| `labels.go` | `ListOrgLabels`, `ListOrgLabelsIter`, `ListRepoLabels`, `ListRepoLabelsIter`, `CreateRepoLabel`, `GetLabelByName`, `EnsureLabel`, `AddIssueLabels`, `RemoveIssueLabel` | | `labels.go` | `ListOrgLabels`, `ListOrgLabelsIter`, `ListRepoLabels`, `ListRepoLabelsIter`, `CreateRepoLabel`, `GetLabelByName`, `EnsureLabel`, `AddIssueLabels`, `RemoveIssueLabel` |
| `prs.go` | `MergePullRequest`, `SetPRDraft`, `ListPRReviews`, `GetCombinedStatus`, `DismissReview`, `UndismissReview` | | `prs.go` | `MergePullRequest`, `SetPRDraft`, `ListPRReviews`, `GetCombinedStatus`, `DismissReview`, `UndismissReview` |
| `webhooks.go` | `CreateRepoWebhook`, `ListRepoWebhooks` | | `webhooks.go` | `CreateRepoWebhook`, `ListRepoWebhooks` |

View file

@ -253,6 +253,17 @@ func (c *Client) CreateIssueComment(owner, repo string, issue int64, body string
return nil return nil
} }
// GetIssueLabels returns the labels currently attached to an issue.
// Usage: GetIssueLabels(...)
func (c *Client) GetIssueLabels(owner, repo string, number int64) ([]*forgejo.Label, error) {
labels, _, err := c.api.GetIssueLabels(owner, repo, number, forgejo.ListLabelsOptions{})
if err != nil {
return nil, log.E("forge.GetIssueLabels", "failed to get issue labels", err)
}
return labels, nil
}
// ListIssueComments returns comments for an issue. // ListIssueComments returns comments for an issue.
// Usage: ListIssueComments(...) // Usage: ListIssueComments(...)
func (c *Client) ListIssueComments(owner, repo string, number int64) ([]*forgejo.Comment, error) { func (c *Client) ListIssueComments(owner, repo string, number int64) ([]*forgejo.Comment, error) {

View file

@ -312,6 +312,25 @@ func TestClient_CreateIssueComment_Bad_ServerError_Good(t *testing.T) {
assert.Contains(t, err.Error(), "failed to create comment") assert.Contains(t, err.Error(), "failed to create comment")
} }
func TestClient_GetIssueLabels_Good(t *testing.T) {
client, srv := newTestClient(t)
defer srv.Close()
labels, err := client.GetIssueLabels("test-org", "org-repo", 1)
require.NoError(t, err)
require.Len(t, labels, 1)
assert.Equal(t, "bug", labels[0].Name)
}
func TestClient_GetIssueLabels_Bad_ServerError_Good(t *testing.T) {
client, srv := newErrorServer(t)
defer srv.Close()
_, err := client.GetIssueLabels("test-org", "org-repo", 1)
assert.Error(t, err)
assert.Contains(t, err.Error(), "failed to get issue labels")
}
func TestClient_ListIssueComments_Good(t *testing.T) { func TestClient_ListIssueComments_Good(t *testing.T) {
client, srv := newTestClient(t) client, srv := newTestClient(t)
defer srv.Close() defer srv.Close()