Skip to content

Commit a342722

Browse files
authored
Merge pull request #22 from capricorn86/21-add-support-for-fallback-github-username
feat: [#21] Adds support for a fallback username
2 parents 8a6031a + c21c274 commit a342722

3 files changed

+257
-39
lines changed

bin/happy-release-notes.cjs

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function getArguments() {
2222
from: null,
2323
to: null,
2424
versionHeader: false,
25-
author: null
25+
authorUsername: null
2626
};
2727

2828
for (const arg of process.argv) {
@@ -32,6 +32,8 @@ function getArguments() {
3232
args.to = arg.split('=')[1];
3333
} else if (arg.startsWith('--author=')) {
3434
args.author = arg.split('=')[1];
35+
} else if (arg.startsWith('--authorUsername=')) {
36+
args.authorUsername = arg.split('=')[1];
3537
} else if (arg.startsWith('--versionHeader')) {
3638
args.versionHeader = true;
3739
}
@@ -56,7 +58,8 @@ async function main() {
5658
fromVersion: args.from ? args.from : null,
5759
toVersion: args.to ? args.to : null,
5860
versionHeader: args.versionHeader,
59-
author: args.author
61+
author: args.author,
62+
authorUsername: args.authorUsername
6063
});
6164

6265
console.log(releaseNotes);

src/ConventionalCommitReleaseNotes.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ export default class ConventionalCommitReleaseNotes {
3939
* @param [options.toVersion] To version.
4040
* @param [options.versionHeader] "true" to show version header.
4141
* @param [options.author] "githubUsername" or "nameAndEmail".
42+
* @param [options.authorUsername] Use this username for author when "author" is not specified or if it was not possible to retrieve the Github username based on email.
4243
* @returns Release notes.
4344
*/
4445
public static async getReleaseNotes(options?: {
4546
fromVersion?: string;
4647
toVersion?: string;
4748
versionHeader?: boolean;
4849
author?: 'githubUsername' | 'nameAndEmail';
50+
authorUsername?: string;
4951
}): Promise<string> {
5052
const releases = await this.getReleases(options);
5153
let output = '';
@@ -61,18 +63,28 @@ export default class ConventionalCommitReleaseNotes {
6163
const message = change.message.endsWith('.')
6264
? change.message.slice(0, -1)
6365
: change.message;
64-
const author =
65-
options?.author === 'githubUsername' && change.author.githubUsername
66-
? change.author.githubUsername
67-
: options?.author === 'nameAndEmail'
68-
? `${change.author.name} (${change.author.email})`
69-
: null;
66+
let author = '';
67+
68+
switch (options?.author) {
69+
case 'githubUsername':
70+
author =
71+
change.author.githubUsername || options?.authorUsername
72+
? `@${change.author.githubUsername || options?.authorUsername}`
73+
: null;
74+
break;
75+
case 'nameAndEmail':
76+
author = `${change.author.name} (${change.author.email})`;
77+
break;
78+
default:
79+
author = options?.authorUsername ? `@${options?.authorUsername}` : null;
80+
break;
81+
}
7082

7183
let userAndTask = '';
7284
if (author && change.taskId) {
73-
userAndTask = ` - By **@${author}** in task ${change.taskId}`;
85+
userAndTask = ` - By **${author}** in task ${change.taskId}`;
7486
} else if (author) {
75-
userAndTask = ` - By **@${author}**`;
87+
userAndTask = ` - By **${author}**`;
7688
} else if (change.taskId) {
7789
userAndTask = ` - In task ${change.taskId}`;
7890
}
@@ -295,7 +307,8 @@ export default class ConventionalCommitReleaseNotes {
295307
const [message, userName, userEmail] = row.trim().split('|');
296308
if (message) {
297309
commits.push(<ICommit>{
298-
message,
310+
// Remove @ from message to avoid Github to link to a user.
311+
message: message.replace('@', ''),
299312
author: {
300313
name: userName,
301314
email: userEmail,

0 commit comments

Comments
 (0)