Skip to content

Commit 2f0b486

Browse files
authored
Merge pull request #10834 from Expensify/andrew-checklist-2
[NO QA]Fix two bugs found with checklist tests
2 parents d73fc07 + 7e34c84 commit 2f0b486

File tree

3 files changed

+61
-63
lines changed

3 files changed

+61
-63
lines changed

.github/actions/javascript/contributorChecklist/contributorChecklist.js

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const core = require('@actions/core');
22
const github = require('@actions/github');
3+
const _ = require('underscore');
34
const GitHubUtils = require('../../../libs/GithubUtils');
45

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

102-
function printUncheckedItems(result) {
103-
const checklist = result.split('\n');
103+
function getPullRequestBody() {
104+
return GitHubUtils.octokit.pulls.get({
105+
owner: GitHubUtils.GITHUB_OWNER,
106+
repo: GitHubUtils.APP_REPO,
107+
pull_number: issue,
108+
}).then(({data: pullRequestComment}) => pullRequestComment.body);
109+
}
104110

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-
});
111+
function getAllReviewComments() {
112+
return GitHubUtils.paginate(GitHubUtils.octokit.pulls.listReviews, {
113+
owner: GitHubUtils.GITHUB_OWNER,
114+
repo: GitHubUtils.APP_REPO,
115+
pull_number: issue,
116+
per_page: 100,
117+
}, response => _.map(response.data, review => review.body));
112118
}
113119

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({
120+
function getAllComments() {
121+
return GitHubUtils.paginate(GitHubUtils.octokit.issues.listComments, {
129122
owner: GitHubUtils.GITHUB_OWNER,
130123
repo: GitHubUtils.APP_REPO,
131124
issue_number: issue,
132125
per_page: 100,
133-
}))
134-
.then(({data: pullRequestComments}) => {
135-
pullRequestComments.forEach(pullRequestComment => combinedData.push(pullRequestComment.body));
126+
}, response => _.map(response.data, comment => comment.body));
127+
}
128+
129+
getPullRequestBody()
130+
.then(pullRequestBody => combinedData.push(pullRequestBody))
131+
.then(() => getAllReviewComments())
132+
.then(reviewComments => combinedData.push(...reviewComments))
133+
.then(() => getAllComments())
134+
.then(comments => combinedData.push(...comments))
135+
.then(() => {
136136
let contributorChecklistComplete = false;
137137
let contributorPlusChecklistComplete = false;
138138

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

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

150148
if (comment.includes(completedContributorPlusChecklist.replace(whitespace, ''))) {
151149
contributorPlusChecklistComplete = true;
152-
} else if (comment.includes('- [')) {
153-
printUncheckedItems(combinedData[i]);
154150
}
155151
}
156152

157153
if (!contributorChecklistComplete) {
154+
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');
158155
core.setFailed('Contributor checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.');
159156
return;
160157
}
161158

162159
if (!contributorPlusChecklistComplete) {
160+
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');
163161
core.setFailed('Contributor plus checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.');
164162
return;
165163
}

.github/actions/javascript/contributorChecklist/index.js

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports =
1010

1111
const core = __nccwpck_require__(2186);
1212
const github = __nccwpck_require__(5438);
13+
const _ = __nccwpck_require__(3571);
1314
const GitHubUtils = __nccwpck_require__(7999);
1415

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

112-
function printUncheckedItems(result) {
113-
const checklist = result.split('\n');
113+
function getPullRequestBody() {
114+
return GitHubUtils.octokit.pulls.get({
115+
owner: GitHubUtils.GITHUB_OWNER,
116+
repo: GitHubUtils.APP_REPO,
117+
pull_number: issue,
118+
}).then(({data: pullRequestComment}) => pullRequestComment.body);
119+
}
114120

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

124-
// Get all user text from the pull request, review comments, and pull request comments
125-
GitHubUtils.octokit.pulls.get({
126-
owner: GitHubUtils.GITHUB_OWNER,
127-
repo: GitHubUtils.APP_REPO,
128-
pull_number: issue,
129-
}).then(({data: pullRequestComment}) => {
130-
combinedData.push(pullRequestComment.body);
131-
}).then(() => GitHubUtils.octokit.pulls.listReviews({
132-
owner: GitHubUtils.GITHUB_OWNER,
133-
repo: GitHubUtils.APP_REPO,
134-
pull_number: issue,
135-
})).then(({data: pullRequestReviewComments}) => {
136-
pullRequestReviewComments.forEach(pullRequestReviewComment => combinedData.push(pullRequestReviewComment.body));
137-
})
138-
.then(() => GitHubUtils.octokit.issues.listComments({
130+
function getAllComments() {
131+
return GitHubUtils.paginate(GitHubUtils.octokit.issues.listComments, {
139132
owner: GitHubUtils.GITHUB_OWNER,
140133
repo: GitHubUtils.APP_REPO,
141134
issue_number: issue,
142135
per_page: 100,
143-
}))
144-
.then(({data: pullRequestComments}) => {
145-
pullRequestComments.forEach(pullRequestComment => combinedData.push(pullRequestComment.body));
136+
}, response => _.map(response.data, comment => comment.body));
137+
}
138+
139+
getPullRequestBody()
140+
.then(pullRequestBody => combinedData.push(pullRequestBody))
141+
.then(() => getAllReviewComments())
142+
.then(reviewComments => combinedData.push(...reviewComments))
143+
.then(() => getAllComments())
144+
.then(comments => combinedData.push(...comments))
145+
.then(() => {
146146
let contributorChecklistComplete = false;
147147
let contributorPlusChecklistComplete = false;
148148

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

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

160158
if (comment.includes(completedContributorPlusChecklist.replace(whitespace, ''))) {
161159
contributorPlusChecklistComplete = true;
162-
} else if (comment.includes('- [')) {
163-
printUncheckedItems(combinedData[i]);
164160
}
165161
}
166162

167163
if (!contributorChecklistComplete) {
164+
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');
168165
core.setFailed('Contributor checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.');
169166
return;
170167
}
171168

172169
if (!contributorPlusChecklistComplete) {
170+
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');
173171
core.setFailed('Contributor plus checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.');
174172
return;
175173
}

.github/workflows/testChecklists.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ name: Contributor Checklist
22

33
on:
44
issue_comment:
5+
types: [created, edited, deleted]
56
pull_request_review:
7+
types: [submitted, edited, dismissed]
68
pull_request:
79
types: [opened, edited, synchronize]
810

911
jobs:
1012
checklist:
1113
runs-on: ubuntu-latest
1214
# Only run when a comment, PR, or PR review comment contains a checklist item
13-
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, '- [')) }}
15+
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, '- ['))
1416
steps:
1517
- name: contributorChecklist.js
1618
uses: Expensify/App/.github/actions/javascript/contributorChecklist@main

0 commit comments

Comments
 (0)