Skip to content

Commit fbdaba0

Browse files
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.
1 parent 92edde4 commit fbdaba0

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

github-actions/pull-request-labeling/lib/main.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as core from '@actions/core';
22
import {context} from '@actions/github';
33
import {Octokit, RestEndpointMethodTypes} from '@octokit/rest';
44
import {Commit, parseCommitMessage} from '../../../ng-dev/commit-message/parse.js';
5-
import {managedLabels, targetLabels} from '../../../ng-dev/pr/common/labels/index.js';
5+
import {actionLabels, managedLabels, targetLabels} from '../../../ng-dev/pr/common/labels/index.js';
66
import {ANGULAR_ROBOT, getAuthTokenFor, revokeActiveInstallationToken} from '../../utils.js';
77
import {ManagedRepositories} from '../../../ng-dev/pr/common/labels/base.js';
88

@@ -85,6 +85,7 @@ class PullRequestLabeling {
8585
if (this.pullRequestMetadata === undefined) {
8686
return;
8787
}
88+
8889
/** The base reference string, or target branch of the pull request. */
8990
const baseRef = this.pullRequestMetadata.base.ref;
9091

@@ -100,6 +101,24 @@ class PullRequestLabeling {
100101
await this.addLabel(targetLabels.TARGET_FEATURE.name);
101102
}
102103
}
104+
105+
if (this.pullRequestMetadata.draft && this.labels.has(actionLabels.ACTION_MERGE.name)) {
106+
core.info(`This pull request is still in draft mode, removing "action: merge" label`);
107+
await this.removeLabel(actionLabels.ACTION_MERGE.name);
108+
}
109+
}
110+
111+
/** Add the provided label to the pull request. */
112+
async removeLabel(label: string) {
113+
const {number: issue_number, owner, repo} = context.issue;
114+
try {
115+
await this.git.issues.removeLabel({repo, owner, issue_number, name: label});
116+
core.info(`Removed ${label} label from PR #${issue_number}`);
117+
this.labels.delete(label);
118+
} catch (err) {
119+
core.error(`Failed to remove ${label} label from PR #${issue_number}`);
120+
core.debug(err as string);
121+
}
103122
}
104123

105124
/** Add the provided label to the pull request. */

github-actions/pull-request-labeling/main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43470,6 +43470,21 @@ var PullRequestLabeling = class {
4347043470
await this.addLabel(targetLabels.TARGET_FEATURE.name);
4347143471
}
4347243472
}
43473+
if (this.pullRequestMetadata.draft && this.labels.has(actionLabels.ACTION_MERGE.name)) {
43474+
core.info(`This pull request is still in draft mode, removing "action: merge" label`);
43475+
await this.removeLabel(actionLabels.ACTION_MERGE.name);
43476+
}
43477+
}
43478+
async removeLabel(label) {
43479+
const { number: issue_number, owner, repo } = import_github2.context.issue;
43480+
try {
43481+
await this.git.issues.removeLabel({ repo, owner, issue_number, name: label });
43482+
core.info(`Removed ${label} label from PR #${issue_number}`);
43483+
this.labels.delete(label);
43484+
} catch (err) {
43485+
core.error(`Failed to remove ${label} label from PR #${issue_number}`);
43486+
core.debug(err);
43487+
}
4347343488
}
4347443489
async addLabel(label) {
4347543490
const { number: issue_number, owner, repo } = import_github2.context.issue;

0 commit comments

Comments
 (0)