Add Jira Issue ID With PowerShell Git

At my current client, we use Scrum to help us manage our development process. One of my favorite tenants of Scrum is self organizing teams.

During our sprint retrospective last week, our team decided to append our git commits with the Jira issue Id so that way Jira can track which commits go to which issue. I was against it solely because it was something extra for me to remember to type. So, I did what any programmer who cares about such things does... I automated!

Now, I should warn that I'm not a PowerShell guy in the least. I've been using PoSh Git for about 3 months now and have just started realizing all the things I can simplify with a little scripting.

So, here's my stab at adding the Jira Issue Id:

function gac(){
  git add --all
  $message = formatCommitMessage($args[0])
  git commit -m $message
  git status

function formatCommitMessage(){
  $jiraPrefix = if ($Global:CurrentJiraIssue -eq $null -or $Global:CurrentJiraIssue -eq "") {""} else { "AB-" + $Global:CurrentJiraIssue + " "}
  return $jiraPrefix + $args[0]

function setJiraIssue(){
  $Global:CurrentJiraIssue = $args[0]
  $GitPromptSettings.BeforeText = " [AB-" + $Global:CurrentJiraIssue + " "

function clearJiraIssue(){
 $GitPromptSettings.BeforeText = " ["

Pretty simple. You just call setJiraIssue  and pass in the issue Id. Then my gac function, which adds all files affected, commits with a message then shows the status, and pass in a message. The 'AB' is just our project's prefix. Obviously, you would want to change that to yours. You could also do this with TFS or any other tracking tool that recognizes a git commit. You just need to format the message to what the tool expects.

[caption id="attachment_841" align="alignleft" width="300"]Setting Jira Issue Id In PowerShell Git Setting Jira Issue Id In PowerShell Git[/caption]