|
| 1 | +const core = require('@actions/core'); |
| 2 | +const github = require('@actions/github'); |
| 3 | +const GitHubUtils = require('../../../libs/GithubUtils'); |
| 4 | + |
| 5 | +/* eslint-disable max-len */ |
| 6 | +const completedContributorChecklist = `- [x] I linked the correct issue in the \`### Fixed Issues\` section above |
| 7 | +- [x] I wrote clear testing steps that cover the changes made in this PR |
| 8 | + - [x] I added steps for local testing in the \`Tests\` section |
| 9 | + - [x] I added steps for Staging and/or Production testing in the \`QA steps\` section |
| 10 | + - [x] I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct) |
| 11 | + - [x] I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline) |
| 12 | +- [x] I included screenshots or videos for tests on [all platforms](https://github.com/Expensify/App/blob/main/contributingGuides/CONTRIBUTING.md#make-sure-you-can-test-on-all-platforms) |
| 13 | +- [x] I ran the tests on **all platforms** & verified they passed on: |
| 14 | + - [x] iOS / native |
| 15 | + - [x] Android / native |
| 16 | + - [x] iOS / Safari |
| 17 | + - [x] Android / Chrome |
| 18 | + - [x] MacOS / Chrome |
| 19 | + - [x] MacOS / Desktop |
| 20 | +- [x] I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed) |
| 21 | +- [x] I followed proper code patterns (see [Reviewing the code](https://github.com/Expensify/App/blob/main/contributingGuides/PR_REVIEW_GUIDELINES.md#reviewing-the-code)) |
| 22 | + - [x] I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. \`toggleReport\` and not \`onIconClick\`) |
| 23 | + - [x] I verified that comments were added to code that is not self explanatory |
| 24 | + - [x] I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing. |
| 25 | + - [x] I verified any copy / text shown in the product was added in all \`src/languages/*\` files |
| 26 | + - [x] I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy. |
| 27 | + - [x] I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README. |
| 28 | + - [x] I verified the JSDocs style guidelines (in [\`STYLE.md\`](https://github.com/Expensify/App/blob/main/contributingGuides/STYLE.md#jsdocs)) were followed |
| 29 | +- [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers |
| 30 | +- [x] I followed the guidelines as stated in the [Review Guidelines](https://github.com/Expensify/App/blob/main/contributingGuides/PR_REVIEW_GUIDELINES.md) |
| 31 | +- [x] I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like \`Avatar\`, I verified the components using \`Avatar\` are working as expected) |
| 32 | +- [x] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests) |
| 33 | +- [x] I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such |
| 34 | +- [x] If a new component is created I verified that: |
| 35 | + - [x] A similar component doesn't exist in the codebase |
| 36 | + - [x] All props are defined accurately and each prop has a \`/** comment above it */\` |
| 37 | + - [x] Any functional components have the \`displayName\` property |
| 38 | + - [x] The file is named correctly |
| 39 | + - [x] The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone |
| 40 | + - [x] The only data being stored in the state is data necessary for rendering and nothing else |
| 41 | + - [x] For Class Components, any internal methods passed to components event handlers are bound to \`this\` properly so there are no scoping issues (i.e. for \`onClick={this.submit}\` the method \`this.submit\` should be bound to \`this\` in the constructor) |
| 42 | + - [x] Any internal methods bound to \`this\` are necessary to be bound (i.e. avoid \`this.submit = this.submit.bind(this);\` if \`this.submit\` is never passed to a component event handler like \`onClick\`) |
| 43 | + - [x] All JSX used for rendering exists in the render method |
| 44 | + - [x] The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions |
| 45 | +- [x] If a new CSS style is added I verified that: |
| 46 | + - [x] A similar style doesn't already exist |
| 47 | + - [x] The style can't be created with an existing [StyleUtils](https://github.com/Expensify/App/blob/main/src/styles/StyleUtils.js) function (i.e. \`StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG\`) |
| 48 | +- [x] If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like \`Avatar\` is modified, I verified that \`Avatar\` is working as expected in all cases) |
| 49 | +- [x] If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected. |
| 50 | +- [x] I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.`; |
| 51 | + |
| 52 | +const completedContributorPlusChecklist = `- [x] I have verified the author checklist is complete (all boxes are checked off). |
| 53 | +- [x] I verified the correct issue is linked in the \`### Fixed Issues\` section above |
| 54 | +- [x] I verified testing steps are clear and they cover the changes made in this PR |
| 55 | + - [x] I verified the steps for local testing are in the \`Tests\` section |
| 56 | + - [x] I verified the steps for Staging and/or Production testing are in the \`QA steps\` section |
| 57 | + - [x] I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct) |
| 58 | + - [x] I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline) |
| 59 | +- [x] I checked that screenshots or videos are included for tests on [all platforms](https://github.com/Expensify/App/blob/main/contributingGuides/CONTRIBUTING.md#make-sure-you-can-test-on-all-platforms) |
| 60 | +- [x] I verified tests pass on **all platforms** & I tested again on: |
| 61 | + - [x] iOS / native |
| 62 | + - [x] Android / native |
| 63 | + - [x] iOS / Safari |
| 64 | + - [x] Android / Chrome |
| 65 | + - [x] MacOS / Chrome |
| 66 | + - [x] MacOS / Desktop |
| 67 | +- [x] I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed) |
| 68 | +- [x] I verified proper code patterns were followed (see [Reviewing the code](https://github.com/Expensify/App/blob/main/contributingGuides/PR_REVIEW_GUIDELINES.md#reviewing-the-code)) |
| 69 | + - [x] I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. \`toggleReport\` and not \`onIconClick\`). |
| 70 | + - [x] I verified that comments were added to code that is not self explanatory |
| 71 | + - [x] I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing. |
| 72 | + - [x] I verified any copy / text shown in the product was added in all \`src/languages/*\` files |
| 73 | + - [x] I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy. |
| 74 | + - [x] I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README. |
| 75 | + - [x] I verified the JSDocs style guidelines (in [\`STYLE.md\`](https://github.com/Expensify/App/blob/main/contributingGuides/STYLE.md#jsdocs)) were followed |
| 76 | +- [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers |
| 77 | +- [x] I verified that this PR follows the guidelines as stated in the [Review Guidelines](https://github.com/Expensify/App/blob/main/contributingGuides/PR_REVIEW_GUIDELINES.md) |
| 78 | +- [x] I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like \`Avatar\`, I verified the components using \`Avatar\` have been tested & I retested again) |
| 79 | +- [x] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests) |
| 80 | +- [x] I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such |
| 81 | +- [x] If a new component is created I verified that: |
| 82 | + - [x] A similar component doesn't exist in the codebase |
| 83 | + - [x] All props are defined accurately and each prop has a \`/** comment above it */\` |
| 84 | + - [x] Any functional components have the \`displayName\` property |
| 85 | + - [x] The file is named correctly |
| 86 | + - [x] The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone |
| 87 | + - [x] The only data being stored in the state is data necessary for rendering and nothing else |
| 88 | + - [x] For Class Components, any internal methods passed to components event handlers are bound to \`this\` properly so there are no scoping issues (i.e. for \`onClick={this.submit}\` the method \`this.submit\` should be bound to \`this\` in the constructor) |
| 89 | + - [x] Any internal methods bound to \`this\` are necessary to be bound (i.e. avoid \`this.submit = this.submit.bind(this);\` if \`this.submit\` is never passed to a component event handler like \`onClick\`) |
| 90 | + - [x] All JSX used for rendering exists in the render method |
| 91 | + - [x] The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions |
| 92 | +- [x] If a new CSS style is added I verified that: |
| 93 | + - [x] A similar style doesn't already exist |
| 94 | + - [x] The style can't be created with an existing [StyleUtils](https://github.com/Expensify/App/blob/main/src/styles/StyleUtils.js) function (i.e. \`StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG\`) |
| 95 | +- [x] If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like \`Avatar\` is modified, I verified that \`Avatar\` is working as expected in all cases) |
| 96 | +- [x] If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected. |
| 97 | +- [x] I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.`; |
| 98 | + |
| 99 | +const issue = github.context.payload.issue ? github.context.payload.issue.number : github.context.payload.pull_request.number; |
| 100 | +const combinedData = []; |
| 101 | + |
| 102 | +function printUncheckedItems(result) { |
| 103 | + const checklist = result.split('\n'); |
| 104 | + |
| 105 | + checklist.forEach((line) => { |
| 106 | + // Provide a search string with the first 30 characters to figure out if the checkbox item is in the checklist |
| 107 | + const lineSearchString = line.replace('- [ ] ', '').slice(0, 30); |
| 108 | + if (line.includes('- [ ]') && (completedContributorChecklist.includes(lineSearchString) || completedContributorPlusChecklist.includes(lineSearchString))) { |
| 109 | + console.log(`Unchecked checklist item: ${line}`); |
| 110 | + } |
| 111 | + }); |
| 112 | +} |
| 113 | + |
| 114 | +// Get all user text from the pull request, review comments, and pull request comments |
| 115 | +GitHubUtils.octokit.pulls.get({ |
| 116 | + owner: GitHubUtils.GITHUB_OWNER, |
| 117 | + repo: GitHubUtils.APP_REPO, |
| 118 | + pull_number: issue, |
| 119 | +}).then(({data: pullRequestComment}) => { |
| 120 | + combinedData.push(pullRequestComment.body); |
| 121 | +}).then(() => GitHubUtils.octokit.pulls.listReviews({ |
| 122 | + owner: GitHubUtils.GITHUB_OWNER, |
| 123 | + repo: GitHubUtils.APP_REPO, |
| 124 | + pull_number: issue, |
| 125 | +})).then(({data: pullRequestReviewComments}) => { |
| 126 | + pullRequestReviewComments.forEach(pullRequestReviewComment => combinedData.push(pullRequestReviewComment.body)); |
| 127 | +}) |
| 128 | + .then(() => GitHubUtils.octokit.issues.listComments({ |
| 129 | + owner: GitHubUtils.GITHUB_OWNER, |
| 130 | + repo: GitHubUtils.APP_REPO, |
| 131 | + issue_number: issue, |
| 132 | + per_page: 100, |
| 133 | + })) |
| 134 | + .then(({data: pullRequestComments}) => { |
| 135 | + pullRequestComments.forEach(pullRequestComment => combinedData.push(pullRequestComment.body)); |
| 136 | + let contributorChecklistComplete = false; |
| 137 | + let contributorPlusChecklistComplete = false; |
| 138 | + |
| 139 | + // Once we've gathered all the data, loop through each comment and look to see if it contains a completed checklist |
| 140 | + for (let i = 0; i < combinedData.length; i++) { |
| 141 | + const whitespace = /([\n\r])/gm; |
| 142 | + const comment = combinedData[i].replace(whitespace, ''); |
| 143 | + |
| 144 | + if (comment.includes(completedContributorChecklist.replace(whitespace, ''))) { |
| 145 | + contributorChecklistComplete = true; |
| 146 | + } else if (comment.includes('- [')) { |
| 147 | + printUncheckedItems(combinedData[i]); |
| 148 | + } |
| 149 | + |
| 150 | + if (comment.includes(completedContributorPlusChecklist.replace(whitespace, ''))) { |
| 151 | + contributorPlusChecklistComplete = true; |
| 152 | + } else if (comment.includes('- [')) { |
| 153 | + printUncheckedItems(combinedData[i]); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + if (!contributorChecklistComplete) { |
| 158 | + core.setFailed('Contributor checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.'); |
| 159 | + return; |
| 160 | + } |
| 161 | + |
| 162 | + if (!contributorPlusChecklistComplete) { |
| 163 | + core.setFailed('Contributor plus checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.'); |
| 164 | + return; |
| 165 | + } |
| 166 | + |
| 167 | + console.log('All checklists are complete 🎉'); |
| 168 | + }); |
0 commit comments