Skip to content
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
9 changes: 6 additions & 3 deletions docs/config/engineer.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export interface GenerateAIPromptType {
type: string
defaultScope?: string
maxSubjectLength?: number
upperCaseSubject?: boolean
upperCaseSubject?: boolean | null
diff?: string
}
```
Expand All @@ -188,8 +188,11 @@ module.exports = {
## upperCaseSubject

- **description** : Whether to automatically capitalize the first character of the short description (subject)
- **type** : `boolean`
- **default** : `false`
- **type** : `boolean` | `null`
- `null`: Do not process
- `true`: Automatically capitalize the first letter
- `false`: Automatically lowercase the first letter
- **default** : `null`

## breaklineNumber

Expand Down
9 changes: 6 additions & 3 deletions docs/public/schema/cz-git.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@
"default": "empty"
},
"upperCaseSubject": {
"type": "boolean",
"description": "Subject is need upper case first.",
"default": false
"type": [
"boolean",
"null"
],
"description": "Subject is need upper case first.\n\n- `null`: Do not enforce capitalization of the first letter\n- `true`: Enforce capitalization of the first letter\n- `false`: Enforce lowercase for the first letter",
"default": null
},
"markBreakingChangeMode": {
"type": "boolean",
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/.commitlintrc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"customScopesAlign": "bottom",
"customScopesAlias": "custom",
"emptyScopesAlias": "empty",
"upperCaseSubject": false,
"upperCaseSubject": null,
"markBreakingChangeMode": false,
"allowBreakingChanges": ["feat", "fix"],
"breaklineNumber": 100,
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/.czrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"customScopesAlign": "bottom",
"customScopesAlias": "custom",
"emptyScopesAlias": "empty",
"upperCaseSubject": false,
"upperCaseSubject": null,
"markBreakingChangeMode": false,
"allowBreakingChanges": ["feat", "fix"],
"breaklineNumber": 100,
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/commitlint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = defineConfig({
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false,
upperCaseSubject: null,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/commitlint.config.cn-en.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = defineConfig({
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false,
upperCaseSubject: null,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/commitlint.config.cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = defineConfig({
customScopesAlign: 'bottom',
customScopesAlias: '以上都不是?我要自定义',
emptyScopesAlias: '跳过',
upperCaseSubject: false,
upperCaseSubject: null,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/commitlint.config.emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = defineConfig({
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false,
upperCaseSubject: null,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/commitlint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default defineConfig({
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false,
upperCaseSubject: null,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/commitlint.config.without-fn.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false,
upperCaseSubject: null,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/commitlint.config.without-fn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default {
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false,
upperCaseSubject: null,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/cz.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = definePrompt({
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false,
upperCaseSubject: null,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/cz.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default definePrompt({
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false,
upperCaseSubject: null,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/cz.config.without-fn.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false,
upperCaseSubject: null,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/cz.config.without-fn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default {
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false,
upperCaseSubject: null,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
Expand Down
9 changes: 6 additions & 3 deletions docs/zh/config/engineer.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export interface GenerateAIPromptType {
type: string
defaultScope?: string
maxSubjectLength?: number
upperCaseSubject?: boolean
upperCaseSubject?: boolean | null
diff?: string
}
```
Expand Down Expand Up @@ -209,8 +209,11 @@ module.exports = {
## upperCaseSubject

- **描述** : 是否自动将 <ruby>简短描述<rt>subject</rt></ruby> 第一个字符进行大写处理
- **类型** : `boolean`
- **默认** : `false`
- **类型** : `boolean` | `null`
- `null`: 不进行处理
- `true`: 首字母自动大写
- `false`: 首字母自动小写
- **默认** : `null`

## breaklineNumber

Expand Down
24 changes: 9 additions & 15 deletions packages/cz-git/src/generator/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import url from 'node:url'
import process from 'node:process'
import { style } from '@cz-git/inquirer'
import HttpsProxyAgent from 'https-proxy-agent'
import { isNodeVersionInRange, log } from '../shared'
import { isNodeVersionInRange, log, transformSubjectCase } from '../shared'
import type { CommitizenGitOptions } from '../shared'

export async function fetchOpenAIMessage(options: CommitizenGitOptions, prompt: string) {
Expand Down Expand Up @@ -88,20 +88,14 @@ function useModelStrategy(options: CommitizenGitOptions, prompt: string) {
function parseAISubject(options: CommitizenGitOptions, subject?: string) {
if (!subject)
return ''

subject = subject
.trim()
.replace(/(\r\n|\n|\r)/g, '')
.replace(/[.。]$/, '')
.replace(/^"|"$/g, '')
let res = subject
if (options.upperCaseSubject)
res = res.charAt(0).toUpperCase()
else
res = res.charAt(0).toLowerCase()
res = res + subject.slice(1)

return res
return transformSubjectCase(
options,
subject
.trim()
.replace(/(\r\n|\n|\r)/g, '')
.replace(/[.。]$/, '')
.replace(/^"|"$/g, ''),
)
}

class APIError extends Error {
Expand Down
46 changes: 19 additions & 27 deletions packages/cz-git/src/generator/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
parseStandardScopes,
resolveListItemPinTop,
resovleCustomListTemplate,
transformSubjectCase,
useThemeCode,
} from '../shared'

Expand Down Expand Up @@ -174,37 +175,28 @@ export function generateQuestions(options: CommitizenGitOptions, cz: any) {
tooltip = `${maxSubjectLength - subjectLength} more chars allowed`
}

tooltip
= (
minSubjectLength !== undefined
&& subjectLength >= minSubjectLength
&& subjectLength <= maxSubjectLength
)
? style.gray(`[${tooltip}]`)
: isWarning
? style.yellow(`[${tooltip}]`)
: style.red(`[${tooltip}]`)
subject
= (
minSubjectLength !== undefined
&& subjectLength >= minSubjectLength
&& subjectLength <= maxSubjectLength
)
tooltip = (
minSubjectLength !== undefined
&& subjectLength >= minSubjectLength
&& subjectLength <= maxSubjectLength
)
? style.gray(`[${tooltip}]`)
: isWarning
? style.yellow(`[${tooltip}]`)
: style.red(`[${tooltip}]`)
subject = (
minSubjectLength !== undefined
&& subjectLength >= minSubjectLength
&& subjectLength <= maxSubjectLength
)
? useThemeCode(subject, options.themeColorCode)
: isWarning
? useThemeCode(subject, options.themeColorCode)
: isWarning
? useThemeCode(subject, options.themeColorCode)
: style.red(subject)
: style.red(subject)

return `${tooltip}\n` + ` ${subject}`
},
filter: (subject: string) => {
const upperCaseSubject = options.upperCaseSubject || false

return (
(upperCaseSubject ? subject.charAt(0).toUpperCase() : subject.charAt(0).toLowerCase())
+ subject.slice(1)
)
},
filter: (subject: string) => transformSubjectCase(options, subject),
},
{
type: 'complete-input',
Expand Down
11 changes: 7 additions & 4 deletions packages/cz-git/src/shared/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export interface GenerateAIPromptType {
type?: string
defaultScope?: string | string[]
maxSubjectLength?: number
upperCaseSubject?: boolean
upperCaseSubject?: boolean | null
diff?: string
}

Expand Down Expand Up @@ -390,9 +390,12 @@ export interface CommitizenGitOptions {
/**
* Subject is need upper case first.
*
* @default false
* - `null`: Do not process
* - `true`: Automatically capitalize the first letter
* - `false`: Automatically lowercase the first letter
* @default null
*/
upperCaseSubject?: boolean
upperCaseSubject?: boolean | null

/**
* Whether to add extra prompt BREAKCHANGE ask. to add an extra "!" to the header
Expand Down Expand Up @@ -653,7 +656,7 @@ export const defaultConfig = Object.freeze({
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false,
upperCaseSubject: null,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
Expand Down
13 changes: 13 additions & 0 deletions packages/cz-git/src/shared/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function parseStandardScopes(scopes: ScopesType): Option[] {
: { value: scope.value, name: scope.name }
})
}

/**
* To get a list of scopes
*
Expand Down Expand Up @@ -197,6 +198,18 @@ export function getProcessSubject(text: string) {
return text.replace(/(^\s+|[\s.]+$)/g, '') ?? ''
}

export function transformSubjectCase(options: CommitizenGitOptions, subject: string) {
if (!subject || options.upperCaseSubject === null)
return subject

const firstChar = subject[0]
const rest = subject.slice(1)

return options.upperCaseSubject
? firstChar.toUpperCase() + rest
: firstChar.toLowerCase() + rest
}

function getEmojiStrLength(options: CommitizenGitOptions, type?: string): number {
const item = options.types?.find((i: { value?: string }) => i.value === type)
// 1: space
Expand Down
7 changes: 5 additions & 2 deletions scripts/czrc-schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,12 @@ export interface CommitizenGitOptions {
/**
* Subject is need upper case first.
*
* @default false
* - `null`: Do not process
* - `true`: Automatically capitalize the first letter
* - `false`: Automatically lowercase the first letter
* @default null
*/
upperCaseSubject?: boolean
upperCaseSubject?: boolean | null

/**
* Whether to add extra prompt BREAKCHANGE ask. to add an extra "!" to the header
Expand Down