diff --git a/README.md b/README.md index 95c28f70..00089017 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ You can use a `gitzy` object in your `package.json`, or the following files: `.g - [breakingChangeEmoji](###breakingChangeEmoji) - [closedIssueEmoji](###closedIssueEmoji) +- [issuesHint](###issuesHint) - [issuesPrefix](###issuesPrefix) - [disableEmoji](###disableEmoji) - [details](###details) @@ -94,6 +95,14 @@ fix: 🐛 resolved nasty bug closedIssueEmoji: '🏁' ``` +### issuesHint + +Allows you to customize the `issues` prompt hint + +```yml +issuesHint: #123 +``` + ### issuesPrefix Allows you to choose the `issuesPrefix` based on [Github supported keywords](https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword). diff --git a/src/config/helpers/validate-config/lang.ts b/src/config/helpers/validate-config/lang.ts index 26ea98cf..1d80ce1b 100644 --- a/src/config/helpers/validate-config/lang.ts +++ b/src/config/helpers/validate-config/lang.ts @@ -8,6 +8,7 @@ export const lang = { disableEmoji: 'disableEmoji must be a boolean', headerMaxLength: 'headerMaxLength must be a number', headerMinLength: 'headerMinLength must be a number', + issuesHint: `issuesHint must be a string`, issuesPrefix: `issuesPrefix must be one of ${validIssuesPrefixes.join(', ')}`, questions: 'questions must be an array of strings', scopes: 'scopes must be an array of strings', diff --git a/src/config/helpers/validate-config/schema.test.ts b/src/config/helpers/validate-config/schema.test.ts index 0f71c38e..ccbcaccc 100644 --- a/src/config/helpers/validate-config/schema.test.ts +++ b/src/config/helpers/validate-config/schema.test.ts @@ -27,6 +27,9 @@ describe('scheme', () => { 'headerMinLength must be a number' ) }) + it(`should return message if issuesHint is invalid`, () => { + expect(schema.issuesHint(1)).toBe('issuesHint must be a string') + }) it(`should return message if issuesPrefix is invalid`, () => { expect(schema.issuesPrefix(1)).toBe( 'issuesPrefix must be one of close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved' diff --git a/src/config/helpers/validate-config/schema.ts b/src/config/helpers/validate-config/schema.ts index 1f179500..a5a09932 100644 --- a/src/config/helpers/validate-config/schema.ts +++ b/src/config/helpers/validate-config/schema.ts @@ -17,6 +17,7 @@ export const schema: Record = { disableEmoji: (value) => isBoolean(value) || lang.disableEmoji, headerMaxLength: (value) => isNumber(value) || lang.headerMaxLength, headerMinLength: (value) => isNumber(value) || lang.headerMinLength, + issuesHint: (value) => isString(value) || lang.issuesHint, issuesPrefix: (value) => isValidIssues(value) || lang.issuesPrefix, questions: (value) => isArrayOfStrings(value) || lang.questions, scopes: (value) => isArrayOfStrings(value) || lang.scopes, diff --git a/src/defaults/config.ts b/src/defaults/config.ts index 7a22aa2b..ed8c6c71 100644 --- a/src/defaults/config.ts +++ b/src/defaults/config.ts @@ -18,6 +18,7 @@ export const defaultConfig: GitzyConfig = { disableEmoji: false, headerMaxLength: 64, headerMinLength: 3, + issuesHint: '#123', issuesPrefix: 'closes', questions, scopes: [], diff --git a/src/interfaces.ts b/src/interfaces.ts index 53243e91..1b29df2f 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -48,6 +48,15 @@ export interface GitzyConfig { disableEmoji: boolean headerMaxLength: number headerMinLength: number + /** + * Allows you to customize the `issues` prompt hint + * @default '#123' + */ + issuesHint: string + /** + * Allows you to choose the `issuesPrefix` based on [Github supported keywords](https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword). + * @default "closes" + */ issuesPrefix: IssuesPrefixes questions: GitzyPrompts[] scopes: string[] diff --git a/src/prompts/issues.test.ts b/src/prompts/issues.test.ts new file mode 100644 index 00000000..9c117664 --- /dev/null +++ b/src/prompts/issues.test.ts @@ -0,0 +1,29 @@ +import type { EnquirerPrompt } from '../interfaces' + +import { defaultConfig } from '../defaults' +import { issues } from './issues' +import { issuesMessage } from './lang' + +describe('issues', () => { + it('should create issues prompt', () => { + const issuesPrompt = issues({ + config: defaultConfig, + answers: { + body: '', + breaking: '', + issues: '', + scope: '', + subject: '', + type: '', + }, + flags: {}, + }) as Required + + expect(issuesPrompt).toStrictEqual({ + hint: '#123', + message: issuesMessage(defaultConfig.issuesPrefix), + name: 'issues', + type: 'text', + }) + }) +}) diff --git a/src/prompts/issues.ts b/src/prompts/issues.ts index 1f871ddc..be300e7c 100644 --- a/src/prompts/issues.ts +++ b/src/prompts/issues.ts @@ -2,7 +2,10 @@ import type { CreatedPrompt } from '../interfaces' import { issuesMessage } from './lang' -export const issues: CreatedPrompt = ({ config: { issuesPrefix } }) => ({ +export const issues: CreatedPrompt = ({ + config: { issuesHint, issuesPrefix }, +}) => ({ + hint: issuesHint, message: issuesMessage(issuesPrefix), name: 'issues', type: 'text', diff --git a/src/prompts/lang.ts b/src/prompts/lang.ts index 3de4014a..2836ca39 100644 --- a/src/prompts/lang.ts +++ b/src/prompts/lang.ts @@ -29,9 +29,7 @@ export const promptsLang: PromptsLang = { } export const issuesMessage = (issuesPrefix: IssuesPrefixes): string => { - return `${bold('Add issues this commit closes, e.g #123')}\n ${closes( - issuesPrefix - )}` + return `${bold(`Add issues this commit closes`)}\n ${closes(issuesPrefix)}` } export const errorMessage = {