Skip to content

Commit 0f0f951

Browse files
josephperrottalan-agius4
authored andcommitted
feat(ng-dev): create a new label target: automation to be used by bots (#3054)
Create a new label for bots to use for targetting only the branch selected in Github. Additionally, set up support for the merge and github actions tooling to support this new label' is not a valid branch name. PR Close #3054
1 parent f67eae0 commit 0f0f951

File tree

11 files changed

+86
-9
lines changed

11 files changed

+86
-9
lines changed

.github/local-actions/branch-manager/main.js

Lines changed: 29 additions & 4 deletions
Large diffs are not rendered by default.

.github/local-actions/labels-sync/main.js

Lines changed: 5 additions & 1 deletion
Large diffs are not rendered by default.

github-actions/branch-manager/main.js

Lines changed: 5 additions & 1 deletion
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 1 deletion
Large diffs are not rendered by default.

github-actions/unified-status-check/main.js

Lines changed: 5 additions & 1 deletion
Large diffs are not rendered by default.

ng-dev/pr/common/fetch-pull-request.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ export const PR_SCHEMA = {
130130
],
131131
},
132132
),
133+
author: {
134+
login: graphqlTypes.string,
135+
},
133136
};
134137

135138
export type PullRequestFromGithub = typeof PR_SCHEMA;

ng-dev/pr/common/labels/target.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export class TargetLabel extends Label {
1313
* https://docs.google.com/document/d/197kVillDwx-RZtSVOBtPb4BBIAw0E9RT3q3v6DZkykU#heading=h.lkuypj38h15d
1414
*/
1515
export const targetLabels = createTypedObject(TargetLabel)({
16+
TARGET_AUTOMATION: {
17+
description:
18+
'This PR is targeted to only merge into the branch defined in Github [bot use only]',
19+
name: 'target: automation',
20+
},
1621
TARGET_FEATURE: {
1722
description: 'This PR is targeted for a feature branch (outside of main and semver branches)',
1823
name: 'target: feature',

ng-dev/pr/common/targeting/labels.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ export async function getTargetLabelConfigsForActiveReleaseTrains(
153153
return [githubTargetBranch];
154154
},
155155
},
156+
{
157+
label: targetLabels['TARGET_AUTOMATION'],
158+
branches: (githubTargetBranch) => {
159+
if (!isVersionBranch(githubTargetBranch)) {
160+
throw new InvalidTargetBranchError(
161+
'"target: automation" pull requests can only target a release branch',
162+
);
163+
}
164+
return [githubTargetBranch];
165+
},
166+
},
156167
];
157168

158169
// LTS branches can only be determined if the release configuration is defined, and must be added

ng-dev/pr/common/validation/assert-allowed-target-label.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {PullRequestFromGithub} from '../fetch-pull-request.js';
910
import {Commit} from '../../../commit-message/parse.js';
1011
import {ActiveReleaseTrains} from '../../../release/versioning/active-release-trains.js';
1112
import {Log, red} from '../../../utils/logging.js';
@@ -14,6 +15,9 @@ import {mergeLabels} from '../labels/index.js';
1415
import {TargetLabel, targetLabels} from '../labels/target.js';
1516
import {createPullRequestValidation, PullRequestValidation} from './validation-config.js';
1617

18+
/** List of automation robot accounts. */
19+
const automationBots = ['angular-robot'];
20+
1721
/** Assert the commits provided are allowed to merge to the provided target label. */
1822
// TODO: update typings to make sure portability is properly handled for windows build.
1923
export const changesAllowForTargetLabelValidation = createPullRequestValidation(
@@ -28,6 +32,7 @@ class Validation extends PullRequestValidation {
2832
config: PullRequestConfig,
2933
releaseTrains: ActiveReleaseTrains,
3034
labelsOnPullRequest: string[],
35+
pullRequest: PullRequestFromGithub,
3136
) {
3237
if (labelsOnPullRequest.includes(mergeLabels['MERGE_FIX_COMMIT_MESSAGE'].name)) {
3338
Log.debug(
@@ -68,6 +73,10 @@ class Validation extends PullRequestValidation {
6873
if (hasDeprecations && !releaseTrains.isFeatureFreeze()) {
6974
throw this._createHasDeprecationsError(targetLabel);
7075
}
76+
case targetLabels['TARGET_AUTOMATION']:
77+
if (!automationBots.includes(pullRequest.author.login)) {
78+
throw this._createUserUsingAutomationLabelError(targetLabel, pullRequest.author.login);
79+
}
7180
break;
7281
default:
7382
Log.warn(red('WARNING: Unable to confirm all commits in the pull request are'));
@@ -98,4 +107,11 @@ class Validation extends PullRequestValidation {
98107
'or "target: major" label.';
99108
return this._createError(message);
100109
}
110+
111+
private _createUserUsingAutomationLabelError(label: TargetLabel, author: string) {
112+
const message =
113+
`Cannot merge into branch for "${label.name}" as the pull request is authored by "${author}" ` +
114+
`but only known automation bot accounts (${automationBots.join(', ')}) can use this label.`;
115+
return this._createError(message);
116+
}
101117
}

ng-dev/pr/common/validation/validate-pull-request.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export async function assertValidPullRequest(
7575
ngDevConfig.pullRequest,
7676
activeReleaseTrains,
7777
labels,
78+
pullRequest,
7879
),
7980
);
8081
}

0 commit comments

Comments
 (0)