Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 65 additions & 6 deletions github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the change, listIssues is used only in the IssuesService.List. So, let's merge listIssues and List functions.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// IssueListByOrgOptions specifies the optional parameters to the
// IssueListByOrgOptions specifies the optional parameter 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
Expand All @@ -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
Expand Down Expand Up @@ -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"`

Expand Down
7 changes: 3 additions & 4 deletions github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"milestone": "*",
"state": "closed",
"assignee": "a",
"type": "bug",
"creator": "c",
"mentioned": "m",
"labels": "a,b",
Expand All @@ -168,17 +169,15 @@
})

opt := &IssueListByRepoOptions{
"*", "closed", "a", "c", "m",
[]string{"a", "b"},
"updated", "asc",
"*", "closed", "a", "bug", "c", "m", []string{"a", "b"}, "updated", "asc",

Check failure on line 172 in github/issues_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gofumpt)
time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC),
ListCursorOptions{PerPage: 1, Before: "foo", After: "bar"},
ListOptions{0, 0},
}
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)}}
Expand Down
Loading