Skip to content
Merged
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
136 changes: 136 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

161 changes: 161 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions github/github-stringify_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ type ListCursorOptions struct {

// A cursor, as given in the Link header. If specified, the query only searches for events before this cursor.
Before string `url:"before,omitempty"`

// A cursor, as given in the Link header. If specified, the query continues the search using this cursor.
Cursor string `url:"cursor,omitempty"`
}

// UploadOptions specifies the parameters to methods that support uploads.
Expand Down Expand Up @@ -445,6 +448,11 @@ type Response struct {
// calling the endpoint again.
NextPageToken string

// For APIs that support cursor pagination, such as RepositoryService.ListRepositoryHookDeliveries,
// the following field will be populated to point to the next page.
// Set ListCursorOptions.Cursor to this value when calling the endpoint again.
Cursor string

// Explicitly specify the Rate type so Rate's String() receiver doesn't
// propagate to Response.
Rate Rate
Expand Down Expand Up @@ -481,7 +489,21 @@ func (r *Response) populatePageValues() {
if err != nil {
continue
}
page := url.Query().Get("page")

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm... I'm not sure I'm happy with this section (especially regarding increasing the already-deep indentation levels).

Since "cursor" is the less-common and smaller case, let's please handle it first, and let's revert all the changes made to the handling of the "page" section, except maybe to pull out the shared query first... something like this:

q := url.Query()
if cursor := q.Get("cursor"); cursor != "" {
...
}

page := q.Get("page")
if page == "" {
  continue
}
...

Copy link
Contributor Author

@mumoshu mumoshu Jul 6, 2021

Choose a reason for hiding this comment

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

Thanks! Addressed in f6d688a

q := url.Query()

if cursor := q.Get("cursor"); cursor != "" {
for _, segment := range segments[1:] {
switch strings.TrimSpace(segment) {
case `rel="next"`:
r.Cursor = cursor
}
}

continue
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are "cursor" and "page" mutually exclusive? (I think the answer is "yes" but I could be wrong.)

If so, do you want to add a continue within this if block just to make that clear?
I'm actually fine either way... your call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Yes, I believe so, although it isn't documented anywhere. Added continue in 72c3380


page := q.Get("page")
if page == "" {
continue
}
Expand All @@ -499,7 +521,6 @@ func (r *Response) populatePageValues() {
case `rel="last"`:
r.LastPage, _ = strconv.Atoi(page)
}

}
}
}
Expand Down
Loading