Skip to content

Commit

Permalink
tickets in commit msg trump tickets in branch name
Browse files Browse the repository at this point in the history
  • Loading branch information
msolomonTMG committed Nov 3, 2015
1 parent 81acaf9 commit ddcff34
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
27 changes: 27 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
GEM
remote: https://rubygems.org/
specs:
domain_name (0.5.24)
unf (>= 0.0.5, < 1.0.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
json (1.8.3)
mime-types (2.6.1)
netrc (0.10.3)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.1)

PLATFORMS
ruby

DEPENDENCIES
json
rest-client

BUNDLED WITH
1.10.6
23 changes: 18 additions & 5 deletions post-commit
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

# Parse the JIRA ticket in the branch
parse_jira_ticket_in_branch() {
parse_git_branch | grep -e '[A-Za-z]\+-[0-9]\+' -o
# Parse the parameter for a JIRA ticket
parse_jira_ticket() {
echo $1 | grep -e '[A-Za-z]\+-[0-9]\+' -o
#grep '[A-Za-z]\+-[0-9]\+' $1
}

# function for checking the existance of jira credentials
Expand Down Expand Up @@ -98,8 +99,8 @@ log_time() {
# Read JIRA credentials if they exist
jira_credentials_file="`git rev-parse --git-dir`/hooks/timesheet-githook/jira_credentials.txt"

# If the user's branch does not include a JIRA ticket number, they are not eligible to log time with this hook
ticket=`parse_jira_ticket_in_branch`
# Get the branch name
git_branch=`parse_git_branch`

# Find out if this is a smart commit (e.g. git commit -m "JQWE-123 #time 1h #comment fixed it" will log 1 hour already)
commit_message=$(git log -1 HEAD --pretty=%B)
Expand All @@ -109,6 +110,18 @@ else
is_smart_commit=false
fi

# Check for a ticket in the branch name
ticket_in_branch=`parse_jira_ticket $git_branch`

# If the user explicitly mentioned a ticket in their commit message, that ticket trumps the git branch name ticket
ticket_in_commit_message=`parse_jira_ticket $commit_message`

if [ "$ticket_in_commit_message" != "" ]; then
ticket=$ticket_in_commit_message
else
ticket=$ticket_in_branch
fi

# check that the jira credentials file exists
check_jira_credentials

Expand Down

0 comments on commit ddcff34

Please sign in to comment.