Skip to content

Commit

Permalink
feat(cli): ✨ allow issues hint to be customized w/ issuesHint option
Browse files Browse the repository at this point in the history
🏁 Closes: #337
  • Loading branch information
jimmy-guzman committed Aug 14, 2022
1 parent 892276c commit 989d839
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions src/config/helpers/validate-config/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions src/config/helpers/validate-config/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions src/config/helpers/validate-config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const schema: Record<string, Scheme> = {
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,
Expand Down
1 change: 1 addition & 0 deletions src/defaults/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const defaultConfig: GitzyConfig = {
disableEmoji: false,
headerMaxLength: 64,
headerMinLength: 3,
issuesHint: '#123',
issuesPrefix: 'closes',
questions,
scopes: [],
Expand Down
9 changes: 9 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
29 changes: 29 additions & 0 deletions src/prompts/issues.test.ts
Original file line number Diff line number Diff line change
@@ -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<EnquirerPrompt>

expect(issuesPrompt).toStrictEqual({
hint: '#123',
message: issuesMessage(defaultConfig.issuesPrefix),
name: 'issues',
type: 'text',
})
})
})
5 changes: 4 additions & 1 deletion src/prompts/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 1 addition & 3 deletions src/prompts/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 989d839

Please sign in to comment.