Skip to content

Commit 37cda49

Browse files
authored
[PM-24744] Remove past BIT status comments on originating issue (#379)
* shorten and clarify PR comments * remove past BIT status comments on originating issue
1 parent 7c3c49d commit 37cda49

File tree

2 files changed

+138
-17
lines changed

2 files changed

+138
-17
lines changed

.github/workflows/test-all-custom-flags.yml

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,46 @@ jobs:
187187
./tests-out/videos
188188
./tests-out/screenshots
189189
190-
# Only post back to the PR if there was a failure since test-all has the
191-
# typical config case covered for success feedback
190+
- name: Remove past BIT status comments on originating issue
191+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
192+
if: steps.set-send-pr-feedback.outputs.send_pr_feedback == 'true'
193+
with:
194+
github-token: ${{ steps.app-token.outputs.token }}
195+
script: |
196+
// Note: should match the first line of `message` in the communication steps
197+
const workflowCommentTag = '<!-- comment_tag: test-all-custom-flags -->';
198+
199+
const owner = 'bitwarden';
200+
201+
const issueComments = await github.rest.issues.listComments({
202+
issue_number: context.payload.client_payload.origin_issue,
203+
owner: owner,
204+
repo: 'clients',
205+
});
206+
207+
for (const comment of issueComments.data || []) {
208+
const shouldDeleteComment =
209+
// Do not delete comments that were not automated
210+
!!comment.performed_via_github_app &&
211+
212+
// Do not delete user comments
213+
comment.user.type === 'Bot' &&
214+
215+
// Do not delete edited comments
216+
comment.created_at === comment.updated_at &&
217+
218+
// Only delete comments from this workflow
219+
comment.body.trim().startsWith(workflowCommentTag);
220+
221+
if (shouldDeleteComment) {
222+
await github.rest.issues.deleteComment({
223+
comment_id: comment.id,
224+
owner: owner,
225+
repo: 'clients',
226+
});
227+
}
228+
}
229+
192230
- name: Communicate BIT failure on originating issue
193231
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
194232
if: failure() && steps.set-send-pr-feedback.outputs.send_pr_feedback == 'true'
@@ -197,17 +235,51 @@ jobs:
197235
script: |
198236
const owner = 'bitwarden';
199237
const featureFlags = "${{ inputs.FEATURE_FLAGS || '{}' }}";
200-
const featureFlagsMessage = featureFlags === '{}' ? 'all feature flags disabled.': `\n\n<details><summary><div>The following flags enabled:</div></summary>\`\`\`json\n${featureFlags}\`\`\``;
238+
const featureFlagsMessage = featureFlags === '{}' ?
239+
'<ins>all feature flags disabled</ins>.' :
240+
`**the following flags enabled**:<br/><details><summary>Show/Hide Flags</summary><pre><code>${featureFlags}</code></pre></details>`;
201241
const runURL = `https://github.com/${owner}/browser-interactions-testing/actions/runs/${context.runId}`;
202-
const message = `⚠️ **Files have been modified in this PR that impact the Autofill experience** ⚠️
242+
const message = `
243+
<!-- comment_tag: test-all-custom-flags -->
244+
#### ⚠️ Changes in this PR impact the Autofill experience of the browser client ⚠️
245+
246+
[BIT](https://github.com/${owner}/browser-interactions-testing) has tested the core experience with these changes and ${featureFlagsMessage}
247+
248+
> [!CAUTION]
249+
> Unfortunately, one or more of these tests failed. 😞
250+
>
251+
> Please resolve the failure before merging; reach out to \`@bitwarden/team-autofill-dev\` if you'd like help.
203252
204-
[BIT](https://github.com/${owner}/browser-interactions-testing) was run to verify no regressions have been introduced to the core Autofill experience. The tests ran with ${featureFlagsMessage}
253+
You can view the detailed results of the tests [here](${runURL}).
254+
`;
205255
206-
❌ Unfortunately, one or more of these BIT tests failed. 😞
256+
github.rest.issues.createComment({
257+
issue_number: context.payload.client_payload.origin_issue,
258+
owner: owner,
259+
repo: 'clients',
260+
body: message
261+
});
262+
263+
- name: Communicate BIT success on originating issue
264+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
265+
if: success() && steps.set-send-pr-feedback.outputs.send_pr_feedback == 'true'
266+
with:
267+
github-token: ${{ steps.app-token.outputs.token }}
268+
script: |
269+
const owner = 'bitwarden';
270+
const featureFlags = "${{ inputs.FEATURE_FLAGS || '{}' }}";
271+
const featureFlagsMessage = featureFlags === '{}' ?
272+
'<ins>all feature flags disabled</ins>.' :
273+
`**the following flags enabled**:<br/><details><summary>Show/Hide Flags</summary><pre><code>${featureFlags}</code></pre></details>`;
274+
const runURL = `https://github.com/${owner}/browser-interactions-testing/actions/runs/${context.runId}`;
275+
const message = `
276+
<!-- comment_tag: test-all-custom-flags -->
277+
#### Changes in this PR impact the Autofill experience of the browser client
207278
208-
Please resolve the failure before merging; reach out to \`@bitwarden/team-autofill-dev\` if you'd like help.
279+
[BIT](https://github.com/${owner}/browser-interactions-testing) has tested the core experience with these changes and ${featureFlagsMessage}
209280
210-
You can view the detailed results of the tests [here](${runURL}).`;
281+
✅ Fortunately, [these BIT tests have passed](${runURL})! 🎉
282+
`;
211283
212284
github.rest.issues.createComment({
213285
issue_number: context.payload.client_payload.origin_issue,

.github/workflows/test-all.yml

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,46 @@ jobs:
189189
./tests-out/videos
190190
./tests-out/screenshots
191191
192+
- name: Remove past BIT status comments on originating issue
193+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
194+
if: steps.set-send-pr-feedback.outputs.send_pr_feedback == 'true'
195+
with:
196+
github-token: ${{ steps.app-token.outputs.token }}
197+
script: |
198+
// Note: should match the first line of `message` in the communication steps
199+
const workflowCommentTag = '<!-- comment_tag: test-all -->';
200+
201+
const owner = 'bitwarden';
202+
203+
const issueComments = await github.rest.issues.listComments({
204+
issue_number: context.payload.client_payload.origin_issue,
205+
owner: owner,
206+
repo: 'clients',
207+
});
208+
209+
for (const comment of issueComments.data || []) {
210+
const shouldDeleteComment =
211+
// Do not delete comments that were not automated
212+
!!comment.performed_via_github_app &&
213+
214+
// Do not delete user comments
215+
comment.user.type === 'Bot' &&
216+
217+
// Do not delete edited comments
218+
comment.created_at === comment.updated_at &&
219+
220+
// Only delete comments from this workflow
221+
comment.body.trim().startsWith(workflowCommentTag);
222+
223+
if (shouldDeleteComment) {
224+
await github.rest.issues.deleteComment({
225+
comment_id: comment.id,
226+
owner: owner,
227+
repo: 'clients',
228+
});
229+
}
230+
}
231+
192232
- name: Communicate BIT failure on originating issue
193233
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
194234
if: failure() && steps.set-send-pr-feedback.outputs.send_pr_feedback == 'true'
@@ -198,15 +238,19 @@ jobs:
198238
const owner = 'bitwarden';
199239
const runURL = `https://github.com/${owner}/browser-interactions-testing/actions/runs/${context.runId}`;
200240
const configURL = new URL('${{ vars.BW_REMOTE_VAULT_CONFIG_MATCH }}');
201-
const message = `⚠️ **Files have been modified in this PR that impact the Autofill experience** ⚠️
202-
203-
[BIT](https://github.com/${owner}/browser-interactions-testing) was run to verify no regressions have been introduced to the core Autofill experience. The tests ran with the same feature flag configuration used by \`${configURL.hostname}\`
241+
const message = `
242+
<!-- comment_tag: test-all -->
243+
#### ⚠️ Changes in this PR impact the Autofill experience of the browser client ⚠️
204244
205-
❌ Unfortunately, one or more of these BIT tests failed. 😞
245+
[BIT](https://github.com/${owner}/browser-interactions-testing) has tested the core experience with these changes and **the feature flag configuration used by \`${configURL.hostname}\`**
206246
207-
Please resolve the failure before merging; reach out to \`@bitwarden/team-autofill-dev\` if you'd like help.
247+
> [!CAUTION]
248+
> Unfortunately, one or more of these tests failed. 😞
249+
>
250+
> Please resolve the failure before merging; reach out to \`@bitwarden/team-autofill-dev\` if you'd like help.
208251
209-
You can view the detailed results of the tests [here](${runURL}).`;
252+
You can view the detailed results of the tests [here](${runURL}).
253+
`;
210254
211255
github.rest.issues.createComment({
212256
issue_number: context.payload.client_payload.origin_issue,
@@ -222,11 +266,16 @@ jobs:
222266
github-token: ${{ steps.app-token.outputs.token }}
223267
script: |
224268
const owner = 'bitwarden';
225-
const message = `⚠️ **Files have been modified in this PR that impact the Autofill experience** ⚠️
269+
const runURL = `https://github.com/${owner}/browser-interactions-testing/actions/runs/${context.runId}`;
270+
const configURL = new URL('${{ vars.BW_REMOTE_VAULT_CONFIG_MATCH }}');
271+
const message = `
272+
<!-- comment_tag: test-all -->
273+
#### Changes in this PR impact the Autofill experience of the browser client
226274
227-
[BIT](https://github.com/${owner}/browser-interactions-testing) was run to verify no regressions have been introduced to the core Autofill experience.
275+
[BIT](https://github.com/${owner}/browser-interactions-testing) has tested the core experience with these changes and <ins>the feature flag configuration used by \`${configURL.hostname}\`</ins>.
228276
229-
✅ Fortunately, [these BIT tests have passed](https://github.com/${owner}/browser-interactions-testing/actions/runs/${context.runId})! 🎉`;
277+
✅ Fortunately, [these BIT tests have passed](${runURL})! 🎉
278+
`;
230279
231280
github.rest.issues.createComment({
232281
issue_number: context.payload.client_payload.origin_issue,

0 commit comments

Comments
 (0)