From 65ee0b74581da1452a7032542bc47aa53e1eb97e Mon Sep 17 00:00:00 2001 From: Xavier RENE-CORAIL Date: Tue, 10 Nov 2020 19:47:28 +0000 Subject: [PATCH 1/3] pagination --- .github/actions/replicate/issues.js | 52 ++++++++++++++------------ .github/actions/replicate/issues.ts | 50 ++++++++++++++----------- .github/actions/replicate/replicate.js | 7 ++++ 3 files changed, 64 insertions(+), 45 deletions(-) diff --git a/.github/actions/replicate/issues.js b/.github/actions/replicate/issues.js index 4830fb4..2afb124 100644 --- a/.github/actions/replicate/issues.js +++ b/.github/actions/replicate/issues.js @@ -33,29 +33,35 @@ exports.getIssueList = async (owner, repo, token, open, checkBountyLabels, per_p const octokit = new github.GitHub(token); const issueState = open ? 'open' : 'all'; // const labelFilter: string = replicate.BOUNTY_LABELS.join(',') - const issues = await octokit.issues.listForRepo({ - owner, - repo, - state: issueState, - per_page: per_page ? per_page : 100 // TODO: implement proper pagination - // labels: labelFilter -- Does not work properly - }); - issues.data.forEach(issue => { - var _a; - const bountyLabel = checkBountyLabels ? issue.labels.some(label => { - return replicate.BOUNTY_LABELS.includes(label.name); - }) : undefined; - if (!checkBountyLabels || bountyLabel) { - let item = { - title: issue.title, - author: (_a = issue.user) === null || _a === void 0 ? void 0 : _a.login, - body: issue.body ? issue.body : '', - number: issue.number, - html_url: issue.html_url - }; - result.push(item); - } - }); + const issuesPerPage = per_page ? per_page : 50; + let pageNb = 0; + do { + const issues = await octokit.issues.listForRepo({ + owner, + repo, + state: issueState, + per_page: issuesPerPage, + page: pageNb + // labels: labelFilter -- Does not work properly + }); + issues.data.forEach(issue => { + var _a; + const bountyLabel = checkBountyLabels ? issue.labels.some(label => { + return replicate.BOUNTY_LABELS.includes(label.name); + }) : undefined; + if (!checkBountyLabels || bountyLabel) { + let item = { + title: issue.title, + author: (_a = issue.user) === null || _a === void 0 ? void 0 : _a.login, + body: issue.body ? issue.body : '', + number: issue.number, + html_url: issue.html_url + }; + result.push(item); + } + }); + pageNb = (issues.data.length < issuesPerPage) ? -1 : pageNb + 1; + } while (pageNb >= 0); return result; } catch (error) { diff --git a/.github/actions/replicate/issues.ts b/.github/actions/replicate/issues.ts index 33945f0..de5d6ba 100644 --- a/.github/actions/replicate/issues.ts +++ b/.github/actions/replicate/issues.ts @@ -15,29 +15,35 @@ export const getIssueList = async (owner: string, repo: string, token: string | const octokit = new github.GitHub(token) const issueState: Issue_state = open? 'open' : 'all' // const labelFilter: string = replicate.BOUNTY_LABELS.join(',') - const issues = await octokit.issues.listForRepo({ - owner, - repo, - state: issueState, - per_page: per_page? per_page : 100 // TODO: implement proper pagination - // labels: labelFilter -- Does not work properly - }) - - issues.data.forEach(issue => { - const bountyLabel = checkBountyLabels? issue.labels.some(label => { - return replicate.BOUNTY_LABELS.includes(label.name as replicate.BountyType) - }) : undefined - if(!checkBountyLabels || bountyLabel){ - let item: Issue_info = { - title: issue.title, - author: issue.user?.login, - body: issue.body? issue.body : '', - number: issue.number, - html_url: issue.html_url + const issuesPerPage = per_page? per_page : 50 + let pageNb = 0 + do { + const issues = await octokit.issues.listForRepo({ + owner, + repo, + state: issueState, + per_page: issuesPerPage, + page: pageNb + // labels: labelFilter -- Does not work properly + }) + + issues.data.forEach(issue => { + const bountyLabel = checkBountyLabels? issue.labels.some(label => { + return replicate.BOUNTY_LABELS.includes(label.name as replicate.BountyType) + }) : undefined + if(!checkBountyLabels || bountyLabel){ + let item: Issue_info = { + title: issue.title, + author: issue.user?.login, + body: issue.body? issue.body : '', + number: issue.number, + html_url: issue.html_url + } + result.push(item) } - result.push(item) - } - }); + }); + pageNb = (issues.data.length < issuesPerPage)? -1 : pageNb + 1 + } while (pageNb >= 0) return result } catch(error) { core.debug(error.message) diff --git a/.github/actions/replicate/replicate.js b/.github/actions/replicate/replicate.js index 1fc4a4a..3b6e8e3 100644 --- a/.github/actions/replicate/replicate.js +++ b/.github/actions/replicate/replicate.js @@ -132,6 +132,13 @@ exports.createInternalIssue = async (payload, issue) => { }); internal_ref = issueResponse.data.number; core.debug(`issue created: ${internal_ref}`); + const labelsResponse = await octokit.issues.addLabels({ + owner, + repo, + issue_number: internal_ref, + labels: issue.labels + }); + core.debug(`Labels addition result: ${labelsResponse.status} ${(labelsResponse.status == 200) ? "OK" : "FAILED"}`); const issueCommentResponse1 = await octokit.issues.createComment({ owner, repo, From 6620ba23ddf1a3bea891c33d71d5d7e2bce87ca3 Mon Sep 17 00:00:00 2001 From: Xavier RENE-CORAIL Date: Tue, 10 Nov 2020 19:53:17 +0000 Subject: [PATCH 2/3] Workflow names --- .github/workflows/check-replication-manual.yml | 2 +- .github/workflows/check-replication.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-replication-manual.yml b/.github/workflows/check-replication-manual.yml index 4892a36..0e1eef3 100644 --- a/.github/workflows/check-replication-manual.yml +++ b/.github/workflows/check-replication-manual.yml @@ -1,4 +1,4 @@ -name: 'Bounty issue replication workflow' +name: 'Bounty issue manual replication check' on: workflow_dispatch jobs: diff --git a/.github/workflows/check-replication.yml b/.github/workflows/check-replication.yml index 3be6424..21c243f 100644 --- a/.github/workflows/check-replication.yml +++ b/.github/workflows/check-replication.yml @@ -1,4 +1,4 @@ -name: 'Bounty issue replication workflow' +name: 'Bounty issue replication check' on: schedule: - cron: '0 17 * * *' From 9662dd9f80664e9a7723423592383321d405885c Mon Sep 17 00:00:00 2001 From: Xavier RENE-CORAIL Date: Tue, 10 Nov 2020 23:34:03 +0000 Subject: [PATCH 3/3] debug --- .github/actions/check/check-replication.js | 2 ++ .github/actions/check/check-replication.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/actions/check/check-replication.js b/.github/actions/check/check-replication.js index b8b9a8a..476311d 100644 --- a/.github/actions/check/check-replication.js +++ b/.github/actions/check/check-replication.js @@ -32,11 +32,13 @@ const run = async () => { return; } else { + core.debug(`Retrieved ${internalIssues === null || internalIssues === void 0 ? void 0 : internalIssues.length} internal issues`); const externalIssues = await issues_1.getIssueList(github.context.repo.owner, github.context.repo.repo, process.env['GITHUB_TOKEN'], true, true); if (!externalIssues) { core.setFailed(`Internal error when retrieving all issues.`); return; } + core.debug(`Retrieved ${externalIssues === null || externalIssues === void 0 ? void 0 : externalIssues.length} external issues`); let failed = false; externalIssues.forEach(issue => { const ref = issues_1.internalIssueAlreadyCreated(issue === null || issue === void 0 ? void 0 : issue.html_url, internalIssues); diff --git a/.github/actions/check/check-replication.ts b/.github/actions/check/check-replication.ts index dec22e8..7dbb23b 100644 --- a/.github/actions/check/check-replication.ts +++ b/.github/actions/check/check-replication.ts @@ -11,11 +11,13 @@ const run = async (): Promise => { core.setFailed(`Internal error. Cannot access the internal repo ${internalRepo}. Aborting`) return } else { + core.debug(`Retrieved ${internalIssues?.length} internal issues`) const externalIssues = await getIssueList(github.context.repo.owner, github.context.repo.repo, process.env['GITHUB_TOKEN'], true, true) if(!externalIssues) { core.setFailed(`Internal error when retrieving all issues.`) return } + core.debug(`Retrieved ${externalIssues?.length} external issues`) let failed = false externalIssues.forEach( issue => { const ref = internalIssueAlreadyCreated(issue?.html_url, internalIssues)