Skip to content

Commit 5c66757

Browse files
committed
refactor!: optimize changelog references
Signed-off-by: Ardalan Amini <[email protected]>
1 parent 7db6dea commit 5c66757

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

action/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/changelog.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,25 @@ export async function generateChangelog(lastSha?: string): Promise<string> {
150150
const reference: string[] = [];
151151

152152
if (pr && shouldIncludePRLinks) reference.push(shouldUseGithubAutolink ? `#${ pr }` : `[#${ pr }](${ url }/issues/${ pr })`);
153+
else if (shouldIncludeCommitLinks) reference.push(shouldUseGithubAutolink ? commit.sha : `\`[${ commit.sha }](${ url }/commit/${ commit.sha })\``);
153154

154-
if ((!pr || !shouldIncludePRLinks) && shouldIncludeCommitLinks) reference.push(shouldUseGithubAutolink ? commit.sha : `\`[${ commit.sha }](${ url }/commit/${ commit.sha })\``);
155+
const username = commit.author?.login;
155156

156-
if (commit.author?.login && shouldMentionAuthors) reference.push(`by @${ commit.author.login }`);
157+
if (username && shouldMentionAuthors) {
158+
const mention = `by @${ username }`;
159+
160+
reference.push(mention);
161+
162+
const lastReference = log.references[log.references.length - 1];
163+
164+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
165+
if (lastReference?.endsWith(mention)) {
166+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
167+
log.references.push(log.references.pop()!.replace(mention, `& ${ reference.join(" ") }`));
168+
169+
continue;
170+
}
171+
}
157172

158173
if (reference.length > 0) log.references.push(reference.join(" "));
159174
}

0 commit comments

Comments
 (0)