Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [#21] Adds support for a fallback username #22

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions bin/happy-release-notes.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function getArguments() {
from: null,
to: null,
versionHeader: false,
author: null
authorUsername: null
};

for (const arg of process.argv) {
Expand All @@ -32,6 +32,8 @@ function getArguments() {
args.to = arg.split('=')[1];
} else if (arg.startsWith('--author=')) {
args.author = arg.split('=')[1];
} else if (arg.startsWith('--authorUsername=')) {
args.authorUsername = arg.split('=')[1];
} else if (arg.startsWith('--versionHeader')) {
args.versionHeader = true;
}
Expand All @@ -56,7 +58,8 @@ async function main() {
fromVersion: args.from ? args.from : null,
toVersion: args.to ? args.to : null,
versionHeader: args.versionHeader,
author: args.author
author: args.author,
authorUsername: args.authorUsername
});

console.log(releaseNotes);
Expand Down
31 changes: 22 additions & 9 deletions src/ConventionalCommitReleaseNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ export default class ConventionalCommitReleaseNotes {
* @param [options.toVersion] To version.
* @param [options.versionHeader] "true" to show version header.
* @param [options.author] "githubUsername" or "nameAndEmail".
* @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.
* @returns Release notes.
*/
public static async getReleaseNotes(options?: {
fromVersion?: string;
toVersion?: string;
versionHeader?: boolean;
author?: 'githubUsername' | 'nameAndEmail';
authorUsername?: string;
}): Promise<string> {
const releases = await this.getReleases(options);
let output = '';
Expand All @@ -61,18 +63,28 @@ export default class ConventionalCommitReleaseNotes {
const message = change.message.endsWith('.')
? change.message.slice(0, -1)
: change.message;
const author =
options?.author === 'githubUsername' && change.author.githubUsername
? change.author.githubUsername
: options?.author === 'nameAndEmail'
? `${change.author.name} (${change.author.email})`
: null;
let author = '';

switch (options?.author) {
case 'githubUsername':
author =
change.author.githubUsername || options?.authorUsername
? `@${change.author.githubUsername || options?.authorUsername}`
: null;
break;
case 'nameAndEmail':
author = `${change.author.name} (${change.author.email})`;
break;
default:
author = options?.authorUsername ? `@${options?.authorUsername}` : null;
break;
}

let userAndTask = '';
if (author && change.taskId) {
userAndTask = ` - By **@${author}** in task ${change.taskId}`;
userAndTask = ` - By **${author}** in task ${change.taskId}`;
} else if (author) {
userAndTask = ` - By **@${author}**`;
userAndTask = ` - By **${author}**`;
} else if (change.taskId) {
userAndTask = ` - In task ${change.taskId}`;
}
Expand Down Expand Up @@ -295,7 +307,8 @@ export default class ConventionalCommitReleaseNotes {
const [message, userName, userEmail] = row.trim().split('|');
if (message) {
commits.push(<ICommit>{
message,
// Remove @ from message to avoid Github to link to a user.
message: message.replace('@', ''),
author: {
name: userName,
email: userEmail,
Expand Down
Loading
Loading