Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Support git commit prefixes #59

Open
adrianrivers opened this issue Mar 27, 2023 · 6 comments
Open

Feature: Support git commit prefixes #59

adrianrivers opened this issue Mar 27, 2023 · 6 comments

Comments

@adrianrivers
Copy link

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
Copy link
Owner

di-sukharev commented Mar 28, 2023

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
Copy link

mreduar commented Mar 30, 2023

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
Copy link

mefengl commented Apr 3, 2023

I would like to have config options like below:

oc config set prefix="xxx"

oc config set suffix="xxx"

@di-sukharev
Copy link
Owner

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
Copy link

mreduar commented Apr 5, 2023

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
Copy link

Stale issue message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants