Skip to content

Commit e4426cd

Browse files
authored
Merge pull request Expensify#91103 from Expensify/andrew-hide-help-preview-comments
[No QA] Fix Help preview PR comments
2 parents 96a097d + b860a95 commit e4426cd

8 files changed

Lines changed: 127 additions & 96 deletions

File tree

.github/actions/javascript/postTestBuildComment/action.yml renamed to .github/actions/javascript/postOrReplaceComment/action.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: "Mark Pull Requests as Deployed"
2-
description: "Mark pull requests as deployed on production or staging"
1+
name: "postOrReplaceComment"
2+
description: "Post a test build or custom pull request comment, hiding the previous matching comment"
33
inputs:
44
REPO:
55
description: "Repository to place a comment. Can be App or Mobile-Expensify"
@@ -31,6 +31,12 @@ inputs:
3131
WEB_LINK:
3232
description: "Link for the web build"
3333
required: false
34+
COMMENT_BODY:
35+
description: "Custom comment body. When provided, posts this comment instead of the test build message"
36+
required: false
37+
COMMENT_PREFIX:
38+
description: "Prefix used to find and hide the previous matching comment"
39+
required: true
3440
runs:
3541
using: "node24"
3642
main: "./index.js"

.github/actions/javascript/postTestBuildComment/index.js renamed to .github/actions/javascript/postOrReplaceComment/index.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11538,7 +11538,7 @@ function wrappy (fn, cb) {
1153811538

1153911539
/***/ }),
1154011540

11541-
/***/ 3580:
11541+
/***/ 7071:
1154211542
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
1154311543

1154411544
"use strict";
@@ -11638,7 +11638,7 @@ Built from${appPr ? ` App PR Expensify/App#${appPr}` : ''}${mobileExpensifyPr ?
1163811638
}
1163911639
/** Comment on a single PR */
1164011640
async function commentPR(REPO, PR, message) {
11641-
console.log(`Posting test build comment on #${PR}`);
11641+
console.log(`Posting comment on #${PR}`);
1164211642
try {
1164311643
await GithubUtils_1.default.createComment(REPO, PR, message);
1164411644
console.log(`Comment created on #${PR} (${REPO}) successfully 🎉`);
@@ -11650,10 +11650,37 @@ async function commentPR(REPO, PR, message) {
1165011650
}
1165111651
}
1165211652
}
11653+
async function hidePreviousComment(repo, issueNumber, commentPrefix) {
11654+
const comments = await GithubUtils_1.default.paginate(GithubUtils_1.default.octokit.issues.listComments, {
11655+
owner: CONST_1.default.GITHUB_OWNER,
11656+
repo,
11657+
// eslint-disable-next-line @typescript-eslint/naming-convention
11658+
issue_number: issueNumber,
11659+
// eslint-disable-next-line @typescript-eslint/naming-convention
11660+
per_page: 100,
11661+
}, (response) => response.data);
11662+
const previousComment = comments.findLast((comment) => comment.body?.startsWith(commentPrefix));
11663+
if (!previousComment) {
11664+
return;
11665+
}
11666+
await GithubUtils_1.default.graphql(`
11667+
mutation MinimizeComment($subjectId: ID!) {
11668+
minimizeComment(input: {classifier: OUTDATED, subjectId: $subjectId}) {
11669+
minimizedComment {
11670+
minimizedReason
11671+
}
11672+
}
11673+
}
11674+
`, {
11675+
subjectId: previousComment.node_id,
11676+
});
11677+
}
1165311678
async function run() {
1165411679
const APP_PR_NUMBER = Number(core.getInput('APP_PR_NUMBER', { required: false }));
1165511680
const MOBILE_EXPENSIFY_PR_NUMBER = Number(core.getInput('MOBILE_EXPENSIFY_PR_NUMBER', { required: false }));
1165611681
const REPO = String(core.getInput('REPO', { required: true }));
11682+
const COMMENT_BODY = core.getInput('COMMENT_BODY', { required: false });
11683+
const COMMENT_PREFIX = core.getInput('COMMENT_PREFIX', { required: true });
1165711684
if (REPO !== CONST_1.default.APP_REPO && REPO !== CONST_1.default.MOBILE_EXPENSIFY_REPO) {
1165811685
core.setFailed(`Invalid repository used to place output comment: ${REPO}`);
1165911686
return;
@@ -11663,28 +11690,8 @@ async function run() {
1166311690
return;
1166411691
}
1166511692
const destinationPRNumber = REPO === CONST_1.default.APP_REPO ? APP_PR_NUMBER : MOBILE_EXPENSIFY_PR_NUMBER;
11666-
const comments = await GithubUtils_1.default.paginate(GithubUtils_1.default.octokit.issues.listComments, {
11667-
owner: CONST_1.default.GITHUB_OWNER,
11668-
repo: REPO,
11669-
// eslint-disable-next-line @typescript-eslint/naming-convention
11670-
issue_number: destinationPRNumber,
11671-
// eslint-disable-next-line @typescript-eslint/naming-convention
11672-
per_page: 100,
11673-
}, (response) => response.data);
11674-
const testBuildComment = comments.find((comment) => comment.body?.startsWith(':test_tube::test_tube: Use the links below to test this adhoc build'));
11675-
if (testBuildComment) {
11676-
console.log('Found previous build comment, hiding it', testBuildComment);
11677-
await GithubUtils_1.default.graphql(`
11678-
mutation {
11679-
minimizeComment(input: {classifier: OUTDATED, subjectId: "${testBuildComment.node_id}"}) {
11680-
minimizedComment {
11681-
minimizedReason
11682-
}
11683-
}
11684-
}
11685-
`);
11686-
}
11687-
await commentPR(REPO, destinationPRNumber, getTestBuildMessage(APP_PR_NUMBER, MOBILE_EXPENSIFY_PR_NUMBER));
11693+
await hidePreviousComment(REPO, destinationPRNumber, COMMENT_PREFIX);
11694+
await commentPR(REPO, destinationPRNumber, COMMENT_BODY || getTestBuildMessage(APP_PR_NUMBER, MOBILE_EXPENSIFY_PR_NUMBER));
1168811695
}
1168911696
if (require.main === require.cache[eval('__filename')]) {
1169011697
run();
@@ -12402,7 +12409,7 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
1240212409
/******/ // startup
1240312410
/******/ // Load entry module and return exports
1240412411
/******/ // This entry module is referenced by other modules so it can't be inlined
12405-
/******/ var __webpack_exports__ = __nccwpck_require__(3580);
12412+
/******/ var __webpack_exports__ = __nccwpck_require__(7071);
1240612413
/******/ module.exports = __webpack_exports__;
1240712414
/******/
1240812415
/******/ })()

