From 29c170f4f1af70f58eb6ad85697c4afeb1938f51 Mon Sep 17 00:00:00 2001 From: Bloop <13398309+vinylspiders@users.noreply.github.com> Date: Fri, 15 Aug 2025 18:56:59 -0400 Subject: [PATCH] Allows labeler action to add/remove labels from the PR title/body on sync (#92553) ## About The Pull Request Followup to https://github.com/tgstation/tgstation/pull/92504 Removes the conditional that was stopping the labeler from checking the PR body for labels on sync.
No more of this weirdness firefox_zppJmK5qz2
Any time someone updates a PR and it syncs, you can potentially lose some of the PR labels from the body (the changelog specifically) if they are not configured as `add_only` in the autoLabelConfig.js I had kept it in previously since it was how it was before, but thinking on it I do not think this is even necessary anymore now that the php webhook method is replaced with the action. Let's remove it! ## Why It's Good For The Game QoL for maintainers and contributors ## Changelog Nothing player-facing --- tools/pull_request_hooks/autoLabel.js | 42 +++++++++++++++++++++------ 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/tools/pull_request_hooks/autoLabel.js b/tools/pull_request_hooks/autoLabel.js index 809e81f49c0..40d99cde8c7 100644 --- a/tools/pull_request_hooks/autoLabel.js +++ b/tools/pull_request_hooks/autoLabel.js @@ -173,7 +173,7 @@ async function check_diff_files_for_labels(github, context) { * Main function to get the updated label set */ export async function get_updated_label_set({ github, context }) { - const { action, pull_request } = context.payload; + const { pull_request } = context.payload; const { body = "", diff_url, @@ -192,14 +192,38 @@ export async function get_updated_label_set({ github, context }) { labels_to_remove.forEach((label) => updated_labels.delete(label)); } - // Check body/title only when PR is opened, not on sync - if (action === "opened") { - if (title) - check_title_for_labels(title).forEach((label) => - updated_labels.add(label) - ); - if (body) - check_body_for_labels(body).forEach((label) => updated_labels.add(label)); + // Always check body/title (otherwise we can lose the changelog labels) + if (title) + check_title_for_labels(title).forEach((label) => + updated_labels.add(label) + ); + if (body) + check_body_for_labels(body).forEach((label) => updated_labels.add(label)); + + // Keep track of labels that were manually added by maintainers in the events. + // And make sure they -stay- added. + try { + await github.paginate( + github.rest.issues.listEventsForTimeline, + { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + per_page: 100, + }, + (response) => { + for (const eventData of response.data) { + if ( + eventData.event === "labeled" && + eventData.actor?.login !== "github-actions" + ) { + updated_labels.add(eventData.label.name); + } + } + } + ); + } catch (error) { + console.error("Error fetching paginated events:", error); } // Always remove Test Merge Candidate