Skip to content

build: exclude redundant cherry-picked commits when generating changelog #17050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2020
Merged
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
46 changes: 43 additions & 3 deletions scripts/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// tslint:disable:no-console
// tslint:disable:no-implicit-dependencies
import { JsonObject, logging } from '@angular-devkit/core';
import { execSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import * as semver from 'semver';
Expand All @@ -29,7 +30,16 @@ export interface ChangelogOptions {
stdout?: boolean;
}

export default function(args: ChangelogOptions, logger: logging.Logger) {
function exec(command: string, input?: string): string {
return execSync(command, {
encoding: 'utf8',
stdio: 'pipe',
input,
maxBuffer: 10 * 1024 * 1024,
}).trim();
}

export default async function(args: ChangelogOptions, logger: logging.Logger) {
const commits: JsonObject[] = [];
let toSha: string | null = null;

Expand All @@ -39,6 +49,35 @@ export default function(args: ChangelogOptions, logger: logging.Logger) {
''
).trim();

// Validate and scrub commit range options
const from = exec(`git rev-parse --verify "${args.from.replace(/"/g, '')}"`);
if (!from) {
logger.error(`"from" value [${args.from}] is invalid.`);

return;
}
const to = exec(`git rev-parse --verify "${args.to?.replace(/"/g, '') || 'HEAD'}"`);
if (!to) {
logger.error(`"to" value [${args.to}] is invalid.`);

return;
}

// Collect patch identifiers for cherry-pick exclusion
const cherryPicked = new Set<string>();
const patchIds = new Map<string, string>();
const hashes = exec(`git rev-list ${from}...${to}`).split(/\s+/);
for (const hash of hashes) {
const [patchId] = exec('git patch-id', exec('git show ' + hash)).split(/\s+/);
const existing = patchIds.get(patchId);
if (existing) {
cherryPicked.add(existing);
cherryPicked.add(hash);
} else {
patchIds.set(patchId, hash);
}
}

return new Promise(resolve => {
(gitRawCommits({
from: args.from,
Expand Down Expand Up @@ -78,8 +117,9 @@ export default function(args: ChangelogOptions, logger: logging.Logger) {
if (tags && tags.find(x => x == args.to)) {
toSha = chunk.hash as string;
}

commits.push(chunk);
if (!cherryPicked.has(chunk.hash as string)) {
commits.push(chunk);
}
cb();
} catch (err) {
cb(err);
Expand Down