diff --git a/github/issues.go b/github/issues.go index 18bd2eff4b5..90e96f01152 100644 --- a/github/issues.go +++ b/github/issues.go @@ -173,18 +173,72 @@ func (s *IssuesService) List(ctx context.Context, all bool, opts *IssueListOptio return s.listIssues(ctx, u, opts) } +func (s *IssuesService) listIssues(ctx context.Context, u string, opts *IssueListOptions) ([]*Issue, *Response, error) { + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launch. + req.Header.Set("Accept", mediaTypeReactionsPreview) + + var issues []*Issue + resp, err := s.client.Do(ctx, req, &issues) + if err != nil { + return nil, resp, err + } + + return issues, resp, nil +} + +// IssueListByOrgOptions specifies the optional parameters to the +// IssuesService.ListByOrg method. +type IssueListByOrgOptions struct { + // Filter specifies which issues to list. Possible values are: assigned, + // created, mentioned, subscribed, all. Default is "assigned". + Filter string `url:"filter,omitempty"` + + // State filters issues based on their state. Possible values are: open, + // closed, all. Default is "open". + State string `url:"state,omitempty"` + + // Labels filters issues based on their label. + Labels []string `url:"labels,comma,omitempty"` + + // Can be the name of an issue type. If the string "*" is passed, issues with + // any type are accepted. If the string "none" is passed, issues without + // type are returned. + Type string `url:"type,omitempty"` + + // Sort specifies how to sort issues. Possible values are: created, updated, + // and comments. Default value is "created". + Sort string `url:"sort,omitempty"` + + // Direction in which to sort issues. Possible values are: asc, desc. + // Default is "desc". + Direction string `url:"direction,omitempty"` + + // Since filters issues by time. + Since time.Time `url:"since,omitempty"` + + // Add ListOptions so offset pagination with integer type "page" query parameter is accepted + // since ListCursorOptions accepts "page" as string only. + ListOptions +} + // ListByOrg fetches the issues in the specified organization for the // authenticated user. // // GitHub API docs: https://docs.github.com/rest/issues/issues#list-organization-issues-assigned-to-the-authenticated-user // //meta:operation GET /orgs/{org}/issues -func (s *IssuesService) ListByOrg(ctx context.Context, org string, opts *IssueListOptions) ([]*Issue, *Response, error) { +func (s *IssuesService) ListByOrg(ctx context.Context, org string, opts *IssueListByOrgOptions) ([]*Issue, *Response, error) { u := fmt.Sprintf("orgs/%v/issues", org) - return s.listIssues(ctx, u, opts) -} - -func (s *IssuesService) listIssues(ctx context.Context, u string, opts *IssueListOptions) ([]*Issue, *Response, error) { u, err := addOptions(u, opts) if err != nil { return nil, nil, err @@ -195,7 +249,7 @@ func (s *IssuesService) listIssues(ctx context.Context, u string, opts *IssueLis return nil, nil, err } - // TODO: remove custom Accept header when this API fully launch. + // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeReactionsPreview) var issues []*Issue @@ -224,6 +278,11 @@ type IssueListByRepoOptions struct { // any assigned user. Assignee string `url:"assignee,omitempty"` + // Can be the name of an issue type. If the string "*" is passed, issues with + // any type are accepted. If the string "none" is passed, issues without + // type are returned. + Type string `url:"type,omitempty"` + // Creator filters issues based on their creator. Creator string `url:"creator,omitempty"` diff --git a/github/issues_test.go b/github/issues_test.go index 450b38a2c2c..b3b3ff8eed9 100644 --- a/github/issues_test.go +++ b/github/issues_test.go @@ -154,6 +154,7 @@ func TestIssuesService_ListByRepo(t *testing.T) { "milestone": "*", "state": "closed", "assignee": "a", + "type": "bug", "creator": "c", "mentioned": "m", "labels": "a,b", @@ -168,9 +169,7 @@ func TestIssuesService_ListByRepo(t *testing.T) { }) opt := &IssueListByRepoOptions{ - "*", "closed", "a", "c", "m", - []string{"a", "b"}, - "updated", "asc", + "*", "closed", "a", "bug", "c", "m", []string{"a", "b"}, "updated", "asc", time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC), ListCursorOptions{PerPage: 1, Before: "foo", After: "bar"}, ListOptions{0, 0}, @@ -178,7 +177,7 @@ func TestIssuesService_ListByRepo(t *testing.T) { ctx := context.Background() issues, _, err := client.Issues.ListByRepo(ctx, "o", "r", opt) if err != nil { - t.Errorf("Issues.ListByOrg returned error: %v", err) + t.Errorf("Issues.ListByRepo returned error: %v", err) } want := []*Issue{{Number: Ptr(1)}}