Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Bitbucket Commit to be associated to JIRA Ticket by Comment Formatting

The exact need is to force all commits into Bitbucket to be linked to a JIRA ticket.

I have does this before on Subversion by creating a commit hook that looked for the JIRA ticket in the commit text, but I don't want this solution to be necessarily constrained to that prior experience.

Does Bitbucket have a setting somewhere to force association for all commits against Jira tickets? If not - does it have a mechanism for enforce commit comment quality (some sort of hook or regex)? If not - does GIT have something that we can use for this purpose?

The imagined solution is (but not limited to being) a commit hook that fails the commit if the comment text does not contain a leading JIRA ticket, followed by a colon, followed by some commit text, such that:

git commit -m "foo"

fails and

git commit -m "PRJ-9327: foo"

commits...

like image 858
Inquisitor Shm Avatar asked Oct 24 '16 19:10

Inquisitor Shm


People also ask

How do I link a Jira issue to a Bitbucket commit?

Go to the code page and select “Connect to Bitbucket”, then choose the Bitbucket workspace you want to connect. Once you've connected Jira with Bitbucket Cloud, you can connect repositories to your project by including issue keys at the beginning of your branch names, commit messages, or pull requests.

How do I link a commit to a Jira ticket?

Open a Jira issue then go to the Git Commits tab. In this tab, you will see commits, files changed, links to external repository, commit author and more. git commit message to link the commit to this issue. The git commit will get associated with the Jira issue if the commit message includes the exact issue ID.

How do I enable smart commits in Jira?

Log in to Jira Software as a user with administrative permissions. Go to Administration > Applications > DVCS accounts. Click the (settings) icon for the account. Click Enable Smart Commits on new repositories.

How do I change commit message in Jira?

In Sourcetree, you can select the commit for which the message needs to be modified and then choose "Interactive Rebase.." from the Repository menu. Use "Edit Message" during the rebase to include the JIRA key and click "Ok" to save the change.


1 Answers

The BitBucket issue 5658 just got implemented today (April 13th, 2017)

Option to reject commits without an issue key in their message

This feature is now available to all users via the repository settings "links" page

The pre-receive hook that rejects pushes when any commit does not have a valid issue key in its message.
The current implementation relies on the per-repository "Links" setting to determine what a valid issue key looks like. This gives us the ability to validate against Jira, Bitbucket Issues, Connect add-ons, and any configured custom Links.

So you don't need for a third-party plugin anymore.

Link

like image 116
VonC Avatar answered Oct 31 '22 14:10

VonC