parent
51f47535e8
commit
8499bbdd17
@ -8,38 +8,27 @@
|
|||||||
|
|
||||||
|
|
||||||
// tslint:disable:no-console
|
// tslint:disable:no-console
|
||||||
module.exports = (gulp) => () => {
|
module.exports = (gulp) => async() => {
|
||||||
try {
|
try {
|
||||||
if (process.env['CIRCLECI'] === 'true' && !process.env['CIRCLE_PR_NUMBER']) {
|
if (process.env['CI'] === 'true' && process.env['CI_PULL_REQUEST'] === 'false') {
|
||||||
console.info(
|
console.info(
|
||||||
`Since commit messages are validated as part of the PR review process,\n` +
|
`Since valid commit messages are enforced by PR linting on CI,\n` +
|
||||||
`we do not need to commit messages on CI runs on upstream branches.\n\n` +
|
`we do not need to validate commit messages on CI runs on upstream branches.\n\n` +
|
||||||
`Skipping validate-commit-message check`
|
`Skipping validate-commit-message check`);
|
||||||
)
|
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
const validateCommitMessage = require('../validate-commit-message');
|
const validateCommitMessage = require('../validate-commit-message');
|
||||||
const shelljs = require('shelljs');
|
const shelljs = require('shelljs');
|
||||||
|
const getRefsAndShasForTarget = require('../utils/get-refs-and-shas-for-target');
|
||||||
|
|
||||||
shelljs.set('-e'); // Break on error.
|
shelljs.set('-e'); // Break on error.
|
||||||
|
|
||||||
let baseBranch = 'master';
|
const target = await getRefsAndShasForTarget(process.env['CIRCLE_PR_NUMBER']);
|
||||||
const currentVersion = require('semver').parse(require('../../package.json').version);
|
|
||||||
const baseHead =
|
|
||||||
shelljs
|
|
||||||
.exec(`git ls-remote --heads origin ${currentVersion.major}.${currentVersion.minor}.*`)
|
|
||||||
.trim()
|
|
||||||
.split('\n')
|
|
||||||
.pop();
|
|
||||||
if (baseHead) {
|
|
||||||
const match = /refs\/heads\/(.+)/.exec(baseHead);
|
|
||||||
baseBranch = match && match[1] || baseBranch;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to fetch origin explicitly because it might be stale.
|
// We need to fetch origin explicitly because it might be stale.
|
||||||
// I couldn't find a reliable way to do this without fetch.
|
// I couldn't find a reliable way to do this without fetch.
|
||||||
const result = shelljs.exec(
|
const result = shelljs.exec(
|
||||||
`git fetch origin ${baseBranch} && git log --reverse --format=%s origin/${baseBranch}..HEAD | grep -v "#34769"`);
|
`git log --reverse --format=%s ${target.commonAncestorSha}..${target.latestShaOfPrBranch}`);
|
||||||
|
|
||||||
if (result.code) {
|
if (result.code) {
|
||||||
throw new Error(`Failed to fetch commits: ${result.stderr}`);
|
throw new Error(`Failed to fetch commits: ${result.stderr}`);
|
||||||
@ -47,10 +36,10 @@ module.exports = (gulp) => () => {
|
|||||||
|
|
||||||
const commitsByLine = result.trim().split(/\n/).filter(line => line != '');
|
const commitsByLine = result.trim().split(/\n/).filter(line => line != '');
|
||||||
|
|
||||||
console.log(`Examining ${commitsByLine.length} commit(s) between ${baseBranch} and HEAD`);
|
console.log(`Examining ${commitsByLine.length} commit(s) between ${target.base.ref} and HEAD`);
|
||||||
|
|
||||||
if (commitsByLine.length == 0) {
|
if (commitsByLine.length == 0) {
|
||||||
console.log(`There are zero new commits between ${baseBranch} and HEAD`);
|
console.log(`There are zero new commits between ${target.base.ref} and HEAD`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const disallowSquashCommits = true;
|
const disallowSquashCommits = true;
|
||||||
|
@ -107,4 +107,3 @@ async function _main(repository, prNumber) {
|
|||||||
await exec(`git rebase origin/${target.base.ref}`);
|
await exec(`git rebase origin/${target.base.ref}`);
|
||||||
console.log('Rebase successful.');
|
console.log('Rebase successful.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// This script uses `console` to print messages to the user.
|
||||||
|
// tslint:disable:no-console
|
||||||
|
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
@ -68,18 +71,19 @@ module.exports = async function getRefsAndShasForTarget(prNumber) {
|
|||||||
const {stdout: commonAncestorSha} =
|
const {stdout: commonAncestorSha} =
|
||||||
await exec(`git merge-base origin/${result.base.ref} ${latestShaOfPrBranch}`);
|
await exec(`git merge-base origin/${result.base.ref} ${latestShaOfPrBranch}`);
|
||||||
|
|
||||||
return {
|
const output = {
|
||||||
base: {
|
base: {
|
||||||
ref: result.base.ref.trim(),
|
ref: result.base.ref,
|
||||||
sha: result.base.sha.trim(),
|
sha: result.base.sha,
|
||||||
},
|
},
|
||||||
head: {
|
head: {
|
||||||
ref: result.head.ref.trim(),
|
ref: result.head.ref,
|
||||||
sha: result.head.sha.trim()
|
sha: result.head.sha,
|
||||||
},
|
},
|
||||||
commonAncestorSha: commonAncestorSha.trim(),
|
commonAncestorSha: commonAncestorSha.trim(),
|
||||||
latestShaOfTargetBranch: latestShaOfTargetBranch.trim(),
|
latestShaOfTargetBranch: latestShaOfTargetBranch.trim(),
|
||||||
latestShaOfPrBranch: latestShaOfPrBranch.trim(),
|
latestShaOfPrBranch: latestShaOfPrBranch.trim(),
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
return output;
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user