.github/actions/javascript/postTestBuildComment/postTestBuildComment.ts renamed to .github/actions/javascript/postOrReplaceComment/postOrReplaceComment.ts

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Built from${appPr ? ` App PR Expensify/App#${appPr}` : ''}${mobileExpensifyPr ?
6868

6969
/** Comment on a single PR */
7070
async function commentPR(REPO: string, PR: number, message: string) {
71-
console.log(`Posting test build comment on #${PR}`);
71+
console.log(`Posting comment on #${PR}`);
7272
try {
7373
await GithubUtils.createComment(REPO, PR, message);
7474
console.log(`Comment created on #${PR} (${REPO}) successfully 🎉`);
@@ -81,48 +81,61 @@ async function commentPR(REPO: string, PR: number, message: string) {
8181
}
8282
}
8383

84-
async function run() {
85-
const APP_PR_NUMBER = Number(core.getInput('APP_PR_NUMBER', {required: false}));
86-
const MOBILE_EXPENSIFY_PR_NUMBER = Number(core.getInput('MOBILE_EXPENSIFY_PR_NUMBER', {required: false}));
87-
const REPO = String(core.getInput('REPO', {required: true}));
88-
89-
if (REPO !== CONST.APP_REPO && REPO !== CONST.MOBILE_EXPENSIFY_REPO) {
90-
core.setFailed(`Invalid repository used to place output comment: ${REPO}`);
91-
return;
92-
}
93-
94-
if ((REPO === CONST.APP_REPO && !APP_PR_NUMBER) || (REPO === CONST.MOBILE_EXPENSIFY_REPO && !MOBILE_EXPENSIFY_PR_NUMBER)) {
95-
core.setFailed(`Please provide ${REPO} pull request number`);
96-
return;
97-
}
98-
99-
const destinationPRNumber = REPO === CONST.APP_REPO ? APP_PR_NUMBER : MOBILE_EXPENSIFY_PR_NUMBER;
84+
async function hidePreviousComment(repo: string, issueNumber: number, commentPrefix: string): Promise<void> {
10085
const comments = await GithubUtils.paginate(
10186
GithubUtils.octokit.issues.listComments,
10287
{
10388
owner: CONST.GITHUB_OWNER,
104-
repo: REPO,
89+
repo,
10590
// eslint-disable-next-line @typescript-eslint/naming-convention
106-
issue_number: destinationPRNumber,
91+
issue_number: issueNumber,
10792
// eslint-disable-next-line @typescript-eslint/naming-convention
10893
per_page: 100,
10994
},
11095
(response) => response.data,
11196
);
112-
const testBuildComment = comments.find((comment) => comment.body?.startsWith(':test_tube::test_tube: Use the links below to test this adhoc build'));
113-
if (testBuildComment) {
114-
console.log('Found previous build comment, hiding it', testBuildComment);
115-
await GithubUtils.graphql(`
116-
mutation {
117-
minimizeComment(input: {classifier: OUTDATED, subjectId: "${testBuildComment.node_id}"}) {
97+
const previousComment = comments.findLast((comment) => comment.body?.startsWith(commentPrefix));
98+
99+
if (!previousComment) {
100+
return;
101+
}
102+
103+
await GithubUtils.graphql(
104+
`
105+
mutation MinimizeComment($subjectId: ID!) {
106+
minimizeComment(input: {classifier: OUTDATED, subjectId: $subjectId}) {
118107
minimizedComment {
119108
minimizedReason
120109
}
121110
}
122111
}
123-
`);
112+
`,
113+
{
114+
subjectId: previousComment.node_id,
115+
},
116+
);
117+
}
118+
119+
async function run() {
120+
const APP_PR_NUMBER = Number(core.getInput('APP_PR_NUMBER', {required: false}));
121+
const MOBILE_EXPENSIFY_PR_NUMBER = Number(core.getInput('MOBILE_EXPENSIFY_PR_NUMBER', {required: false}));
122+
const REPO = String(core.getInput('REPO', {required: true}));
123+
const COMMENT_BODY = core.getInput('COMMENT_BODY', {required: false});
124+
const COMMENT_PREFIX = core.getInput('COMMENT_PREFIX', {required: true});
125+
126+
if (REPO !== CONST.APP_REPO && REPO !== CONST.MOBILE_EXPENSIFY_REPO) {
127+
core.setFailed(`Invalid repository used to place output comment: ${REPO}`);
128+
return;
129+
}
130+
131+
if ((REPO === CONST.APP_REPO && !APP_PR_NUMBER) || (REPO === CONST.MOBILE_EXPENSIFY_REPO && !MOBILE_EXPENSIFY_PR_NUMBER)) {
132+
core.setFailed(`Please provide ${REPO} pull request number`);
133+
return;
124134
}
125-
await commentPR(REPO, destinationPRNumber, getTestBuildMessage(APP_PR_NUMBER, MOBILE_EXPENSIFY_PR_NUMBER));
135+
136+
const destinationPRNumber = REPO === CONST.APP_REPO ? APP_PR_NUMBER : MOBILE_EXPENSIFY_PR_NUMBER;
137+
await hidePreviousComment(REPO, destinationPRNumber, COMMENT_PREFIX);
138+
await commentPR(REPO, destinationPRNumber, COMMENT_BODY || getTestBuildMessage(APP_PR_NUMBER, MOBILE_EXPENSIFY_PR_NUMBER));
126139
}
127140

128141
if (require.main === module) {

.github/scripts/buildActions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ declare -r GITHUB_ACTIONS=(
2525
"$ACTIONS_DIR/getPullRequestIncrementalChanges/getPullRequestIncrementalChanges.ts"
2626
"$ACTIONS_DIR/isDeployChecklistLocked/isDeployChecklistLocked.ts"
2727
"$ACTIONS_DIR/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts"
28-
"$ACTIONS_DIR/postTestBuildComment/postTestBuildComment.ts"
28+
"$ACTIONS_DIR/postOrReplaceComment/postOrReplaceComment.ts"
2929
"$ACTIONS_DIR/proposalPoliceComment/proposalPoliceComment.ts"
3030
"$ACTIONS_DIR/reopenIssueWithComment/reopenIssueWithComment.ts"
3131
"$ACTIONS_DIR/reviewerChecklist/reviewerChecklist.ts"

.github/workflows/buildAdHoc.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,13 @@ jobs:
147147

148148
- name: Publish links to apps for download on Expensify/App PR
149149
if: ${{ inputs.APP_PR_NUMBER != '' }}
150-
uses: ./.github/actions/javascript/postTestBuildComment
150+
uses: ./.github/actions/javascript/postOrReplaceComment
151151
with:
152152
REPO: App
153153
APP_PR_NUMBER: ${{ inputs.APP_PR_NUMBER }}
154154
MOBILE_EXPENSIFY_PR_NUMBER: ${{ inputs.MOBILE_EXPENSIFY_PR }}
155155
GITHUB_TOKEN: ${{ github.token }}
156+
COMMENT_PREFIX: ':test_tube::test_tube: Use the links below to test this adhoc build'
156157
ANDROID: ${{ needs.buildAndroid.result }}
157158
IOS: ${{ needs.buildIOS.result }}
158159
WEB: ${{ needs.buildWeb.result == 'failure' && 'failure' || needs.deployWebAdHoc.result }}
@@ -162,11 +163,12 @@ jobs:
162163

163164
- name: Publish links to apps for download on Expensify/Mobile-Expensify PR
164165
if: ${{ inputs.MOBILE_EXPENSIFY_PR != '' }}
165-
uses: ./.github/actions/javascript/postTestBuildComment
166+
uses: ./.github/actions/javascript/postOrReplaceComment
166167
with:
167168
REPO: Mobile-Expensify
168169
MOBILE_EXPENSIFY_PR_NUMBER: ${{ inputs.MOBILE_EXPENSIFY_PR }}
169170
GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}
171+
COMMENT_PREFIX: ':test_tube::test_tube: Use the links below to test this adhoc build'
170172
ANDROID: ${{ needs.buildAndroid.result }}
171173
IOS: ${{ needs.buildIOS.result }}
172174
ANDROID_LINK: ${{ needs.buildAndroid.outputs.ROCK_ARTIFACT_URL }}

.github/workflows/deployExpensifyHelp.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ jobs:
125125
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
126126

127127
- name: Leave a comment on the PR
128-
uses: actions-cool/maintain-one-comment@de04bd2a3750d86b324829a3ff34d47e48e16f4b
128+
uses: ./.github/actions/javascript/postOrReplaceComment
129129
if: ${{ github.event_name == 'pull_request' && env.IS_PR_FROM_FORK != 'true' }}
130130
with:
131-
token: ${{ secrets.OS_BOTIFY_TOKEN }}
132-
body: ${{ steps.preview_comment.outputs.BODY }}
131+
REPO: App
132+
APP_PR_NUMBER: ${{ github.event.pull_request.number }}
133+
GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}
134+
COMMENT_PREFIX: A preview of your ExpensifyHelp changes have been deployed to
135+
COMMENT_BODY: ${{ steps.preview_comment.outputs.BODY }}

.github/workflows/deployNewHelp.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ jobs:
8888

8989
# After deploying Cloudflare preview build, share wherever it deployed to in the PR comment.
9090
- name: Leave a comment on the PR
91-
# v3.2.0
92-
uses: actions-cool/maintain-one-comment@4b2dbf086015f892dcb5e8c1106f5fccd6c1476b
91+
uses: ./.github/actions/javascript/postOrReplaceComment
9392
if: ${{ github.event_name == 'pull_request' && env.IS_PR_FROM_FORK != 'true' }}
9493
with:
95-
token: ${{ github.token }}
96-
body: ${{ format('Your New Help changes have been deployed to {0} :zap:️', steps.cloudflarePagesAction.outputs.alias) }}
94+
REPO: App
95+
APP_PR_NUMBER: ${{ github.event.pull_request.number }}
96+
GITHUB_TOKEN: ${{ github.token }}
97+
COMMENT_PREFIX: Your New Help changes have been deployed to
98+
COMMENT_BODY: ${{ format('Your New Help changes have been deployed to {0} :zap:️', steps.cloudflarePagesAction.outputs.alias) }}
9799

98100
- name: Get merged pull request
99101
if: ${{ github.event_name == 'push' }}

0 commit comments

Comments
 (0)