Last active
December 6, 2018 21:36
-
-
Save thrgamon/0437b19d1959cf191f5d3c26e0fbfd28 to your computer and use it in GitHub Desktop.
Takes the ticket prefix from the branch name and adds it to the commit message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
BRANCHES_TO_SKIP = ['master', 'develop'].freeze | |
# Grabs 1-4 letters, a dash and 1-4 numbers after a leading slash. | |
# For example, with the string 'feature/DOT-38-update-gems' it would match 'DOT-38' | |
PREFIX_REGEX = /(?<=\/)[a-zA-Z]{1,4}-\d{1,4}/.freeze | |
message_file = ARGV[0] | |
branch_name = `git symbolic-ref --short HEAD`.strip | |
return if BRANCHES_TO_SKIP.include?(branch_name) | |
return unless branch_name =~ PREFIX_REGEX | |
jira_ticket_prefix = branch_name.scan(PREFIX_REGEX).first | |
message_text = File.read(message_file) | |
return if message_text.include?(jira_ticket_prefix) | |
new_message_text = [jira_ticket_prefix, ': ', message_text].join | |
File.write(message_file, new_message_text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment