class CreateTicket
Constants
- VERSION
Attributes
conf[R]
Public Class Methods
new(conf)
click to toggle source
# File lib/create_ticket.rb, line 15 def initialize(conf) conf = OpenStruct.new(conf) if conf.is_a? Hash @conf = conf end
Public Instance Methods
content()
click to toggle source
# File lib/create_ticket.rb, line 70 def content ERB.new(template).result(binding) end
create_ticket!()
click to toggle source
# File lib/create_ticket.rb, line 36 def create_ticket! response = jira_request.post do |req| req.url '/rest/api/2/issue' req.body = jira_ticket_json end begin key = JSON.parse(response.body).fetch('key') rescue KeyError raise CouldNotCreateTicketError, "Response from JIRA was: #{response.body}" end "#{jira_url}/browse/#{key}" end
description()
click to toggle source
# File lib/create_ticket.rb, line 90 def description # TODO: Assumes Markdown with an h1 at the top. markdown = content.sub(/# .*\n/, '') Kramdown::Document.new(markdown, kramdown_options).to_confluence end
fields()
click to toggle source
# File lib/create_ticket.rb, line 51 def fields effs = { project: { key: project }, issuetype: { name: issue_type }, summary: summary, description: description, assignee: { name: assignee }, reporter: { name: assignee } }.merge(custom_fields) effs[:duedate] = duedate unless duedate.nil? effs end
jira_request()
click to toggle source
# File lib/create_ticket.rb, line 28 def jira_request Faraday.new(url: jira_url) do |faraday| faraday.adapter Faraday.default_adapter faraday.headers['Content-Type'] = 'application/json' faraday.headers['Authorization'] = 'Basic ' + jira_token end end
jira_ticket_json()
click to toggle source
# File lib/create_ticket.rb, line 64 def jira_ticket_json { fields: fields }.to_json end
kramdown_options()
click to toggle source
# File lib/create_ticket.rb, line 79 def kramdown_options { input: 'GFM', syntax_highlighter: 'coderay', syntax_highlighter_opts: { css: 'style', line_numbers: 'table' } } end
summary()
click to toggle source
# File lib/create_ticket.rb, line 74 def summary # TODO: Assumes Markdown with an h1 at the top. content.lines.first[2..-1].strip end
template()
click to toggle source
# File lib/create_ticket.rb, line 24 def template @template ||= File.open(template_filename).read end