Last active
April 10, 2017 07:46
-
-
Save laginha87/a9234a03f2a3c3e6a2c6558846b0ee9c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
require 'json' | |
USAGE = "USAGE:\ngit ticket TICKET_ID\n" | |
# get ticket ID from first command line argument | |
ticket_id = ARGV[0] | |
unless ticket_id | |
print USAGE | |
exit | |
end | |
## Get jira configuration from repo config | |
jira_user = `git config jira.user`.sub("\n",'') | |
jira_token = `git config jira.token`.sub("\n",'') | |
jira_url = `git config jira.url`.sub("\n",'') | |
## Get ticket data from jira | |
jira_response = `curl -s -u \"#{jira_user}:#{jira_token}\" -X GET https://#{jira_url}/rest/api/2/issue/#{ticket_id}` | |
## Parse the response | |
jira_ticket = JSON.parse(jira_response) | |
jira_fields = jira_ticket['fields'] | |
## Get the ticket type | |
type = jira_fields['issuetype']['name'].downcase | |
description = jira_fields["summary"][0..50].split.join('_').downcase | |
## Create branch name from ticket name, description and type | |
branch_name = "#{ticket_id}-#{type}-#{description}" | |
## Print out the branch name | |
puts branch_name | |
## Copy the branch name to the clipboard | |
`printf #{branch_name} | pbcopy` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment