Skip to content

Commit

Permalink
Merge pull request #10834 from Expensify/andrew-checklist-2
Browse files Browse the repository at this point in the history
[NO QA]Fix two bugs found with checklist tests
  • Loading branch information
AndrewGable authored Sep 6, 2022
2 parents d73fc07 + 7e34c84 commit 2f0b486
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const core = require('@actions/core');
const github = require('@actions/github');
const _ = require('underscore');
const GitHubUtils = require('../../../libs/GithubUtils');

/* eslint-disable max-len */
Expand Down Expand Up @@ -99,40 +100,39 @@ const completedContributorPlusChecklist = `- [x] I have verified the author chec
const issue = github.context.payload.issue ? github.context.payload.issue.number : github.context.payload.pull_request.number;
const combinedData = [];

function printUncheckedItems(result) {
const checklist = result.split('\n');
function getPullRequestBody() {
return GitHubUtils.octokit.pulls.get({
owner: GitHubUtils.GITHUB_OWNER,
repo: GitHubUtils.APP_REPO,
pull_number: issue,
}).then(({data: pullRequestComment}) => pullRequestComment.body);
}

checklist.forEach((line) => {
// Provide a search string with the first 30 characters to figure out if the checkbox item is in the checklist
const lineSearchString = line.replace('- [ ] ', '').slice(0, 30);
if (line.includes('- [ ]') && (completedContributorChecklist.includes(lineSearchString) || completedContributorPlusChecklist.includes(lineSearchString))) {
console.log(`Unchecked checklist item: ${line}`);
}
});
function getAllReviewComments() {
return GitHubUtils.paginate(GitHubUtils.octokit.pulls.listReviews, {
owner: GitHubUtils.GITHUB_OWNER,
repo: GitHubUtils.APP_REPO,
pull_number: issue,
per_page: 100,
}, response => _.map(response.data, review => review.body));
}

// Get all user text from the pull request, review comments, and pull request comments
GitHubUtils.octokit.pulls.get({
owner: GitHubUtils.GITHUB_OWNER,
repo: GitHubUtils.APP_REPO,
pull_number: issue,
}).then(({data: pullRequestComment}) => {
combinedData.push(pullRequestComment.body);
}).then(() => GitHubUtils.octokit.pulls.listReviews({
owner: GitHubUtils.GITHUB_OWNER,
repo: GitHubUtils.APP_REPO,
pull_number: issue,
})).then(({data: pullRequestReviewComments}) => {
pullRequestReviewComments.forEach(pullRequestReviewComment => combinedData.push(pullRequestReviewComment.body));
})
.then(() => GitHubUtils.octokit.issues.listComments({
function getAllComments() {
return GitHubUtils.paginate(GitHubUtils.octokit.issues.listComments, {
owner: GitHubUtils.GITHUB_OWNER,
repo: GitHubUtils.APP_REPO,
issue_number: issue,
per_page: 100,
}))
.then(({data: pullRequestComments}) => {
pullRequestComments.forEach(pullRequestComment => combinedData.push(pullRequestComment.body));
}, response => _.map(response.data, comment => comment.body));
}

getPullRequestBody()
.then(pullRequestBody => combinedData.push(pullRequestBody))
.then(() => getAllReviewComments())
.then(reviewComments => combinedData.push(...reviewComments))
.then(() => getAllComments())
.then(comments => combinedData.push(...comments))
.then(() => {
let contributorChecklistComplete = false;
let contributorPlusChecklistComplete = false;

Expand All @@ -143,23 +143,21 @@ GitHubUtils.octokit.pulls.get({

if (comment.includes(completedContributorChecklist.replace(whitespace, ''))) {
contributorChecklistComplete = true;
} else if (comment.includes('- [')) {
printUncheckedItems(combinedData[i]);
}

if (comment.includes(completedContributorPlusChecklist.replace(whitespace, ''))) {
contributorPlusChecklistComplete = true;
} else if (comment.includes('- [')) {
printUncheckedItems(combinedData[i]);
}
}

if (!contributorChecklistComplete) {
console.log('Make sure you are using the most up to date checklist found here: https://raw.githubusercontent.com/Expensify/App/main/.github/PULL_REQUEST_TEMPLATE.md');
core.setFailed('Contributor checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.');
return;
}

if (!contributorPlusChecklistComplete) {
console.log('Make sure you are using the most up to date checklist found here: https://raw.githubusercontent.com/Expensify/App/main/.github/PULL_REQUEST_TEMPLATE.md');
core.setFailed('Contributor plus checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.');
return;
}
Expand Down
60 changes: 29 additions & 31 deletions .github/actions/javascript/contributorChecklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports =

const core = __nccwpck_require__(2186);
const github = __nccwpck_require__(5438);
const _ = __nccwpck_require__(3571);
const GitHubUtils = __nccwpck_require__(7999);

/* eslint-disable max-len */
Expand Down Expand Up @@ -109,40 +110,39 @@ const completedContributorPlusChecklist = `- [x] I have verified the author chec
const issue = github.context.payload.issue ? github.context.payload.issue.number : github.context.payload.pull_request.number;
const combinedData = [];

function printUncheckedItems(result) {
const checklist = result.split('\n');
function getPullRequestBody() {
return GitHubUtils.octokit.pulls.get({
owner: GitHubUtils.GITHUB_OWNER,
repo: GitHubUtils.APP_REPO,
pull_number: issue,
}).then(({data: pullRequestComment}) => pullRequestComment.body);
}

checklist.forEach((line) => {
// Provide a search string with the first 30 characters to figure out if the checkbox item is in the checklist
const lineSearchString = line.replace('- [ ] ', '').slice(0, 30);
if (line.includes('- [ ]') && (completedContributorChecklist.includes(lineSearchString) || completedContributorPlusChecklist.includes(lineSearchString))) {
console.log(`Unchecked checklist item: ${line}`);
}
});
function getAllReviewComments() {
return GitHubUtils.paginate(GitHubUtils.octokit.pulls.listReviews, {
owner: GitHubUtils.GITHUB_OWNER,
repo: GitHubUtils.APP_REPO,
pull_number: issue,
per_page: 100,
}, response => _.map(response.data, review => review.body));
}

// Get all user text from the pull request, review comments, and pull request comments
GitHubUtils.octokit.pulls.get({
owner: GitHubUtils.GITHUB_OWNER,
repo: GitHubUtils.APP_REPO,
pull_number: issue,
}).then(({data: pullRequestComment}) => {
combinedData.push(pullRequestComment.body);
}).then(() => GitHubUtils.octokit.pulls.listReviews({
owner: GitHubUtils.GITHUB_OWNER,
repo: GitHubUtils.APP_REPO,
pull_number: issue,
})).then(({data: pullRequestReviewComments}) => {
pullRequestReviewComments.forEach(pullRequestReviewComment => combinedData.push(pullRequestReviewComment.body));
})
.then(() => GitHubUtils.octokit.issues.listComments({
function getAllComments() {
return GitHubUtils.paginate(GitHubUtils.octokit.issues.listComments, {
owner: GitHubUtils.GITHUB_OWNER,
repo: GitHubUtils.APP_REPO,
issue_number: issue,
per_page: 100,
}))
.then(({data: pullRequestComments}) => {
pullRequestComments.forEach(pullRequestComment => combinedData.push(pullRequestComment.body));
}, response => _.map(response.data, comment => comment.body));
}

getPullRequestBody()
.then(pullRequestBody => combinedData.push(pullRequestBody))
.then(() => getAllReviewComments())
.then(reviewComments => combinedData.push(...reviewComments))
.then(() => getAllComments())
.then(comments => combinedData.push(...comments))
.then(() => {
let contributorChecklistComplete = false;
let contributorPlusChecklistComplete = false;

Expand All @@ -153,23 +153,21 @@ GitHubUtils.octokit.pulls.get({

if (comment.includes(completedContributorChecklist.replace(whitespace, ''))) {
contributorChecklistComplete = true;
} else if (comment.includes('- [')) {
printUncheckedItems(combinedData[i]);
}

if (comment.includes(completedContributorPlusChecklist.replace(whitespace, ''))) {
contributorPlusChecklistComplete = true;
} else if (comment.includes('- [')) {
printUncheckedItems(combinedData[i]);
}
}

if (!contributorChecklistComplete) {
console.log('Make sure you are using the most up to date checklist found here: https://raw.githubusercontent.com/Expensify/App/main/.github/PULL_REQUEST_TEMPLATE.md');
core.setFailed('Contributor checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.');
return;
}

if (!contributorPlusChecklistComplete) {
console.log('Make sure you are using the most up to date checklist found here: https://raw.githubusercontent.com/Expensify/App/main/.github/PULL_REQUEST_TEMPLATE.md');
core.setFailed('Contributor plus checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.');
return;
}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/testChecklists.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ name: Contributor Checklist

on:
issue_comment:
types: [created, edited, deleted]
pull_request_review:
types: [submitted, edited, dismissed]
pull_request:
types: [opened, edited, synchronize]

jobs:
checklist:
runs-on: ubuntu-latest
# Only run when a comment, PR, or PR review comment contains a checklist item
if: ${{ github.actor != 'OSBotify' || (github.event.issue.pull_request && github.event_name == 'issue_comment' && contains(github.event.comment.body, '- [') || github.event_name == 'pull_request_review' && contains(github.event.review.body, '- [') || github.event_name == 'pull_request' && contains(github.event.pull_request.body, '- [')) }}
if: github.actor != 'OSBotify' && (contains(github.event.issue.pull_request.url, 'http') && github.event_name == 'issue_comment' && contains(github.event.comment.body, '- [') || github.event_name == 'pull_request_review' && contains(github.event.review.body, '- [') || github.event_name == 'pull_request' && contains(github.event.pull_request.body, '- ['))
steps:
- name: contributorChecklist.js
uses: Expensify/App/.github/actions/javascript/contributorChecklist@main
Expand Down

0 comments on commit 2f0b486

Please sign in to comment.