class CC::Service::Lighthouse

Public Instance Methods

receive_issue() click to toggle source
# File lib/cc/services/lighthouse.rb, line 36
def receive_issue
  title = %(Fix "#{issue["check_name"]}" issue in #{constant_name})

  body = [issue["description"], details_url].join("\n\n")

  create_ticket(title, body)
end
receive_quality() click to toggle source
# File lib/cc/services/lighthouse.rb, line 32
def receive_quality
  create_ticket(quality_title, details_url)
end
receive_test() click to toggle source
# File lib/cc/services/lighthouse.rb, line 25
def receive_test
  result = create_ticket("Test ticket from Code Climate", "")
  result.merge(
    message: "Ticket <a href='#{result[:url]}'>#{result[:id]}</a> created.",
  )
end
receive_vulnerability() click to toggle source
# File lib/cc/services/lighthouse.rb, line 44
def receive_vulnerability
  formatter = CC::Formatters::TicketFormatter.new(self)

  create_ticket(
    formatter.format_vulnerability_title,
    formatter.format_vulnerability_body,
  )
end

Private Instance Methods

create_ticket(title, ticket_body) click to toggle source
# File lib/cc/services/lighthouse.rb, line 55
def create_ticket(title, ticket_body)
  params = { ticket: { title: title, body: ticket_body } }

  if config.tags.present?
    params[:ticket][:tags] = config.tags.strip
  end

  http.headers["X-LighthouseToken"] = config.api_token
  http.headers["Content-Type"] = "application/json"

  base_url = "https://#{config.subdomain}.lighthouseapp.com"
  url = "#{base_url}/projects/#{config.project_id}/tickets.json"

  service_post(url, params.to_json) do |response|
    body = JSON.parse(response.body)
    {
      id: body["ticket"]["number"],
      url: body["ticket"]["url"],
    }
  end
end