Skip to content

Commit

Permalink
refactor!: optimize changelog references
Browse files Browse the repository at this point in the history
Signed-off-by: Ardalan Amini <[email protected]>
  • Loading branch information
ardalanamini committed Apr 29, 2023
1 parent 7db6dea commit 5c66757
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion action/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion action/index.js.map

Large diffs are not rendered by default.

19 changes: 17 additions & 2 deletions src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,25 @@ export async function generateChangelog(lastSha?: string): Promise<string> {
const reference: string[] = [];

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

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

if (commit.author?.login && shouldMentionAuthors) reference.push(`by @${ commit.author.login }`);
if (username && shouldMentionAuthors) {
const mention = `by @${ username }`;

reference.push(mention);

const lastReference = log.references[log.references.length - 1];

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (lastReference?.endsWith(mention)) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
log.references.push(log.references.pop()!.replace(mention, `& ${ reference.join(" ") }`));

continue;
}
}

if (reference.length > 0) log.references.push(reference.join(" "));
}
Expand Down

0 comments on commit 5c66757

Please sign in to comment.