Skip to content

Commit d7abc04

Browse files
committed
add cleanup trigger
1 parent 88ccbea commit d7abc04

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

.github/workflows/codegen.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ jobs:
4343

4444
- name: Clean previously generated branch
4545
run: yarn workspace scripts cleanGeneratedBranch ${{ github.head_ref }}
46+
47+
- name: Add cleanup comment
48+
run: yarn workspace scripts upsertGenerationComment cleanup
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.TOKEN_GENERATE_BOT }}
51+
PR_NUMBER: ${{ github.event.number }}

scripts/ci/codegen/__tests__/codegen.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ describe('codegen', () => {
5858
expect(await getCommentBody('noGen')).toMatchInlineSnapshot(`
5959
"✗ No code generated.
6060
61-
_If you believe this is an issue on our side, please [open an issue](https://github.com/algolia/api-clients-automation/issues/new?template=Bug_report.md)_"
61+
_If you believe this is an issue on our side, please [open an issue](https://github.com/algolia/api-clients-automation/issues/new?template=Bug_report.md)._"
62+
`);
63+
});
64+
65+
it('returns the right comment for a `cleanup` trigger', async () => {
66+
expect(await getCommentBody('cleanup')).toMatchInlineSnapshot(`
67+
"✗ The generated branch has been deleted.
68+
69+
If the PR has been merged, you can check the generated code on the [\`generated/main\` branch](https://github.com/algolia/api-clients-automation/tree/generated/main)."
6270
`);
6371
});
6472

scripts/ci/codegen/text.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ export default {
99
},
1010
noGen: {
1111
header: '✗ No code generated.',
12-
body: `_If you believe this is an issue on our side, please [open an issue](${REPO_URL}/issues/new?template=Bug_report.md)_`,
12+
body: `_If you believe this is an issue on our side, please [open an issue](${REPO_URL}/issues/new?template=Bug_report.md)._`,
13+
},
14+
cleanup: {
15+
header: '✗ The generated branch has been deleted.',
16+
body: `If the PR has been merged, you can check the generated code on the [\`generated/main\` branch](${REPO_URL}/tree/generated/main).`,
1317
},
1418
codegen: {
1519
header: '✔️ Code generated!',

scripts/ci/codegen/upsertGenerationComment.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ const octokit = new Octokit({
1414
});
1515

1616
const args = process.argv.slice(2);
17-
const allowedTriggers = ['notification', 'codegen', 'noGen'];
17+
const allowedTriggers = ['notification', 'codegen', 'noGen', 'cleanup'];
1818

1919
type Trigger = keyof typeof commentText;
2020

2121
export async function getCommentBody(trigger: Trigger): Promise<string> {
22-
if (trigger === 'notification' || trigger === 'noGen') {
22+
if (
23+
trigger === 'notification' ||
24+
trigger === 'noGen' ||
25+
trigger === 'cleanup'
26+
) {
2327
return `${commentText[trigger].header}
2428
2529
${commentText[trigger].body}`;

0 commit comments

Comments
 (0)