Describe the Bug
The commit message generated by the generateCommitMessage function is sometimes not formatted correctly. This can lead to commit messages that are not suitable for use in version control systems, potentially causing confusion or errors in the commit history.
Additional Context
The issue arises in the generateCommitMessage function within the src/commit-message.ts file. The function uses the OpenAI API to generate commit messages based on the provided changes and configuration. However, the output from the API may not always adhere to the expected format for commit messages.
Proposed Solution
Implement a parser to handle the formatting of the generated commit message. This parser should ensure that the commit message adheres to a standard format, such as the conventional commit format, and handle any necessary adjustments to the message content.
Steps to Implement the Solution
- Create a new function
parseCommitMessage that takes the generated message as input.
- Define the expected format for the commit message (e.g., conventional commits).
- Implement logic within
parseCommitMessage to adjust the message to fit the expected format.
- Integrate
parseCommitMessage into the generateCommitMessage function to process the output before returning it.
Example
function parseCommitMessage(message: string): string {
// Implement parsing logic here
// For example, ensure the message starts with a type and scope
return formattedMessage;
}
// Update generateCommitMessage to use parseCommitMessage
export async function generateCommitMessage(client: OpenAI, minifiedChanges: string, config: ClientConfig = getClientConfig()) {
const response = await client.chat.completions.create({
model: config.model,
messages: [
{
role: "system",
content: config.prompt,
},
{
role: "user",
content: `${minifiedChanges}`,
},
],
temperature: config.temperature,
max_tokens: config.maxTokens,
seed: config.seed,
stream: false,
});
const rawMessage = response.choices[0].message.content ?? "";
return parseCommitMessage(rawMessage);
}
Describe the Bug
The commit message generated by the
generateCommitMessagefunction is sometimes not formatted correctly. This can lead to commit messages that are not suitable for use in version control systems, potentially causing confusion or errors in the commit history.Additional Context
The issue arises in the
generateCommitMessagefunction within thesrc/commit-message.tsfile. The function uses the OpenAI API to generate commit messages based on the provided changes and configuration. However, the output from the API may not always adhere to the expected format for commit messages.Proposed Solution
Implement a parser to handle the formatting of the generated commit message. This parser should ensure that the commit message adheres to a standard format, such as the conventional commit format, and handle any necessary adjustments to the message content.
Steps to Implement the Solution
parseCommitMessagethat takes the generated message as input.parseCommitMessageto adjust the message to fit the expected format.parseCommitMessageinto thegenerateCommitMessagefunction to process the output before returning it.Example