Skip to content

Commit 45dc2c4

Browse files
authored
feat: add OCO_ONE_LINE_COMMIT config for enabling one line commit message (#307)
1 parent a192441 commit 45dc2c4

4 files changed

Lines changed: 20 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ OCO_MODEL=<either 'gpt-4', 'gpt-3.5-turbo' (default), 'gpt-3.5-turbo-0125', 'gpt
101101
OCO_LANGUAGE=<locale, scroll to the bottom to see options>
102102
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=<message template placeholder, default: '$msg'>
103103
OCO_PROMPT_MODULE=<either conventional-commit or @commitlint, default: conventional-commit>
104+
OCO_ONE_LINE_COMMIT=<one line commit message, default: false>
104105
```
105106

106107
### Global config for all repos

src/commands/config.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export enum CONFIG_KEYS {
2525
OCO_MESSAGE_TEMPLATE_PLACEHOLDER = 'OCO_MESSAGE_TEMPLATE_PLACEHOLDER',
2626
OCO_PROMPT_MODULE = 'OCO_PROMPT_MODULE',
2727
OCO_AI_PROVIDER = 'OCO_AI_PROVIDER',
28+
OCO_ONE_LINE_COMMIT = 'OCO_ONE_LINE_COMMIT'
2829
}
2930

3031
export enum CONFIG_MODES {
@@ -195,6 +196,16 @@ export const configValidators = {
195196
);
196197
return value;
197198
},
199+
200+
[CONFIG_KEYS.OCO_ONE_LINE_COMMIT](value: any) {
201+
validateConfig(
202+
CONFIG_KEYS.OCO_ONE_LINE_COMMIT,
203+
typeof value === 'boolean',
204+
'Must be true or false'
205+
);
206+
207+
return value;
208+
},
198209
};
199210

200211
export type ConfigType = {
@@ -220,7 +231,8 @@ export const getConfig = (): ConfigType | null => {
220231
OCO_MESSAGE_TEMPLATE_PLACEHOLDER:
221232
process.env.OCO_MESSAGE_TEMPLATE_PLACEHOLDER || '$msg',
222233
OCO_PROMPT_MODULE: process.env.OCO_PROMPT_MODULE || 'conventional-commit',
223-
OCO_AI_PROVIDER: process.env.OCO_AI_PROVIDER || 'openai'
234+
OCO_AI_PROVIDER: process.env.OCO_AI_PROVIDER || 'openai',
235+
OCO_ONE_LINE_COMMIT: process.env.OCO_ONE_LINE_COMMIT === 'true' ? true : false
224236
};
225237

226238
const configExists = existsSync(configPath);

src/modules/commitlint/prompts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ const INIT_MAIN_PROMPT = (
267267
${config?.OCO_EMOJI ? 'Use GitMoji convention to preface the commit.' : 'Do not preface the commit with anything.'}
268268
${config?.OCO_DESCRIPTION ? 'Add a short description of WHY the changes are done after the commit message. Don\'t start it with "This commit", just describe the changes.' : "Don't add any descriptions to the commit, only commit message."}
269269
Use the present tense. Use ${language} to answer.
270+
${ config?.OCO_ONE_LINE_COMMIT ? 'Craft a concise commit message that encapsulates all changes made, with an emphasis on the primary updates. If the modifications share a common theme or scope, mention it succinctly; otherwise, leave the scope out to maintain focus. The goal is to provide a clear and unified overview of the changes in a one single message, without diverging into a list of commit per file change.' : ""}
270271
271272
You will strictly follow the following conventions to generate the content of the commit message:
272273
- ${prompts.join('\n- ')}

src/prompts.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ const INIT_MAIN_PROMPT = (
115115
? 'Add a short description of WHY the changes are done after the commit message. Don\'t start it with "This commit", just describe the changes.'
116116
: "Don't add any descriptions to the commit, only commit message."
117117
}
118+
${
119+
config?.OCO_ONE_LINE_COMMIT
120+
? 'Craft a concise commit message that encapsulates all changes made, with an emphasis on the primary updates. If the modifications share a common theme or scope, mention it succinctly; otherwise, leave the scope out to maintain focus. The goal is to provide a clear and unified overview of the changes in a one single message, without diverging into a list of commit per file change.'
121+
: ""
122+
}
118123
Use the present tense. Lines must not be longer than 74 characters. Use ${language} for the commit message.`
119124
});
120125

0 commit comments

Comments
 (0)