Skip to content

Commit

Permalink
refactor: improve prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Apr 26, 2023
1 parent 91f1918 commit ffbff91
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/utils/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
47 changes: 34 additions & 13 deletions tests/specs/cli/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit ffbff91

Please sign in to comment.