From 9def54d3644e10dd3dbb339c498f5ce4570e3223 Mon Sep 17 00:00:00 2001 From: Jessica Janiuk Date: Tue, 20 May 2025 13:17:45 +0200 Subject: [PATCH] refactor(github-actions/commit-message-based-labels): prevent auto removal of already applied labels If a commit message does not match our patterns and a label has already been applied manually, this action would remove the labels, which would add the PR back to the triage queue. Instead, this will never remove an already added label. --- .../commit-message-based-labels/lib/main.ts | 16 ---------------- .../commit-message-based-labels/main.js | 14 -------------- 2 files changed, 30 deletions(-) diff --git a/github-actions/commit-message-based-labels/lib/main.ts b/github-actions/commit-message-based-labels/lib/main.ts index c0acf38b4..0e6e2f36a 100644 --- a/github-actions/commit-message-based-labels/lib/main.ts +++ b/github-actions/commit-message-based-labels/lib/main.ts @@ -49,9 +49,6 @@ class CommitMessageBasedLabelManager { if (hasCommit && !hasLabel) { await this.addLabel(name); } - if (!hasCommit && hasLabel) { - await this.removeLabel(name); - } } for (const commit of this.commits) { @@ -78,19 +75,6 @@ class CommitMessageBasedLabelManager { } } - /** Remove the provided label from the pull request. */ - async removeLabel(name: string) { - const {number: issue_number, owner, repo} = context.issue; - try { - await this.git.issues.removeLabel({repo, owner, issue_number, name}); - core.info(`Added ${name} label to PR #${issue_number}`); - this.labels.delete(name); - } catch (err) { - core.error(`Failed to add ${name} label to PR #${issue_number}`); - core.debug(err as string); - } - } - /** Initialize the current labels and commits for the PR. */ async initialize() { const {number, owner, repo} = context.issue; diff --git a/github-actions/commit-message-based-labels/main.js b/github-actions/commit-message-based-labels/main.js index 19297284a..166a08ebc 100644 --- a/github-actions/commit-message-based-labels/main.js +++ b/github-actions/commit-message-based-labels/main.js @@ -43655,9 +43655,6 @@ var CommitMessageBasedLabelManager = class { if (hasCommit && !hasLabel) { await this.addLabel(name); } - if (!hasCommit && hasLabel) { - await this.removeLabel(name); - } } for (const commit of this.commits) { const label = "area: " + commit.scope; @@ -43677,17 +43674,6 @@ var CommitMessageBasedLabelManager = class { core.debug(err); } } - async removeLabel(name) { - const { number: issue_number, owner, repo } = import_github2.context.issue; - try { - await this.git.issues.removeLabel({ repo, owner, issue_number, name }); - core.info(`Added ${name} label to PR #${issue_number}`); - this.labels.delete(name); - } catch (err) { - core.error(`Failed to add ${name} label to PR #${issue_number}`); - core.debug(err); - } - } async initialize() { const { number, owner, repo } = import_github2.context.issue; await this.git.paginate(this.git.issues.listLabelsForRepo, { owner, repo }).then((labels) => labels.filter((l) => l.name.startsWith("area: ")).forEach((l) => this.repoAreaLabels.add(l.name)));