Skip to content

Commit 4bc42c5

Browse files
authored
Merge pull request #203 from github/pagination
Pagination
2 parents a74574b + 9662dd9 commit 4bc42c5

6 files changed

Lines changed: 63 additions & 47 deletions

File tree

.github/actions/check/check-replication.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/check/check-replication.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ const run = async (): Promise<void> => {
1111
core.setFailed(`Internal error. Cannot access the internal repo ${internalRepo}. Aborting`)
1212
return
1313
} else {
14+
core.debug(`Retrieved ${internalIssues?.length} internal issues`)
1415
const externalIssues = await getIssueList(github.context.repo.owner, github.context.repo.repo, process.env['GITHUB_TOKEN'], true, true)
1516
if(!externalIssues) {
1617
core.setFailed(`Internal error when retrieving all issues.`)
1718
return
1819
}
20+
core.debug(`Retrieved ${externalIssues?.length} external issues`)
1921
let failed = false
2022
externalIssues.forEach( issue => {
2123
const ref = internalIssueAlreadyCreated(issue?.html_url, internalIssues)

.github/actions/replicate/issues.js

Lines changed: 29 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/replicate/issues.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,35 @@ export const getIssueList = async (owner: string, repo: string, token: string |
1515
const octokit = new github.GitHub(token)
1616
const issueState: Issue_state = open? 'open' : 'all'
1717
// const labelFilter: string = replicate.BOUNTY_LABELS.join(',')
18-
const issues = await octokit.issues.listForRepo({
19-
owner,
20-
repo,
21-
state: issueState,
22-
per_page: per_page? per_page : 100 // TODO: implement proper pagination
23-
// labels: labelFilter -- Does not work properly
24-
})
25-
26-
issues.data.forEach(issue => {
27-
const bountyLabel = checkBountyLabels? issue.labels.some(label => {
28-
return replicate.BOUNTY_LABELS.includes(label.name as replicate.BountyType)
29-
}) : undefined
30-
if(!checkBountyLabels || bountyLabel){
31-
let item: Issue_info = {
32-
title: issue.title,
33-
author: issue.user?.login,
34-
body: issue.body? issue.body : '',
35-
number: issue.number,
36-
html_url: issue.html_url
18+
const issuesPerPage = per_page? per_page : 50
19+
let pageNb = 0
20+
do {
21+
const issues = await octokit.issues.listForRepo({
22+
owner,
23+
repo,
24+
state: issueState,
25+
per_page: issuesPerPage,
26+
page: pageNb
27+
// labels: labelFilter -- Does not work properly
28+
})
29+
30+
issues.data.forEach(issue => {
31+
const bountyLabel = checkBountyLabels? issue.labels.some(label => {
32+
return replicate.BOUNTY_LABELS.includes(label.name as replicate.BountyType)
33+
}) : undefined
34+
if(!checkBountyLabels || bountyLabel){
35+
let item: Issue_info = {
36+
title: issue.title,
37+
author: issue.user?.login,
38+
body: issue.body? issue.body : '',
39+
number: issue.number,
40+
html_url: issue.html_url
41+
}
42+
result.push(item)
3743
}
38-
result.push(item)
39-
}
40-
});
44+
});
45+
pageNb = (issues.data.length < issuesPerPage)? -1 : pageNb + 1
46+
} while (pageNb >= 0)
4147
return result
4248
} catch(error) {
4349
core.debug(error.message)

.github/workflows/check-replication-manual.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Bounty issue replication workflow'
1+
name: 'Bounty issue manual replication check'
22
on: workflow_dispatch
33

44
jobs:

.github/workflows/check-replication.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Bounty issue replication workflow'
1+
name: 'Bounty issue replication check'
22
on:
33
schedule:
44
- cron: '0 17 * * *'

0 commit comments

Comments
 (0)