Skip to content

Parse Before/After Links into Response - #2154

Merged
gmlewis merged 2 commits into
google:masterfrom
dghubble:parse-before-after
Nov 15, 2021
Merged

Parse Before/After Links into Response#2154
gmlewis merged 2 commits into
google:masterfrom
dghubble:parse-before-after

Conversation

@dghubble

@dghubbledghubble commented Oct 27, 2021

Copy link
Copy Markdown
Contributor

With this change, pagination can be performed

auditParams:=&github.GetAuditLogOptions{}
for {
entries, resp, err:=client.Organizations.GetAuditLog(ctx, "myorg", auditParams)
iferr!=nil {
returnerr
}
ifresp.After=="" {
break
}
auditParams.After=resp.After
}

Rel: #1848

* Some Github APIs use `before`/`after` for pagination, rather
than `page` or `cursor` pagination. Parse these response values
* For example, the Organizations GetAuditLog (Enterprise Cloud)
https://docs.github.com/en/rest/reference/orgs#get-the-audit-log-for-an-organization
With this change, pagination can be performed
```go
for pageCount < PageMax {
entries, resp, err := client.Organizations.GetAuditLog(ctx, "org", auditParams)
if err != nil {
return err
}
pageCount++
if resp.After == "" {
break
}
auditParams.After = resp.After
}
```
@google-clagoogle-claBot added the cla: yes Indication that the PR author has signed a Google Contributor License Agreement. label Oct 27, 2021
@codecov

codecovBot commented Oct 27, 2021

Copy link
Copy Markdown

Codecov Report

Merging #2154 (cc18ba5) into master (d9d58a2) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@ Coverage Diff @@## master #2154 +/- ##
==========================================
+ Coverage 97.78% 97.79% +0.01% 
==========================================
Files 112 112 Lines 9976 10036 +60 ==========================================
+ Hits 9755 9815 +60 
Misses 154 154 Partials 67 67 
Impacted FilesCoverage Δ
github/github.go97.60% <100.00%> (+0.01%)⬆️
github/code-scanning.go100.00% <0.00%> (ø)
github/issues_timeline.go100.00% <0.00%> (ø)
github/repos.go98.68% <0.00%> (+0.02%)⬆️
github/reactions.go97.84% <0.00%> (+0.13%)⬆️
github/issues.go97.41% <0.00%> (+0.35%)⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d9d58a2...cc18ba5. Read the comment docs.

@gmlewisgmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you, @dghubble !
LGTM.

Awaiting second LGTM before merging.

@gmlewis
gmlewis requested a review from wesleimpOctober 27, 2021 21:03
@dghubble

Copy link
Copy Markdown
ContributorAuthor

Maybe another reviewer has time / interest?

@gmlewis

Copy link
Copy Markdown
Collaborator

Perhaps @Parker77 has time?

@Parker77Parker77 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

One minor change, otherwise LGTM!

Comment threadgithub/github.go Outdated
Co-authored-by: Parker77 <20973702+Parker77@users.noreply.github.com>
@gmlewis

Copy link
Copy Markdown
Collaborator

Thank you, @Parker77 !
Merging after tests pass.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yesIndication that the PR author has signed a Google Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@dghubble@gmlewis@Parker77