Skip to content

Commit dc034ad

Browse files
dannifyLFDanLu
andauthored
Include user links in change log script (#2984)
* include users in logs * formatting Co-authored-by: Daniel Lu <[email protected]>
1 parent 0e85731 commit dc034ad

File tree

1 file changed

+63
-41
lines changed

1 file changed

+63
-41
lines changed

scripts/changelog.js

Lines changed: 63 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,76 @@
11
const exec = require('child_process').execSync;
22
const spawn = require('child_process').spawnSync;
33
const fs = require('fs');
4+
const Octokit = require('@octokit/rest');
45

5-
let packages = JSON.parse(exec('yarn workspaces info --json').toString().split('\n').slice(1, -2).join('\n'));
6-
7-
let commits = new Map();
8-
9-
// Diff each package individually. Some packages might have been skipped during last release,
10-
// so we cannot simply look at the last tag on the whole repo.
11-
for (let name in packages) {
12-
let filePath = packages[name].location + '/package.json';
13-
let pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'));
14-
if (!pkg.private) {
15-
// Diff this package since the last published version, according to the package.json.
16-
// The release script creates a tag for each package version.
17-
let tag = `${pkg.name}@${pkg.version}`;
18-
19-
let args = [
20-
'log',
21-
`${tag}..HEAD`,
22-
'--pretty="%H%x00%aI%x00%an%x00%s"',
23-
packages[name].location,
24-
25-
// filter out non-code changes
26-
':!**/test/**',
27-
':!**/stories/**',
28-
':!**/chromatic/**'
29-
];
30-
31-
let res = spawn('git', args, {encoding: 'utf8'});
32-
if (res.stdout.length === 0) {
33-
continue;
34-
}
6+
const octokit = new Octokit();
7+
8+
run();
9+
10+
async function run() {
11+
let packages = JSON.parse(exec('yarn workspaces info --json').toString().split('\n').slice(1, -2).join('\n'));
12+
let commits = new Map();
13+
14+
// Diff each package individually. Some packages might have been skipped during last release,
15+
// so we cannot simply look at the last tag on the whole repo.
16+
for (let name in packages) {
17+
let filePath = packages[name].location + '/package.json';
18+
let pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'));
19+
if (!pkg.private) {
20+
// Diff this package since the last published version, according to the package.json.
21+
// The release script creates a tag for each package version.
22+
let tag = `${pkg.name}@${pkg.version}`;
3523

36-
for (let line of res.stdout.split('\n')) {
37-
if (line === '') {
24+
let args = [
25+
'log',
26+
`${tag}..HEAD`,
27+
'--pretty="%H%x00%aI%x00%an%x00%s"',
28+
packages[name].location,
29+
30+
// filter out non-code changes
31+
':!**/test/**',
32+
':!**/stories/**',
33+
':!**/chromatic/**'
34+
];
35+
36+
let res = spawn('git', args, {encoding: 'utf8'});
37+
if (res.stdout.length === 0) {
3838
continue;
3939
}
4040

41-
let info = line.replace(/^"|"$/g, '').split('\0');
42-
commits.set(info[0], info);
41+
for (let line of res.stdout.split('\n')) {
42+
if (line === '') {
43+
continue;
44+
}
45+
46+
let info = line.replace(/^"|"$/g, '').split('\0');
47+
commits.set(info[0], info);
48+
}
4349
}
4450
}
45-
}
4651

47-
let sortedCommits = [...commits.values()].sort((a, b) => a[1] < b[1] ? -1 : 1);
52+
let sortedCommits = [...commits.values()].sort((a, b) => a[1] < b[1] ? -1 : 1);
53+
54+
for (let commit of sortedCommits) {
55+
let message = '';
56+
let user = '';
57+
let pr;
58+
59+
//look for commits with pr #
60+
let m = commit[3].match(/(.*?) \(#(\d+)\)$/);
61+
62+
if (m) {
63+
let prId = m[2];
64+
message = m[1];
4865

49-
for (let commit of sortedCommits) {
50-
let m = commit[3].match(/(.*?) \(#(\d+)\)$/);
51-
let message = m?.[1] || commit[3];
52-
let pr = m ? `https://github.com/adobe/react-spectrum/pull/${m[2]}` : null;
53-
console.log(`* ${message} - ${commit[2]}` + (pr ? ` - [PR](${pr})` : ''));
66+
let res = await octokit.request('GET /repos/adobe/react-spectrum/pulls/{pull}', { pull: prId });
67+
user = `[@${res.data.user.login}](${res.data.user.html_url})`;
68+
pr = `https://github.com/adobe/react-spectrum/pull/${prId}`;
69+
70+
} else { // not a pr so just print what we know from the commit
71+
message = commit[3];
72+
user = commit[2];
73+
}
74+
console.log(`* ${message} - ${user}` + (pr ? ` - [PR](${pr})` : ''));
75+
}
5476
}

0 commit comments

Comments
 (0)