Skip to content

Commit

Permalink
Merge pull request #2771 from Expensify/Rory-FixGetStagingDeployCash
Browse files Browse the repository at this point in the history
[No QA] Fix parsing bug in getStagingDeployCash
  • Loading branch information
AndrewGable authored May 10, 2021
2 parents 6fcfb3f + 59ff71f commit 93a206a
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 11 deletions.
8 changes: 7 additions & 1 deletion .github/actions/checkDeployBlockers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ class GithubUtils {
* @returns {Array<Object>} - [{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 => ({
Expand Down
8 changes: 7 additions & 1 deletion .github/actions/createOrUpdateStagingDeploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ class GithubUtils {
* @returns {Array<Object>} - [{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 => ({
Expand Down
8 changes: 7 additions & 1 deletion .github/actions/getReleaseBody/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ class GithubUtils {
* @returns {Array<Object>} - [{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 => ({
Expand Down
8 changes: 7 additions & 1 deletion .github/actions/isPullRequestMergeable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ class GithubUtils {
* @returns {Array<Object>} - [{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 => ({
Expand Down
8 changes: 7 additions & 1 deletion .github/actions/isStagingDeployLocked/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ class GithubUtils {
* @returns {Array<Object>} - [{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 => ({
Expand Down
8 changes: 7 additions & 1 deletion .github/actions/markPullRequestsAsDeployed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ class GithubUtils {
* @returns {Array<Object>} - [{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 => ({
Expand Down
8 changes: 7 additions & 1 deletion .github/actions/reopenIssueWithComment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,13 @@ class GithubUtils {
* @returns {Array<Object>} - [{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 => ({
Expand Down
8 changes: 7 additions & 1 deletion .github/libs/GithubUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ class GithubUtils {
* @returns {Array<Object>} - [{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 => ({
Expand Down
25 changes: 22 additions & 3 deletions tests/unit/GithubUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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',
Expand All @@ -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);
Expand Down

0 comments on commit 93a206a

Please sign in to comment.