Skip to content

Commit 547953f

Browse files
committed
add type to IssueListByRepoOptions and update ListByOrg to support type filter as well
Signed-off-by: Carlos Panato <[email protected]>
1 parent f137c94 commit 547953f

File tree

2 files changed

+68
-8
lines changed

2 files changed

+68
-8
lines changed

github/issues.go

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,72 @@ func (s *IssuesService) List(ctx context.Context, all bool, opts *IssueListOptio
173173
return s.listIssues(ctx, u, opts)
174174
}
175175

176+
func (s *IssuesService) listIssues(ctx context.Context, u string, opts *IssueListOptions) ([]*Issue, *Response, error) {
177+
u, err := addOptions(u, opts)
178+
if err != nil {
179+
return nil, nil, err
180+
}
181+
182+
req, err := s.client.NewRequest("GET", u, nil)
183+
if err != nil {
184+
return nil, nil, err
185+
}
186+
187+
// TODO: remove custom Accept header when this API fully launch.
188+
req.Header.Set("Accept", mediaTypeReactionsPreview)
189+
190+
var issues []*Issue
191+
resp, err := s.client.Do(ctx, req, &issues)
192+
if err != nil {
193+
return nil, resp, err
194+
}
195+
196+
return issues, resp, nil
197+
}
198+
199+
// IssueListByOrgOptions specifies the optional parameters to the
200+
// IssuesService.ListByOrg method.
201+
type IssueListByOrgOptions struct {
202+
// Filter specifies which issues to list. Possible values are: assigned,
203+
// created, mentioned, subscribed, all. Default is "assigned".
204+
Filter string `url:"filter,omitempty"`
205+
206+
// State filters issues based on their state. Possible values are: open,
207+
// closed, all. Default is "open".
208+
State string `url:"state,omitempty"`
209+
210+
// Labels filters issues based on their label.
211+
Labels []string `url:"labels,comma,omitempty"`
212+
213+
// Can be the name of an issue type. If the string "*" is passed, issues with
214+
// any type are accepted. If the string "none" is passed, issues without
215+
// type are returned.
216+
Type string `url:"type,omitempty"`
217+
218+
// Sort specifies how to sort issues. Possible values are: created, updated,
219+
// and comments. Default value is "created".
220+
Sort string `url:"sort,omitempty"`
221+
222+
// Direction in which to sort issues. Possible values are: asc, desc.
223+
// Default is "desc".
224+
Direction string `url:"direction,omitempty"`
225+
226+
// Since filters issues by time.
227+
Since time.Time `url:"since,omitempty"`
228+
229+
// Add ListOptions so offset pagination with integer type "page" query parameter is accepted
230+
// since ListCursorOptions accepts "page" as string only.
231+
ListOptions
232+
}
233+
176234
// ListByOrg fetches the issues in the specified organization for the
177235
// authenticated user.
178236
//
179237
// GitHub API docs: https://docs.github.com/rest/issues/issues#list-organization-issues-assigned-to-the-authenticated-user
180238
//
181239
//meta:operation GET /orgs/{org}/issues
182-
func (s *IssuesService) ListByOrg(ctx context.Context, org string, opts *IssueListOptions) ([]*Issue, *Response, error) {
240+
func (s *IssuesService) ListByOrg(ctx context.Context, org string, opts *IssueListByOrgOptions) ([]*Issue, *Response, error) {
183241
u := fmt.Sprintf("orgs/%v/issues", org)
184-
return s.listIssues(ctx, u, opts)
185-
}
186-
187-
func (s *IssuesService) listIssues(ctx context.Context, u string, opts *IssueListOptions) ([]*Issue, *Response, error) {
188242
u, err := addOptions(u, opts)
189243
if err != nil {
190244
return nil, nil, err
@@ -195,7 +249,7 @@ func (s *IssuesService) listIssues(ctx context.Context, u string, opts *IssueLis
195249
return nil, nil, err
196250
}
197251

198-
// TODO: remove custom Accept header when this API fully launch.
252+
// TODO: remove custom Accept header when this API fully launches.
199253
req.Header.Set("Accept", mediaTypeReactionsPreview)
200254

201255
var issues []*Issue
@@ -224,6 +278,11 @@ type IssueListByRepoOptions struct {
224278
// any assigned user.
225279
Assignee string `url:"assignee,omitempty"`
226280

281+
// Can be the name of an issue type. If the string "*" is passed, issues with
282+
// any type are accepted. If the string "none" is passed, issues without
283+
// type are returned.
284+
Type string `url:"type,omitempty"`
285+
227286
// Creator filters issues based on their creator.
228287
Creator string `url:"creator,omitempty"`
229288

github/issues_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func TestIssuesService_ListByRepo(t *testing.T) {
151151
"milestone": "*",
152152
"state": "closed",
153153
"assignee": "a",
154+
"type": "bug",
154155
"creator": "c",
155156
"mentioned": "m",
156157
"labels": "a,b",
@@ -165,14 +166,14 @@ func TestIssuesService_ListByRepo(t *testing.T) {
165166
})
166167

167168
opt := &IssueListByRepoOptions{
168-
"*", "closed", "a", "c", "m", []string{"a", "b"}, "updated", "asc",
169+
"*", "closed", "a", "bug", "c", "m", []string{"a", "b"}, "updated", "asc",
169170
time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC),
170171
ListCursorOptions{PerPage: 1, Before: "foo", After: "bar"}, ListOptions{0, 0},
171172
}
172173
ctx := context.Background()
173174
issues, _, err := client.Issues.ListByRepo(ctx, "o", "r", opt)
174175
if err != nil {
175-
t.Errorf("Issues.ListByOrg returned error: %v", err)
176+
t.Errorf("Issues.ListByRepo returned error: %v", err)
176177
}
177178

178179
want := []*Issue{{Number: Ptr(1)}}

0 commit comments

Comments
 (0)