Skip to content

Commit 3127962

Browse files
authored
Fix authors script (microsoft#30440)
1 parent e552163 commit 3127962

File tree

1 file changed

+45
-47
lines changed

1 file changed

+45
-47
lines changed

scripts/authors.ts

+45-47
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ type Command = {
1515
description?: string;
1616
};
1717

18-
const mailMapPath = path.resolve("../.mailmap");
19-
const authorsPath = path.resolve("../AUTHORS.md");
18+
const mailMapPath = path.resolve(__dirname, "../.mailmap");
19+
const authorsPath = path.resolve(__dirname, "../AUTHORS.md");
2020

2121
function getKnownAuthors(): Author[] {
2222
const segmentRegExp = /\s?([^<]+)\s+<([^>]+)>/g;
@@ -113,56 +113,54 @@ namespace Commands {
113113
const cmd = "git shortlog -se " + specs.join(" ");
114114
console.log(cmd);
115115
const outputRegExp = /\d+\s+([^<]+)<([^>]+)>/;
116-
const tty = process.platform === 'win32' ? 'CON' : '/dev/tty';
117116
const authors: { name: string, email: string, knownAuthor?: Author }[] = [];
118-
child_process.exec(`${cmd} < ${tty}`, { cwd: path.resolve("../") }, function (error, stdout, stderr) {
119-
if (error) {
120-
console.log(stderr.toString());
121-
}
122-
else {
123-
const output = stdout.toString();
124-
const lines = output.split("\n");
125-
lines.forEach(line => {
126-
if (line) {
127-
let match: RegExpExecArray | null;
128-
if (match = outputRegExp.exec(line)) {
129-
authors.push({ name: match[1], email: match[2] });
130-
}
131-
else {
132-
throw new Error("Could not parse output: " + line);
133-
}
117+
const {output: [error, stdout, stderr]} = child_process.spawnSync(`git`, ["shortlog", "-se", ...specs], { cwd: path.resolve(__dirname, "../") });
118+
if (error) {
119+
console.log(stderr.toString());
120+
}
121+
else {
122+
const output = stdout.toString();
123+
const lines = output.split("\n");
124+
lines.forEach(line => {
125+
if (line) {
126+
let match: RegExpExecArray | null;
127+
if (match = outputRegExp.exec(line)) {
128+
authors.push({ name: match[1], email: match[2] });
129+
}
130+
else {
131+
throw new Error("Could not parse output: " + line);
134132
}
135-
});
136-
137-
const maps = getKnownAuthorMaps();
138-
139-
const lookupAuthor = function ({name, email}: { name: string, email: string }) {
140-
return maps.authorsByEmail[email.toLocaleLowerCase()] || maps.authorsByName[name];
141-
};
142-
143-
const knownAuthors = authors
144-
.map(lookupAuthor)
145-
.filter(a => !!a)
146-
.map(getAuthorName);
147-
const unknownAuthors = authors
148-
.filter(a => !lookupAuthor(a))
149-
.map(a => `${a.name} <${a.email}>`);
150-
151-
if (knownAuthors.length) {
152-
console.log("\r\n");
153-
console.log("Found known authors: ");
154-
console.log("=====================");
155-
deduplicate(knownAuthors).sort(sortAuthors).forEach(log);
156133
}
134+
});
135+
136+
const maps = getKnownAuthorMaps();
137+
138+
const lookupAuthor = function ({name, email}: { name: string, email: string }) {
139+
return maps.authorsByEmail[email.toLocaleLowerCase()] || maps.authorsByName[name];
140+
};
141+
142+
const knownAuthors = authors
143+
.map(lookupAuthor)
144+
.filter(a => !!a)
145+
.map(getAuthorName);
146+
const unknownAuthors = authors
147+
.filter(a => !lookupAuthor(a))
148+
.map(a => `${a.name} <${a.email}>`);
149+
150+
if (knownAuthors.length) {
151+
console.log("\r\n");
152+
console.log("Found known authors: ");
153+
console.log("=====================");
154+
deduplicate(knownAuthors).sort(sortAuthors).forEach(log);
155+
}
157156

158-
if (unknownAuthors.length) {
159-
console.log("\r\n");
160-
console.log("Found unknown authors: ");
161-
console.log("=====================");
162-
deduplicate(unknownAuthors).sort(sortAuthors).forEach(log);
163-
}
157+
if (unknownAuthors.length) {
158+
console.log("\r\n");
159+
console.log("Found unknown authors: ");
160+
console.log("=====================");
161+
deduplicate(unknownAuthors).sort(sortAuthors).forEach(log);
164162
}
165-
});
163+
}
166164
};
167165
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'";
168166
}

0 commit comments

Comments
 (0)