forked from qltysh-archive/codeclimate-services
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlighthouse.rb
More file actions
76 lines (58 loc) · 2.12 KB
/
Copy pathlighthouse.rb
File metadata and controls
76 lines (58 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class CC::Service::Lighthouse < CC::Service
class Config < CC::Service::Config
attribute :subdomain, Axiom::Types::String,
description: "Your Lighthouse subdomain"
attribute :api_token, Axiom::Types::Token,
label: "API Token",
description: "Your Lighthouse API Key (http://help.lighthouseapp.com/kb/api/how-do-i-get-an-api-token)"
attribute :project_id, Axiom::Types::String,
description: "Your Lighthouse project ID. You can find this from the URL to your Lighthouse project."
attribute :tags, Axiom::Types::String,
description: "Which tags to add to tickets, comma delimited"
validates :subdomain, presence: true
validates :api_token, presence: true
validates :project_id, presence: true
end
self.title = "Lighthouse"
self.description = "Create tickets in Lighthouse"
self.issue_tracker = true
def receive_test
result = create_ticket("Test ticket from Code Climate", "")
result.merge(
message: "Ticket <a href='#{result[:url]}'>#{result[:id]}</a> created.",
)
end
def receive_quality
create_ticket(quality_title, details_url)
end
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
def receive_vulnerability
formatter = CC::Formatters::TicketFormatter.new(self)
create_ticket(
formatter.format_vulnerability_title,
formatter.format_vulnerability_body,
)
end
private
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
end