Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions .github/local-actions/branch-manager/main.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion .github/local-actions/labels-sync/main.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion github-actions/branch-manager/main.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion github-actions/pull-request-labeling/main.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion github-actions/unified-status-check/main.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions ng-dev/pr/common/fetch-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ export const PR_SCHEMA = {
],
},
),
author: {
login: graphqlTypes.string,
},
};

export type PullRequestFromGithub = typeof PR_SCHEMA;
Expand Down
5 changes: 5 additions & 0 deletions ng-dev/pr/common/labels/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export class TargetLabel extends Label {
* https://docs.google.com/document/d/197kVillDwx-RZtSVOBtPb4BBIAw0E9RT3q3v6DZkykU#heading=h.lkuypj38h15d
*/
export const targetLabels = createTypedObject(TargetLabel)({
TARGET_AUTOMATION: {
description:
'This PR is targeted to only merge into the branch defined in Github [bot use only]',
name: 'target: automation',
},
TARGET_FEATURE: {
description: 'This PR is targeted for a feature branch (outside of main and semver branches)',
name: 'target: feature',
Expand Down
11 changes: 11 additions & 0 deletions ng-dev/pr/common/targeting/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ export async function getTargetLabelConfigsForActiveReleaseTrains(
return [githubTargetBranch];
},
},
{
label: targetLabels['TARGET_AUTOMATION'],
branches: (githubTargetBranch) => {
if (!isVersionBranch(githubTargetBranch)) {
throw new InvalidTargetBranchError(
'"target: automation" pull requests can only target a release branch',
);
}
return [githubTargetBranch];
},
},
];

// LTS branches can only be determined if the release configuration is defined, and must be added
Expand Down
16 changes: 16 additions & 0 deletions ng-dev/pr/common/validation/assert-allowed-target-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

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

/** List of automation robot accounts. */
const automationBots = ['angular-robot'];

/** Assert the commits provided are allowed to merge to the provided target label. */
// TODO: update typings to make sure portability is properly handled for windows build.
export const changesAllowForTargetLabelValidation = createPullRequestValidation(
Expand All @@ -28,6 +32,7 @@ class Validation extends PullRequestValidation {
config: PullRequestConfig,
releaseTrains: ActiveReleaseTrains,
labelsOnPullRequest: string[],
pullRequest: PullRequestFromGithub,
) {
if (labelsOnPullRequest.includes(mergeLabels['MERGE_FIX_COMMIT_MESSAGE'].name)) {
Log.debug(
Expand Down Expand Up @@ -68,6 +73,10 @@ class Validation extends PullRequestValidation {
if (hasDeprecations && !releaseTrains.isFeatureFreeze()) {
throw this._createHasDeprecationsError(targetLabel);
}
case targetLabels['TARGET_AUTOMATION']:
if (!automationBots.includes(pullRequest.author.login)) {
throw this._createUserUsingAutomationLabelError(targetLabel, pullRequest.author.login);
}
break;
default:
Log.warn(red('WARNING: Unable to confirm all commits in the pull request are'));
Expand Down Expand Up @@ -98,4 +107,11 @@ class Validation extends PullRequestValidation {
'or "target: major" label.';
return this._createError(message);
}

private _createUserUsingAutomationLabelError(label: TargetLabel, author: string) {
const message =
`Cannot merge into branch for "${label.name}" as the pull request is authored by "${author}" ` +
`but only known automation bot accounts (${automationBots.join(', ')}) can use this label.`;
return this._createError(message);
}
}
1 change: 1 addition & 0 deletions ng-dev/pr/common/validation/validate-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export async function assertValidPullRequest(
ngDevConfig.pullRequest,
activeReleaseTrains,
labels,
pullRequest,
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion ng-dev/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"noPropertyAccessFromIndexSignature": true,
"esModuleInterop": true,
"strict": true,
"noFallthroughCasesInSwitch": true,
"noFallthroughCasesInSwitch": false,
"moduleResolution": "bundler",
"module": "esnext",
"target": "es2020",
Expand Down
Loading