diff --git a/src/utils/openai.ts b/src/utils/openai.ts index 2cdfc0df..98596f96 100644 --- a/src/utils/openai.ts +++ b/src/utils/openai.ts @@ -108,7 +108,12 @@ const getPrompt = ( locale: string, diff: string, maxLength: number, -) => `Write a git commit message in present tense for the following diff without prefacing it with anything. Do not be needlessly verbose and make sure the answer is concise and to the point. The response must be no longer than ${maxLength} characters. The response must be in the language ${locale}:\n${diff}`; +) => `${[ + 'Generate a concise git commit message written in present tense for the following code diff with the given specifications.', + `Message language: ${locale}`, + `Message max character length: ${maxLength}`, + 'Do not include anything unnecessary such as the original translation—your entire response will be passed directly into git commit.', +].join('\n')}\n\n${diff}`; const generateStringFromLength = (length: number) => { let result = ''; diff --git a/tests/specs/cli/commits.ts b/tests/specs/cli/commits.ts index 78a37101..b8dbc077 100644 --- a/tests/specs/cli/commits.ts +++ b/tests/specs/cli/commits.ts @@ -50,8 +50,11 @@ export default testSuite(({ describe }) => { const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']); expect(statusAfter.stdout).toBe(''); - const { stdout: commitMessage } = await git('log', ['--oneline']); - console.log('Committed with:', commitMessage); + const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']); + console.log({ + commitMessage, + length: commitMessage.length, + }); expect(commitMessage.length <= 50).toBe(true); await fixture.rm(); @@ -79,7 +82,10 @@ export default testSuite(({ describe }) => { await committing; const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']); - console.log('20 Committed with:', commitMessage, commitMessage.length); + console.log({ + commitMessage, + length: commitMessage.length, + }); expect(commitMessage.length <= 20).toBe(true); await fixture.rm(); @@ -111,8 +117,11 @@ export default testSuite(({ describe }) => { const statusAfter = await git('status', ['--short', '--untracked-files=no']); expect(statusAfter.stdout).toBe(''); - const { stdout: commitMessage } = await git('log', ['-n1', '--oneline']); - console.log('Committed with:', commitMessage); + const { stdout: commitMessage } = await git('log', ['-n1', '--pretty=format:%s']); + console.log({ + commitMessage, + length: commitMessage.length, + }); expect(commitMessage.length <= 50).toBe(true); await fixture.rm(); @@ -151,8 +160,11 @@ export default testSuite(({ describe }) => { const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']); expect(statusAfter.stdout).toBe(''); - const { stdout: commitMessage } = await git('log', ['--oneline']); - console.log('Committed with:', commitMessage); + const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']); + console.log({ + commitMessage, + length: commitMessage.length, + }); expect(commitMessage.length <= 50).toBe(true); await fixture.rm(); @@ -185,8 +197,11 @@ export default testSuite(({ describe }) => { const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']); expect(statusAfter.stdout).toBe(''); - const { stdout: commitMessage } = await git('log', ['--oneline']); - console.log('Committed with:', commitMessage); + const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']); + console.log({ + commitMessage, + length: commitMessage.length, + }); expect(commitMessage).toMatch(japanesePattern); expect(commitMessage.length <= 50).toBe(true); @@ -247,8 +262,11 @@ export default testSuite(({ describe }) => { const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']); expect(statusAfter.stdout).toBe(''); - const { stdout: commitMessage } = await git('log', ['--oneline']); - console.log('Committed with:', commitMessage); + const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']); + console.log({ + commitMessage, + length: commitMessage.length, + }); expect(commitMessage.length <= 50).toBe(true); await fixture.rm(); @@ -279,8 +297,11 @@ export default testSuite(({ describe }) => { const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']); expect(statusAfter.stdout).toBe(''); - const { stdout: commitMessage } = await git('log', ['--oneline']); - console.log('Committed with:', commitMessage); + const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']); + console.log({ + commitMessage, + length: commitMessage.length, + }); expect(commitMessage.length <= 50).toBe(true); await fixture.rm();