From 58c4b5ed070f97c658d8cfc79ef9795afe072be0 Mon Sep 17 00:00:00 2001 From: Rory Abraham Date: Mon, 10 May 2021 14:49:59 -0700 Subject: [PATCH 1/4] Fix parsing bug in getStagingDeployCash --- .github/libs/GithubUtils.js | 8 +++++++- tests/unit/GithubUtilsTest.js | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/libs/GithubUtils.js b/.github/libs/GithubUtils.js index 8930cfa00f5b..59b76c2cb9bc 100644 --- a/.github/libs/GithubUtils.js +++ b/.github/libs/GithubUtils.js @@ -82,7 +82,13 @@ class GithubUtils { * @returns {Array} - [{url: String, number: Number, isVerified: Boolean}] */ getStagingDeployCashPRList(issue) { - const PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/)[1]; + let PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/) || []; + if (PRListSection.length !== 2) { + // No PRs, return an empty array + console.log('Hmmm...The open StagingDeployCash does not list any pull requests, continuing...'); + return []; + } + PRListSection = PRListSection[1]; const unverifiedPRs = _.map( [...PRListSection.matchAll(new RegExp(`- \\[ ] (${PULL_REQUEST_REGEX.source})`, 'g'))], match => ({ diff --git a/tests/unit/GithubUtilsTest.js b/tests/unit/GithubUtilsTest.js index 1f73a65cdbd4..c4f5b0a0f4b7 100644 --- a/tests/unit/GithubUtilsTest.js +++ b/tests/unit/GithubUtilsTest.js @@ -59,8 +59,9 @@ describe('GithubUtils', () => { tag: '1.0.1-47', title: 'Andrew Test Issue', url: 'https://api.github.com/repos/Andrew-Test-Org/Public-Test-Repo/issues/29', + deployBlockers: [], }; - const expectedResponseWithDeployBlockers = baseExpectedResponse; + const expectedResponseWithDeployBlockers = {...baseExpectedResponse}; expectedResponseWithDeployBlockers.deployBlockers = [ { url: 'https://github.com/Expensify/Expensify.cash/issues/1', @@ -79,6 +80,24 @@ describe('GithubUtils', () => { }, ]; + test('Test finding an open issue with no PRs successfully', () => { + const octokit = new Octokit(); + const github = new GithubUtils(octokit); + const bareIssue = { + ...baseIssue, + // eslint-disable-next-line max-len + body: '**Release Version:** `1.0.1-47`\r\n**Compare Changes:** https://github.com/Expensify/Expensify.cash/compare/production...staging\r\n\r\ncc @Expensify/applauseleads\n' + }; + + const bareExpectedResponse = { + ...baseExpectedResponse, + PRList: [], + }; + + octokit.issues.listForRepo = jest.fn().mockResolvedValue({data: [bareIssue]}); + return github.getStagingDeployCash().then(data => expect(data).toStrictEqual(bareExpectedResponse)); + }); + test('Test finding an open issue successfully', () => { const octokit = new Octokit(); const github = new GithubUtils(octokit); From b0798fb7e2098f438be63516a149b11037c33277 Mon Sep 17 00:00:00 2001 From: Rory Abraham Date: Mon, 10 May 2021 14:55:25 -0700 Subject: [PATCH 2/4] Rebuild GH Actions --- .github/actions/checkDeployBlockers/index.js | 8 +++++++- .github/actions/createOrUpdateStagingDeploy/index.js | 8 +++++++- .github/actions/getReleaseBody/index.js | 8 +++++++- .github/actions/isPullRequestMergeable/index.js | 8 +++++++- .github/actions/isStagingDeployLocked/index.js | 8 +++++++- .github/actions/markPullRequestsAsDeployed/index.js | 8 +++++++- .github/actions/reopenIssueWithComment/index.js | 8 +++++++- 7 files changed, 49 insertions(+), 7 deletions(-) diff --git a/.github/actions/checkDeployBlockers/index.js b/.github/actions/checkDeployBlockers/index.js index 0687cbef4598..f34a1d6aefc2 100644 --- a/.github/actions/checkDeployBlockers/index.js +++ b/.github/actions/checkDeployBlockers/index.js @@ -172,7 +172,13 @@ class GithubUtils { * @returns {Array} - [{url: String, number: Number, isVerified: Boolean}] */ getStagingDeployCashPRList(issue) { - const PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/)[1]; + let PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/) || []; + if (PRListSection.length !== 2) { + // No PRs, return an empty array + console.log('Hmmm...The open StagingDeployCash does not list any pull requests, continuing...'); + return []; + } + PRListSection = PRListSection[1]; const unverifiedPRs = _.map( [...PRListSection.matchAll(new RegExp(`- \\[ ] (${PULL_REQUEST_REGEX.source})`, 'g'))], match => ({ diff --git a/.github/actions/createOrUpdateStagingDeploy/index.js b/.github/actions/createOrUpdateStagingDeploy/index.js index 5fc7ffa6c9bc..3fd6c4c9386b 100644 --- a/.github/actions/createOrUpdateStagingDeploy/index.js +++ b/.github/actions/createOrUpdateStagingDeploy/index.js @@ -198,7 +198,13 @@ class GithubUtils { * @returns {Array} - [{url: String, number: Number, isVerified: Boolean}] */ getStagingDeployCashPRList(issue) { - const PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/)[1]; + let PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/) || []; + if (PRListSection.length !== 2) { + // No PRs, return an empty array + console.log('Hmmm...The open StagingDeployCash does not list any pull requests, continuing...'); + return []; + } + PRListSection = PRListSection[1]; const unverifiedPRs = _.map( [...PRListSection.matchAll(new RegExp(`- \\[ ] (${PULL_REQUEST_REGEX.source})`, 'g'))], match => ({ diff --git a/.github/actions/getReleaseBody/index.js b/.github/actions/getReleaseBody/index.js index 0a3cb15cd7e8..f1601e48a833 100644 --- a/.github/actions/getReleaseBody/index.js +++ b/.github/actions/getReleaseBody/index.js @@ -111,7 +111,13 @@ class GithubUtils { * @returns {Array} - [{url: String, number: Number, isVerified: Boolean}] */ getStagingDeployCashPRList(issue) { - const PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/)[1]; + let PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/) || []; + if (PRListSection.length !== 2) { + // No PRs, return an empty array + console.log('Hmmm...The open StagingDeployCash does not list any pull requests, continuing...'); + return []; + } + PRListSection = PRListSection[1]; const unverifiedPRs = _.map( [...PRListSection.matchAll(new RegExp(`- \\[ ] (${PULL_REQUEST_REGEX.source})`, 'g'))], match => ({ diff --git a/.github/actions/isPullRequestMergeable/index.js b/.github/actions/isPullRequestMergeable/index.js index 58042983cfde..e105a86a30a3 100644 --- a/.github/actions/isPullRequestMergeable/index.js +++ b/.github/actions/isPullRequestMergeable/index.js @@ -146,7 +146,13 @@ class GithubUtils { * @returns {Array} - [{url: String, number: Number, isVerified: Boolean}] */ getStagingDeployCashPRList(issue) { - const PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/)[1]; + let PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/) || []; + if (PRListSection.length !== 2) { + // No PRs, return an empty array + console.log('Hmmm...The open StagingDeployCash does not list any pull requests, continuing...'); + return []; + } + PRListSection = PRListSection[1]; const unverifiedPRs = _.map( [...PRListSection.matchAll(new RegExp(`- \\[ ] (${PULL_REQUEST_REGEX.source})`, 'g'))], match => ({ diff --git a/.github/actions/isStagingDeployLocked/index.js b/.github/actions/isStagingDeployLocked/index.js index d3e79e56dacf..d96388a77dc0 100644 --- a/.github/actions/isStagingDeployLocked/index.js +++ b/.github/actions/isStagingDeployLocked/index.js @@ -124,7 +124,13 @@ class GithubUtils { * @returns {Array} - [{url: String, number: Number, isVerified: Boolean}] */ getStagingDeployCashPRList(issue) { - const PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/)[1]; + let PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/) || []; + if (PRListSection.length !== 2) { + // No PRs, return an empty array + console.log('Hmmm...The open StagingDeployCash does not list any pull requests, continuing...'); + return []; + } + PRListSection = PRListSection[1]; const unverifiedPRs = _.map( [...PRListSection.matchAll(new RegExp(`- \\[ ] (${PULL_REQUEST_REGEX.source})`, 'g'))], match => ({ diff --git a/.github/actions/markPullRequestsAsDeployed/index.js b/.github/actions/markPullRequestsAsDeployed/index.js index bd86817652cf..99248d97bdc7 100644 --- a/.github/actions/markPullRequestsAsDeployed/index.js +++ b/.github/actions/markPullRequestsAsDeployed/index.js @@ -157,7 +157,13 @@ class GithubUtils { * @returns {Array} - [{url: String, number: Number, isVerified: Boolean}] */ getStagingDeployCashPRList(issue) { - const PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/)[1]; + let PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/) || []; + if (PRListSection.length !== 2) { + // No PRs, return an empty array + console.log('Hmmm...The open StagingDeployCash does not list any pull requests, continuing...'); + return []; + } + PRListSection = PRListSection[1]; const unverifiedPRs = _.map( [...PRListSection.matchAll(new RegExp(`- \\[ ] (${PULL_REQUEST_REGEX.source})`, 'g'))], match => ({ diff --git a/.github/actions/reopenIssueWithComment/index.js b/.github/actions/reopenIssueWithComment/index.js index 37ac365ae566..557f18c17291 100644 --- a/.github/actions/reopenIssueWithComment/index.js +++ b/.github/actions/reopenIssueWithComment/index.js @@ -135,7 +135,13 @@ class GithubUtils { * @returns {Array} - [{url: String, number: Number, isVerified: Boolean}] */ getStagingDeployCashPRList(issue) { - const PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/)[1]; + let PRListSection = issue.body.match(/pull requests:\*\*\r\n((?:.*\r\n)+)\r\n/) || []; + if (PRListSection.length !== 2) { + // No PRs, return an empty array + console.log('Hmmm...The open StagingDeployCash does not list any pull requests, continuing...'); + return []; + } + PRListSection = PRListSection[1]; const unverifiedPRs = _.map( [...PRListSection.matchAll(new RegExp(`- \\[ ] (${PULL_REQUEST_REGEX.source})`, 'g'))], match => ({ From 556c1e1265250ad031425f978716221a196b2100 Mon Sep 17 00:00:00 2001 From: Rory Abraham Date: Mon, 10 May 2021 14:58:40 -0700 Subject: [PATCH 3/4] Fix JS style --- tests/unit/GithubUtilsTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/GithubUtilsTest.js b/tests/unit/GithubUtilsTest.js index c4f5b0a0f4b7..68a72afd8db0 100644 --- a/tests/unit/GithubUtilsTest.js +++ b/tests/unit/GithubUtilsTest.js @@ -86,7 +86,7 @@ describe('GithubUtils', () => { const bareIssue = { ...baseIssue, // eslint-disable-next-line max-len - body: '**Release Version:** `1.0.1-47`\r\n**Compare Changes:** https://github.com/Expensify/Expensify.cash/compare/production...staging\r\n\r\ncc @Expensify/applauseleads\n' + body: '**Release Version:** `1.0.1-47`\r\n**Compare Changes:** https://github.com/Expensify/Expensify.cash/compare/production...staging\r\n\r\ncc @Expensify/applauseleads\n', }; const bareExpectedResponse = { From 59ff71f8e735995f2b180da17a3e87a9de4c428d Mon Sep 17 00:00:00 2001 From: Rory Abraham Date: Mon, 10 May 2021 15:13:42 -0700 Subject: [PATCH 4/4] Fix tests copying by reference issues --- tests/unit/GithubUtilsTest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/GithubUtilsTest.js b/tests/unit/GithubUtilsTest.js index 68a72afd8db0..8c14182b9556 100644 --- a/tests/unit/GithubUtilsTest.js +++ b/tests/unit/GithubUtilsTest.js @@ -21,9 +21,9 @@ describe('GithubUtils', () => { }, ], // eslint-disable-next-line max-len - body: '**Release Version:** `1.0.1-47`\r\n**Compare Changes:** https://github.com/Expensify/Expensify.cash/compare/production...staging\r\n\r\n**This release contains changes from the following pull requests:**\r\n- [ ] https://github.com/Expensify/Expensify.cash/pull/21\r\n- [x] https://github.com/Expensify/Expensify.cash/pull/22\r\n- [ ] https://github.com/Expensify/Expensify.cash/pull/23\r\n', + body: '**Release Version:** `1.0.1-47`\r\n**Compare Changes:** https://github.com/Expensify/Expensify.cash/compare/production...staging\r\n\r\n**This release contains changes from the following pull requests:**\r\n- [ ] https://github.com/Expensify/Expensify.cash/pull/21\r\n- [x] https://github.com/Expensify/Expensify.cash/pull/22\r\n- [ ] https://github.com/Expensify/Expensify.cash/pull/23\r\n\r\n', }; - const issueWithDeployBlockers = baseIssue; + const issueWithDeployBlockers = {...baseIssue}; // eslint-disable-next-line max-len issueWithDeployBlockers.body += '\r\n**Deploy Blockers:**\r\n- [ ] https://github.com/Expensify/Expensify.cash/issues/1\r\n- [x] https://github.com/Expensify/Expensify.cash/issues/2\r\n- [ ] https://github.com/Expensify/Expensify.cash/pull/1234\r\n';