Skip to content

Generated Commit Message Formatting Issue #6

Description

@myinusa

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

  1. Create a new function parseCommitMessage that takes the generated message as input.
  2. Define the expected format for the commit message (e.g., conventional commits).
  3. Implement logic within parseCommitMessage to adjust the message to fit the expected format.
  4. 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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions