From b8e88f5c91f147218f4d38ff6defe2197e6b17cd Mon Sep 17 00:00:00 2001 From: Jessica Janiuk Date: Wed, 25 Jun 2025 14:07:32 +0200 Subject: [PATCH] refactor(github-actions): Updated metadata labeler to remove merge label when PR is in draft This prevents items being added to the merge queue accidentally still in draft mode. --- .../pull-request-labeling/lib/main.ts | 21 ++++++++++++++++++- github-actions/pull-request-labeling/main.js | 15 +++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/github-actions/pull-request-labeling/lib/main.ts b/github-actions/pull-request-labeling/lib/main.ts index 5f495c47b..33f2a992b 100644 --- a/github-actions/pull-request-labeling/lib/main.ts +++ b/github-actions/pull-request-labeling/lib/main.ts @@ -2,7 +2,7 @@ import * as core from '@actions/core'; import {context} from '@actions/github'; import {Octokit, RestEndpointMethodTypes} from '@octokit/rest'; import {Commit, parseCommitMessage} from '../../../ng-dev/commit-message/parse.js'; -import {managedLabels, targetLabels} from '../../../ng-dev/pr/common/labels/index.js'; +import {actionLabels, managedLabels, targetLabels} from '../../../ng-dev/pr/common/labels/index.js'; import {ANGULAR_ROBOT, getAuthTokenFor, revokeActiveInstallationToken} from '../../utils.js'; import {ManagedRepositories} from '../../../ng-dev/pr/common/labels/base.js'; @@ -85,6 +85,7 @@ class PullRequestLabeling { if (this.pullRequestMetadata === undefined) { return; } + /** The base reference string, or target branch of the pull request. */ const baseRef = this.pullRequestMetadata.base.ref; @@ -100,6 +101,24 @@ class PullRequestLabeling { await this.addLabel(targetLabels.TARGET_FEATURE.name); } } + + if (this.pullRequestMetadata.draft && this.labels.has(actionLabels.ACTION_MERGE.name)) { + core.info(`This pull request is still in draft mode, removing "action: merge" label`); + await this.removeLabel(actionLabels.ACTION_MERGE.name); + } + } + + /** Remove the provided label to the pull request. */ + async removeLabel(label: string) { + const {number: issue_number, owner, repo} = context.issue; + try { + await this.git.issues.removeLabel({repo, owner, issue_number, name: label}); + core.info(`Removed ${label} label from PR #${issue_number}`); + this.labels.delete(label); + } catch (err) { + core.error(`Failed to remove ${label} label from PR #${issue_number}`); + core.debug(err as string); + } } /** Add the provided label to the pull request. */ diff --git a/github-actions/pull-request-labeling/main.js b/github-actions/pull-request-labeling/main.js index cb10f2af1..ce300fbce 100644 --- a/github-actions/pull-request-labeling/main.js +++ b/github-actions/pull-request-labeling/main.js @@ -43470,6 +43470,21 @@ var PullRequestLabeling = class { await this.addLabel(targetLabels.TARGET_FEATURE.name); } } + if (this.pullRequestMetadata.draft && this.labels.has(actionLabels.ACTION_MERGE.name)) { + core.info(`This pull request is still in draft mode, removing "action: merge" label`); + await this.removeLabel(actionLabels.ACTION_MERGE.name); + } + } + async removeLabel(label) { + const { number: issue_number, owner, repo } = import_github2.context.issue; + try { + await this.git.issues.removeLabel({ repo, owner, issue_number, name: label }); + core.info(`Removed ${label} label from PR #${issue_number}`); + this.labels.delete(label); + } catch (err) { + core.error(`Failed to remove ${label} label from PR #${issue_number}`); + core.debug(err); + } } async addLabel(label) { const { number: issue_number, owner, repo } = import_github2.context.issue;