formatting

This commit is contained in:
Hassan El Mghari
2024-01-26 09:53:16 -08:00
parent 578572b1d9
commit f33bfeed60
14 changed files with 836 additions and 3251 deletions

View File

@@ -4,7 +4,8 @@ const commitTypeFormats: Record<CommitType, string> = {
'': '<commit message>',
conventional: '<type>(<optional scope>): <commit message>',
};
const specifyCommitFormat = (type: CommitType) => `The output response must be in format:\n${commitTypeFormats[type]}`;
const specifyCommitFormat = (type: CommitType) =>
`The output response must be in format:\n${commitTypeFormats[type]}`;
const commitTypes: Record<CommitType, string> = {
'': '',
@@ -17,10 +18,11 @@ const commitTypes: Record<CommitType, string> = {
* Conventional Changelog:
* https://github.com/conventional-changelog/conventional-changelog/blob/d0e5d5926c8addba74bc962553dd8bcfba90e228/packages/conventional-changelog-conventionalcommits/writer-opts.js#L182-L193
*/
conventional: `Choose a type from the type-to-description JSON below that best describes the git diff:\n${
JSON.stringify({
conventional: `Choose a type from the type-to-description JSON below that best describes the git diff:\n${JSON.stringify(
{
docs: 'Documentation only changes',
style: 'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
style:
'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
refactor: 'A code change that neither fixes a bug nor adds a feature',
perf: 'A code change that improves performance',
test: 'Adding missing tests or correcting existing tests',
@@ -30,19 +32,24 @@ const commitTypes: Record<CommitType, string> = {
revert: 'Reverts a previous commit',
feat: 'A new feature',
fix: 'A bug fix',
}, null, 2)
}`,
},
null,
2
)}`,
};
export const generatePrompt = (
locale: string,
maxLength: number,
type: CommitType,
) => [
'Generate a concise git commit message written in present tense for the following code diff with the given specifications below:',
`Message language: ${locale}`,
`Commit message must be a maximum of ${maxLength} characters.`,
'Exclude anything unnecessary such as translation. Your entire response will be passed directly into git commit.',
commitTypes[type],
specifyCommitFormat(type),
].filter(Boolean).join('\n');
type: CommitType
) =>
[
'Generate a concise git commit message written in present tense for the following code diff with the given specifications below:',
`Message language: ${locale}`,
`Commit message must be a maximum of ${maxLength} characters.`,
'Exclude anything unnecessary such as translation. Your entire response will be passed directly into git commit.',
commitTypes[type],
specifyCommitFormat(type),
]
.filter(Boolean)
.join('\n');