From e7c017cfe303aa46ce048c12c770d1ab950c3477 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Fri, 15 May 2020 17:21:47 +0200 Subject: [PATCH] build: configure dev-infra merge script (#37138) Sets up the dev-infa merge script in the framework ng-dev configuration file. This allow us to use the script in the future. PR Close #37138 --- .ng-dev-config.ts | 63 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/.ng-dev-config.ts b/.ng-dev-config.ts index 0ee02484a2..d85be46331 100644 --- a/.ng-dev-config.ts +++ b/.ng-dev-config.ts @@ -1,3 +1,7 @@ +import {exec} from 'shelljs'; + +import {MergeConfig} from './dev-infra/pr/merge/config'; + // The configuration for `ng-dev commit-message` commands. const commitMessage = { 'maxLength': 120, @@ -72,15 +76,72 @@ const format = { 'buildifier': true }; -// Github metadata information for `ng-dev` commands. +/** Github metadata information for `ng-dev` commands. */ const github = { owner: 'angular', name: 'angular', }; +/** + * Gets the name of the current patch branch. The patch branch is determined by + * looking for upstream branches that follow the format of `{major}.{minor}.x`. + */ +const getPatchBranchName = (): string => { + const branches = + exec( + `git ls-remote --heads https://github.com/${github.owner}/${github.name}.git`, + {silent: true}) + .trim() + .split('\n'); + + for (let i = branches.length - 1; i >= 0; i--) { + const branchName = branches[i]; + const matches = branchName.match(/refs\/heads\/([0-9]+\.[0-9]+\.x)/); + if (matches !== null) { + return matches[1]; + } + } + + throw Error('Could not determine patch branch name.'); +}; + +// Configuration for the `ng-dev pr merge` command. The command can be used +// for merging upstream pull requests into branches based on a PR target label. +const merge = () => { + const patchBranch = getPatchBranchName(); + const config: MergeConfig = { + githubApiMerge: false, + claSignedLabel: 'cla: yes', + mergeReadyLabel: /^PR action: merge(-assistance)?/, + commitMessageFixupLabel: 'commit message fixup', + labels: [ + { + pattern: 'PR target: master-only', + branches: ['master'], + }, + { + pattern: 'PR target: patch-only', + branches: [patchBranch], + }, + { + pattern: 'PR target: master & patch', + branches: ['master', patchBranch], + }, + ], + requiredBaseCommits: { + // PRs that target either `master` or the patch branch, need to be rebased + // on top of the latest commit message validation fix. + 'master': '4341743b4a6d7e23c6f944aa9e34166b701369a1', + [patchBranch]: '2a53f471592f424538802907aca1f60f1177a86d' + }, + }; + return config; +}; + // Export function to build ng-dev configuration object. module.exports = { commitMessage, format, github, + merge, };