di-sukharev / opencommit

Generate conventional git commit messages with AI in 1 second 🤯🔫
https://www.npmjs.com/package/opencommit
MIT License
5.98k stars 318 forks source link

Feature: Support git commit prefixes #59

Open adrianrivers opened 1 year ago

adrianrivers commented 1 year ago

Hi, I'm happy to contribute to this. My work requires that the ticket be referenced in all commit messages e.g. foo-1243-feature-button-component. I'm wondering if it is viable to make the commits reference the ticket number from the branch name e.g. feat/foo-1234-button would result in commit messages being prefixed with foo-1234: blah blah?

di-sukharev commented 1 year ago

hi hi

would be cool to have this configurable via oc config set branch=true or if you have a better name — do it :)

mreduar commented 1 year ago

I just came to ask the same question, it would be great a feature like this, for now without this configuration I can't use oc. Is there any way to get the output of the commit with a command? For example, to do my own command setup, I have an alias as a function that does this job of getting the ticket name automatically for me. For example:

#  Commit everything
function commit() {
    commitMessage="$1"

    if [ "$commitMessage" = "" ]; then
        commitMessage="wip"
    fi

    # check if getIssueName returns a value and if it does, then prepend it to the commit message
    if [ -n "$(getIssueName)" ]; then
        commitMessage="$(getIssueName): $commitMessage"
    fi

    git add .
    git status

    eval "git commit -a -m \"${commitMessage}\" $2"
}

I have another function getIssueName that extracts the ticket name depending on my branch name.

Taking the example of @adrianrivers feat/foo-1234-button the function getIssueName would extract foo-1234 and put it at the beginning of the commit, so when doing

commit "Changes in the user module"

The final message would be: foo-1234: Changes in the user module.

Now, if there was a way to extract the output suggested by opencommit, a function like this could be done automatically.

#  Commit everything
function commit() {
    commitMessage="$1"

    if [ "$commitMessage" = "" ]; then
        commitMessage="wip"
    fi

    generatedMessage="oc --raw" #or sometinhg like that

    # check if getIssueName returns a value and if it does, then prepend it to the commit message
    if [ -n "$(getIssueName)" ]; then
        commitMessage="$(getIssueName): $generatedMessage"
    fi

    git add .
    git status

    eval "git commit -a -m \"${commitMessage}\" $2"
}
mefengl commented 1 year ago

I would like to have config options like below:

oc config set prefix="xxx"

oc config set suffix="xxx"

di-sukharev commented 1 year ago

I believe oc config set scope=true which automatically extracts ticket number and pastes as a prefix is best UX. WDYT?

anybody wants to make a PR?

mreduar commented 1 year ago

I believe oc config set scope=true which automatically extracts ticket number and pastes as a prefix is best UX. WDYT?

It would be great, but I think it would be very difficult to create a regex to identify the ticket of each one, since it could be anything, don't you think?

github-actions[bot] commented 1 year ago

Stale issue message