ai-commit icon indicating copy to clipboard operation
ai-commit copied to clipboard

Extract issue name from branch and append to commit message

Open aozmekik opened this issue 3 years ago • 5 comments

Feature Request: Extract Issue Name from Branch and Append to Commit Message

Overview

For developers who follow a naming convention for their branches that includes an issue name or identifier, it would be beneficial for the aicommits tool to automatically extract this issue name and append it to the generated commit message. This ensures that each commit is directly associated with the relevant issue, providing better traceability and context.

Current Behavior

Currently, when using the aicommits tool, the generated commit message is in the format:

<commit_msg>

Desired Behavior

Given a branch name that follows the convention feature/abc-576, bugfix/abc-577, etc., the tool should extract the issue name (e.g., abc-576) and append it to the commit message. The resulting commit message should be:

abc-576 <commit_msg>

Use Case

Consider a developer working on a feature branch named feature/abc-576. They make some changes and stage them. When they use the aicommits tool to generate a commit message, the tool should:

  1. Detect the current branch name.
  2. Extract the issue name from the branch name.
  3. Append the issue name to the generated commit message.

For example, if the AI-generated commit message is "Added new login functionality", the final commit message should be:

abc-576 Added new login functionality 

Implementation Suggestions

  1. Use Git commands to detect the current branch name.
  2. Use regular expressions or string manipulation to extract the issue name from the branch name.
  3. Append the issue name to the AI-generated commit message.

Benefits

  • Traceability: By associating commits with specific issues, developers and teams can easily trace changes back to their originating requirements or bug reports.

  • Context: When reviewing commit histories, having the issue name directly in the commit message provides immediate context about the purpose of the change.

  • Integration with Other Tools: Many project management and CI/CD tools can utilize the issue name in the commit message for better automation and linking of code changes to tasks.

Alternatives

I am editing the commit message in this way right now,

git commit --amend

And I am pushing it.

aozmekik avatar Oct 11 '23 20:10 aozmekik

Super good idea. I'll look into it 👍🏼

negoziator avatar Oct 11 '23 20:10 negoziator

@aozmekik It's implemented.

Update aicommit

npm update -g @negoziator/ai-commit

Enable prepend-reference

aicommit config set prepend-reference=true

See docs: https://github.com/negoziator/ai-commit#prepend-reference

negoziator avatar Oct 11 '23 21:10 negoziator

Thanks a lot! I can't wait to use it.

aozmekik avatar Oct 11 '23 21:10 aozmekik

@aozmekik No problem 👍🏼

Consider staring the repo, so you will get updates ⭐

negoziator avatar Oct 11 '23 22:10 negoziator

I starred.

aozmekik avatar Oct 11 '23 22:10 aozmekik