refactor: improve prompt

This commit is contained in:
Hiroki Osame
2023-04-26 23:11:47 +09:00
parent 91f1918b73
commit ffbff9194a
2 changed files with 40 additions and 14 deletions

View File

@@ -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 = '';

View File

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