Fix authors script (#30440)

This commit is contained in:
Wesley Wigham 2019-03-18 12:26:27 -07:00 committed by GitHub
parent e5521630fb
commit 3127962cd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,8 +15,8 @@ type Command = {
description?: string;
};
const mailMapPath = path.resolve("../.mailmap");
const authorsPath = path.resolve("../AUTHORS.md");
const mailMapPath = path.resolve(__dirname, "../.mailmap");
const authorsPath = path.resolve(__dirname, "../AUTHORS.md");
function getKnownAuthors(): Author[] {
const segmentRegExp = /\s?([^<]+)\s+<([^>]+)>/g;
@ -113,56 +113,54 @@ namespace Commands {
const cmd = "git shortlog -se " + specs.join(" ");
console.log(cmd);
const outputRegExp = /\d+\s+([^<]+)<([^>]+)>/;
const tty = process.platform === 'win32' ? 'CON' : '/dev/tty';
const authors: { name: string, email: string, knownAuthor?: Author }[] = [];
child_process.exec(`${cmd} < ${tty}`, { cwd: path.resolve("../") }, function (error, stdout, stderr) {
if (error) {
console.log(stderr.toString());
}
else {
const output = stdout.toString();
const lines = output.split("\n");
lines.forEach(line => {
if (line) {
let match: RegExpExecArray | null;
if (match = outputRegExp.exec(line)) {
authors.push({ name: match[1], email: match[2] });
}
else {
throw new Error("Could not parse output: " + line);
}
const {output: [error, stdout, stderr]} = child_process.spawnSync(`git`, ["shortlog", "-se", ...specs], { cwd: path.resolve(__dirname, "../") });
if (error) {
console.log(stderr.toString());
}
else {
const output = stdout.toString();
const lines = output.split("\n");
lines.forEach(line => {
if (line) {
let match: RegExpExecArray | null;
if (match = outputRegExp.exec(line)) {
authors.push({ name: match[1], email: match[2] });
}
else {
throw new Error("Could not parse output: " + line);
}
});
const maps = getKnownAuthorMaps();
const lookupAuthor = function ({name, email}: { name: string, email: string }) {
return maps.authorsByEmail[email.toLocaleLowerCase()] || maps.authorsByName[name];
};
const knownAuthors = authors
.map(lookupAuthor)
.filter(a => !!a)
.map(getAuthorName);
const unknownAuthors = authors
.filter(a => !lookupAuthor(a))
.map(a => `${a.name} <${a.email}>`);
if (knownAuthors.length) {
console.log("\r\n");
console.log("Found known authors: ");
console.log("=====================");
deduplicate(knownAuthors).sort(sortAuthors).forEach(log);
}
});
if (unknownAuthors.length) {
console.log("\r\n");
console.log("Found unknown authors: ");
console.log("=====================");
deduplicate(unknownAuthors).sort(sortAuthors).forEach(log);
}
const maps = getKnownAuthorMaps();
const lookupAuthor = function ({name, email}: { name: string, email: string }) {
return maps.authorsByEmail[email.toLocaleLowerCase()] || maps.authorsByName[name];
};
const knownAuthors = authors
.map(lookupAuthor)
.filter(a => !!a)
.map(getAuthorName);
const unknownAuthors = authors
.filter(a => !lookupAuthor(a))
.map(a => `${a.name} <${a.email}>`);
if (knownAuthors.length) {
console.log("\r\n");
console.log("Found known authors: ");
console.log("=====================");
deduplicate(knownAuthors).sort(sortAuthors).forEach(log);
}
});
if (unknownAuthors.length) {
console.log("\r\n");
console.log("Found unknown authors: ");
console.log("=====================");
deduplicate(unknownAuthors).sort(sortAuthors).forEach(log);
}
}
};
listAuthors.description = "List known and unknown authors for a given spec, e.g. 'node authors.js listAuthors origin/release-2.6..origin/release-2.7'";
}