class Fuel::CLI::Jira
Public Instance Methods
auth(user)
click to toggle source
# File lib/fuel/cli/jira.rb, line 38 def auth(user) set_credentials(user, ['jira', 'user'], ['jira', 'password']) end
resolve()
click to toggle source
# File lib/fuel/cli/jira.rb, line 28 def resolve transition('resolve issue') end
start(jira = nil)
click to toggle source
# File lib/fuel/cli/jira.rb, line 23 def start(jira = nil) transition('start progress', jira) end
status(jira = nil)
click to toggle source
# File lib/fuel/cli/jira.rb, line 10 def status(jira = nil) jira_id = jira || fetch_jira_or_fail result = self.class.get(issue_endpoint(jira_id)).parsed_response fields = result["fields"] say "#{jira_id}: #{fields['summary']}", :bold table = [['Type', fields['issuetype']['name']]] table << ['Status', fields['status']['name']] assignee = fields['assignee'] && fields['assignee']['displayName'] || 'Unassigned' table << ['Assignee', assignee] print_table table end
submit()
click to toggle source
# File lib/fuel/cli/jira.rb, line 33 def submit transition('submit', nil, fields: { get_field_id(fetch_jira_or_fail, 'review id') => Gerrit.new.gerrit_change_url }) end
Private Instance Methods
fetch_jira_or_fail()
click to toggle source
# File lib/fuel/cli/jira.rb, line 74 def fetch_jira_or_fail commit_message.split("\n")[2] or raise Thor::Error, set_color("No JIRA found at HEAD", :red) end
get_allowed_transitions(jira_id)
click to toggle source
# File lib/fuel/cli/jira.rb, line 69 def get_allowed_transitions(jira_id) result = self.class.get(issue_endpoint(jira_id, "transitions")).parsed_response result["transitions"] end
get_field_id(jira_id, name)
click to toggle source
# File lib/fuel/cli/jira.rb, line 56 def get_field_id(jira_id, name) result = self.class.get(jira_endpoint("field")).parsed_response field = result.find { |r| r['name'].downcase == name.downcase } field && field['id'] end
get_transition_id(jira_id, name)
click to toggle source
# File lib/fuel/cli/jira.rb, line 62 def get_transition_id(jira_id, name) get_allowed_transitions(jira_id).each do |transition| return transition["id"] if transition["name"].downcase == name.downcase end nil end
issue_endpoint(id, path = "")
click to toggle source
# File lib/fuel/cli/jira.rb, line 82 def issue_endpoint(id, path = "") jira_endpoint("issue/#{id}/#{path}") end
jira_endpoint(path = "")
click to toggle source
# File lib/fuel/cli/jira.rb, line 78 def jira_endpoint(path = "") "#{jira_url}/rest/api/2/#{path}" end
jira_url()
click to toggle source
# File lib/fuel/cli/jira.rb, line 52 def jira_url Config.get('jira', 'url').chomp('/') end
transition(name, jira = nil, extra_body = {})
click to toggle source
# File lib/fuel/cli/jira.rb, line 44 def transition(name, jira = nil, extra_body = {}) jira_id = jira || fetch_jira_or_fail body = { transition: { id: get_transition_id(jira_id, name) } }.merge(extra_body) result = self.class.post(issue_endpoint(jira_id, "transitions"), body: body.to_json) say 'Jira status changed.', :green if result.code.to_i < 400 end