From 74b4cf6206b4bfccfba75cff3371411bb7f8a956 Mon Sep 17 00:00:00 2001 From: cranberry-platypus Date: Mon, 16 Feb 2026 19:04:27 -0600 Subject: [PATCH 1/6] Also run label workflow on `syncronize` events --- .github/workflows/label.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 5c4c7024c75d..7ebb9bd559f0 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -2,7 +2,7 @@ name: 🛠️ Add/Remove Labels on: pull_request_target: - types: [ opened, closed ] + types: [ opened, synchronize, closed ] jobs: merge_job: From 433cd9519d5c3d3b52c73cfb25a041f4fe7f86db Mon Sep 17 00:00:00 2001 From: cranberry-platypus Date: Sat, 11 Apr 2026 22:42:09 -0500 Subject: [PATCH 2/6] Handle case when multiple changes are made --- .github/workflows/label.yml | 49 ++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 7ebb9bd559f0..688470eecca6 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -101,6 +101,14 @@ jobs: ]; let stringsLabel = "Strings"; + + async function getPullRequest() { + return await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + }); + } async function addLabel(labels) { await github.rest.issues.addLabels({ @@ -134,6 +142,28 @@ jobs: }) } + async function deleteComments() { + // Try to find comment to delete + for await (const comment of github.paginate.iterator( + octokit.rest.issues.listForRepo, + { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }, + )) { + if (comment.user.login === "github-actions[bot]" && comment.body.includes("This PR contains https://github.com/ankidroid/Anki-Android/labels/Strings changes")) { + await github.rest.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: comment.id, + }); + } + } + +octokit.paginate.iterator() accepts the same options as octokit.paginate(). + } + const changedFiles = await github.rest.pulls.listFiles({ owner: context.repo.owner, repo: context.repo.repo, @@ -143,6 +173,7 @@ jobs: // loop through list of files in current pr, then check if filename contains in i18n file name, // set boolean to true and use the boolean in outer loop to add label let fileChanged = false; + const pullRequestData = await getPullRequest(); for (let files of changedFiles.data) { for (let i18n of I18N_FILES) { if (files.filename.includes(i18n)) { @@ -152,26 +183,20 @@ jobs: } if (fileChanged) { - addLabel([stringsLabel]); - addComments(); + if (!pullRequestData.data.labels.find(label => label.name === stringsLabel)) { + addLabel([stringsLabel]); + addComments(); + } break; } } - async function getPullRequest() { - return await github.rest.pulls.get({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.issue.number, - }); - } - // if no file changed, remove label - const pullRequestData = await getPullRequest(); if (!fileChanged) { if (pullRequestData.data.labels.find(label => label.name === stringsLabel)) { console.log(`Removing #${stringsLabel} label from PR #${context.issue.number}`); removeLabel([stringsLabel]); + deleteComments(); } } @@ -223,4 +248,4 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, labels: ['Needs Review'] - }) \ No newline at end of file + }) From 18d47d07aeb429020eb46b6ebf0de1358bb10a04 Mon Sep 17 00:00:00 2001 From: cranberry-platypus Date: Sat, 11 Apr 2026 22:44:26 -0500 Subject: [PATCH 3/6] Remove note for myself to fix yaml syntax --- .github/workflows/label.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 688470eecca6..c7a0fd6d664d 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -160,8 +160,6 @@ jobs: }); } } - -octokit.paginate.iterator() accepts the same options as octokit.paginate(). } const changedFiles = await github.rest.pulls.listFiles({ From 206eb6c0f2c671af6912967d7f6e7ea198129e7c Mon Sep 17 00:00:00 2001 From: cranberry-platypus Date: Sat, 11 Apr 2026 22:55:27 -0500 Subject: [PATCH 4/6] Use correct API and handle case where user is null --- .github/workflows/label.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index c7a0fd6d664d..d3466ace704f 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -145,14 +145,14 @@ jobs: async function deleteComments() { // Try to find comment to delete for await (const comment of github.paginate.iterator( - octokit.rest.issues.listForRepo, + octokit.rest.issues.listComments, { owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, }, )) { - if (comment.user.login === "github-actions[bot]" && comment.body.includes("This PR contains https://github.com/ankidroid/Anki-Android/labels/Strings changes")) { + if (comment.user && comment.user.login === "github-actions[bot]" && comment.body.includes("This PR contains https://github.com/ankidroid/Anki-Android/labels/Strings changes")) { await github.rest.issues.deleteComment({ owner: context.repo.owner, repo: context.repo.repo, From 774440cd6f9d1ad55fb56350c083999ec65874f3 Mon Sep 17 00:00:00 2001 From: cranberry-platypus Date: Sat, 11 Apr 2026 23:04:48 -0500 Subject: [PATCH 5/6] Add debug check --- .github/workflows/label.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index d3466ace704f..ff80dfbde595 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -152,6 +152,7 @@ jobs: issue_number: context.issue.number, }, )) { + console.log(`Comment by: ${comment.user ? comment.user.login : "?"}: ${comment.body}`); if (comment.user && comment.user.login === "github-actions[bot]" && comment.body.includes("This PR contains https://github.com/ankidroid/Anki-Android/labels/Strings changes")) { await github.rest.issues.deleteComment({ owner: context.repo.owner, From d1880c209b10a4f951470a2b446275b530d1678f Mon Sep 17 00:00:00 2001 From: cranberry-platypus Date: Sat, 11 Apr 2026 23:15:06 -0500 Subject: [PATCH 6/6] Finalize label.yml - Add step to delete comments if no strings changes exist - Only add comment if strings label wasn't already added to PR --- .github/workflows/label.yml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index ff80dfbde595..f605e012b7eb 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -144,7 +144,7 @@ jobs: async function deleteComments() { // Try to find comment to delete - for await (const comment of github.paginate.iterator( + for await (const page of github.paginate.iterator( octokit.rest.issues.listComments, { owner: context.repo.owner, @@ -152,13 +152,15 @@ jobs: issue_number: context.issue.number, }, )) { - console.log(`Comment by: ${comment.user ? comment.user.login : "?"}: ${comment.body}`); - if (comment.user && comment.user.login === "github-actions[bot]" && comment.body.includes("This PR contains https://github.com/ankidroid/Anki-Android/labels/Strings changes")) { - await github.rest.issues.deleteComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: comment.id, - }); + for(const comment of page.data) { + console.log(`Comment: ${JSON.stringify(comment)}`); + if (comment.user && comment.user.login === "github-actions[bot]" && comment.body.includes("This PR contains https://github.com/ankidroid/Anki-Android/labels/Strings changes")) { + await github.rest.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: comment.id, + }); + } } } } @@ -195,8 +197,8 @@ jobs: if (pullRequestData.data.labels.find(label => label.name === stringsLabel)) { console.log(`Removing #${stringsLabel} label from PR #${context.issue.number}`); removeLabel([stringsLabel]); - deleteComments(); } + deleteComments(); } add_new_contributor_label: