feat(forge): add issue label getter
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
e0ff9d2c28
commit
fe8c7e5982
3 changed files with 31 additions and 1 deletions
|
|
@ -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` |
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue