Skip to content

Commit

Permalink
feat: use user login as default assignee
Browse files Browse the repository at this point in the history
Also dynamically update help message based on default values
  • Loading branch information
jamacku committed Aug 14, 2024
1 parent 87f94d5 commit 3b3674b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Arguments:
Options:
-V, --version output the version number
-c, --component [component] Issue component
-a, --assignee [assignee] Issue assignee
-a, --assignee [assignee] Issue assignee (default: "<user-login>@redhat.com")
-d, --developer [developer] Issue developer
-l, --legend Print legend
-h, --help display help for command
Expand Down
20 changes: 16 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '@total-typescript/ts-reset';

import { Jira } from './jira';
import { getLegend } from './legend';
import { getOptions, raise, tokenUnavailable } from './util';
import { getDefaultValue, getOptions, raise, tokenUnavailable } from './util';

import {
colorPrioritySchema,
Expand Down Expand Up @@ -41,9 +41,21 @@ const cli = async () => {
.version('1.0.0');

program
.option('-c, --component [component]', 'Issue component')
.option('-a, --assignee [assignee]', 'Issue assignee')
.option('-d, --developer [developer]', 'Issue developer')
.option(
'-c, --component [component]',
'Issue component',
getDefaultValue('COMPONENT')
)
.option(
'-a, --assignee [assignee]',
'Issue assignee',
getDefaultValue('ASSIGNEE')
)
.option(
'-d, --developer [developer]',
'Issue developer',
getDefaultValue('DEVELOPER')
)
.option('-l, --legend', 'Print legend');

program.argument('[string]', 'Issue keys separated by `␣`');
Expand Down
15 changes: 14 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { OptionValues } from 'commander';
import os from 'os';
import { env } from 'process';

export function raise(error: string): never {
throw new Error(error);
Expand All @@ -10,10 +12,21 @@ export function tokenUnavailable(): never {
);
}

export function getUserFromLogin(): string {
const login = os.userInfo().username;
return `${login}@redhat.com`;
}

export function getDefaultValue(
envName: 'ASSIGNEE' | 'COMPONENT' | 'DEVELOPER'
) {
return process.env[envName];
const value = process.env[envName];

if (envName === 'ASSIGNEE' && !value) {
return getUserFromLogin();
}

return value;
}

export function getOptions(inputs: OptionValues): OptionValues {
Expand Down

0 comments on commit 3b3674b

Please sign in to comment.