Skip to content

Commit 8951c5f

Browse files
authored
[DevTools][BE] Read username using gh in release script (#25270)
* [DevTools][BE] Read username using gh in release script * better regex & fix lint
1 parent e7fc04b commit 8951c5f

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

scripts/devtools/prepare-release.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,46 @@ async function getCommitLog(sha) {
9999
let shortLog = '';
100100
let formattedLog = '';
101101

102+
const hasGh = await hasGithubCLI();
102103
const rawLog = await execRead(`
103104
git log --topo-order --pretty=format:'%s' ${sha}...HEAD -- packages/react-devtools*
104105
`);
105-
rawLog.split('\n').forEach(line => {
106-
line = line.replace('[DevTools] ', '');
107-
106+
const lines = rawLog.split('\n');
107+
for (let i = 0; i < lines.length; i++) {
108+
const line = lines[i].replace(/^\[devtools\] */i, '');
108109
const match = line.match(/(.+) \(#([0-9]+)\)/);
109110
if (match !== null) {
110111
const title = match[1];
111112
const pr = match[2];
112-
113-
formattedLog += `\n* ${title} ([USERNAME](https://github.com/USERNAME) in [#${pr}](${PULL_REQUEST_BASE_URL}${pr}))`;
113+
let username;
114+
if (hasGh) {
115+
const response = await execRead(
116+
`gh api /repos/facebook/react/pulls/${pr}`
117+
);
118+
const {user} = JSON.parse(response);
119+
username = `[${user.login}](${user.html_url})`;
120+
} else {
121+
username = '[USERNAME](https://github.com/USERNAME)';
122+
}
123+
formattedLog += `\n* ${title} (${username} in [#${pr}](${PULL_REQUEST_BASE_URL}${pr}))`;
114124
shortLog += `\n* ${title}`;
115125
} else {
116126
formattedLog += `\n* ${line}`;
117127
shortLog += `\n* ${line}`;
118128
}
119-
});
129+
}
120130

121131
return [shortLog, formattedLog];
122132
}
123133

134+
async function hasGithubCLI() {
135+
try {
136+
await exec('which gh');
137+
return true;
138+
} catch (_) {}
139+
return false;
140+
}
141+
124142
async function getPreviousCommitSha() {
125143
const choices = [];
126144

0 commit comments

Comments
 (0)