Skip to content

Commit 32ca675

Browse files
committed
get username from PR
1 parent c677f16 commit 32ca675

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

scripts/release/__tests__/createReleasePR.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const buildTestCommit = (
1818
}> = {}
1919
): string => {
2020
const { type = 'fix', scope, message = 'fix the thing (#123)' } = options;
21-
const baseTestCommit = `b2501882|${gitAuthor.name}|${gitAuthor.email}`;
21+
const baseTestCommit = `b2501882|${gitAuthor.email}`;
2222
const typeAndScope = `${type}${scope ? `(${scope})` : ''}`;
2323

2424
return `${baseTestCommit}|${typeAndScope}: ${message}`;
@@ -29,10 +29,12 @@ describe('createReleasePR', () => {
2929
// Mock `getOctokit` to bypass the API call and credential requirements
3030
jest.spyOn(common, 'getOctokit').mockImplementation((): any => {
3131
return {
32-
search: {
33-
users: (): any => ({
32+
pulls: {
33+
get: (): any => ({
3434
data: {
35-
total_count: 0,
35+
user: {
36+
login: gitAuthor.name,
37+
},
3638
},
3739
}),
3840
},
@@ -61,10 +63,10 @@ describe('createReleasePR', () => {
6163
hash: 'b2501882',
6264
scope: 'javascript',
6365
message: 'fix(javascript): fix the thing',
64-
prNumber: '123',
66+
prNumber: 123,
6567
raw: testCommit,
6668
type: 'fix',
67-
author: `[${gitAuthor.name}](${gitAuthor.email})`,
69+
author: `[@${gitAuthor.name}](https://github.com/${gitAuthor.name}/)`,
6870
});
6971
});
7072

@@ -74,10 +76,10 @@ describe('createReleasePR', () => {
7476
hash: 'b2501882',
7577
scope: 'specs',
7678
message: 'fix(specs): fix the thing',
77-
prNumber: '123',
79+
prNumber: 123,
7880
raw: testCommit,
7981
type: 'fix',
80-
author: `[${gitAuthor.name}](${gitAuthor.email})`,
82+
author: `[@${gitAuthor.name}](https://github.com/${gitAuthor.name}/)`,
8183
});
8284
});
8385

scripts/release/createReleasePR.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,15 @@ export function getSkippedCommitsText({
113113
}
114114

115115
export async function parseCommit(commit: string): Promise<Commit> {
116-
const [hash, authorName, authorEmail, message] = commit.split('|');
116+
const [hash, authorEmail, message] = commit.split('|');
117117
const commitScope = message.slice(0, message.indexOf(':'));
118118
const typeAndScope = commitScope.match(/(.+)\((.+)\)/);
119-
const prNumber = message.match(/#(\d+)/);
119+
const prNumberMatch = message.match(/#(\d+)/);
120+
const prNumber = prNumberMatch ? parseInt(prNumberMatch[1], 10) : 0;
120121
let commitMessage = message;
121122

122123
if (prNumber) {
123-
commitMessage = message.replace(`(#${prNumber[1]})`, '').trim();
124+
commitMessage = message.replace(`(#${prNumber})`, '').trim();
124125
}
125126

126127
// We skip generation commits as they do not appear in changelogs
@@ -146,18 +147,18 @@ export async function parseCommit(commit: string): Promise<Commit> {
146147
}
147148

148149
// Retrieve the author GitHub username if publicly available
149-
if (!fetchedUsers[authorEmail]) {
150+
if (!fetchedUsers[authorEmail] && prNumber) {
150151
const octokit = getOctokit();
151-
const { data } = await octokit.search.users({
152-
q: authorEmail,
152+
const { data } = await octokit.pulls.get({
153+
owner: OWNER,
154+
repo: REPO,
155+
pull_number: prNumber,
153156
});
154157

155-
if (data.total_count === 0) {
156-
fetchedUsers[authorEmail] = `[${authorName}](${authorEmail})`;
157-
} else {
158+
if (data.user) {
158159
fetchedUsers[
159160
authorEmail
160-
] = `[@${data.items[0].login}](https://github.com/${data.items[0].login}/)`;
161+
] = `[@${data.user.login}](https://github.com/${data.user.login}/)`;
161162
}
162163
}
163164

@@ -166,7 +167,7 @@ export async function parseCommit(commit: string): Promise<Commit> {
166167
type: typeAndScope[1], // `fix` | `feat` | `chore` | ...
167168
scope, // `clients` | `specs` | `javascript` | `php` | `java` | ...
168169
message: commitMessage,
169-
prNumber: prNumber ? prNumber[1] : undefined,
170+
prNumber,
170171
raw: commit,
171172
author: fetchedUsers[authorEmail],
172173
};
@@ -298,7 +299,7 @@ async function getCommits(): Promise<{
298299
// Reading commits since last release
299300
const latestCommits = (
300301
await run(
301-
`git log --pretty=format:"%h|%an|%ae|%s" ${RELEASED_TAG}..${MAIN_BRANCH}`
302+
`git log --pretty=format:"%h|%ae|%s" ${RELEASED_TAG}..${MAIN_BRANCH}`
302303
)
303304
)
304305
.split('\n')

scripts/release/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type PassedCommit = {
2929
author: string;
3030
message: string;
3131
raw: string;
32-
prNumber: string | undefined;
32+
prNumber: number;
3333
};
3434

3535
export type Commit =

0 commit comments

Comments
 (0)