lighthouse_tracker.rb
1.37 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
class IssueTrackers::LighthouseTracker < IssueTracker
Label = "lighthouseapp"
Fields = [
[:account, {
:placeholder => "abc from http://abc.lighthouseapp.com"
}],
[:api_token, {
:placeholder => "API Token for your account"
}],
[:project_id, {
:placeholder => "Lighthouse project"
}]
]
def check_params
if Fields.detect {|f| self[f[0]].blank? }
errors.add :base, 'You must specify your Lighthouseapp account, API token and Project ID'
end
end
def create_issue(problem, reported_by = nil)
Lighthouse.account = account
Lighthouse.token = api_token
# updating lighthouse account
Lighthouse::Ticket.site
Lighthouse::Ticket.format = :xml
ticket = Lighthouse::Ticket.new(:project_id => project_id)
ticket.title = issue_title problem
ticket.body = body_template.result(binding)
ticket.tags << "errbit"
ticket.save!
problem.update_attributes(
:issue_link => "#{Lighthouse::Ticket.site.to_s.sub(/#{Lighthouse::Ticket.site.path}$/, '')}#{Lighthouse::Ticket.element_path(ticket.id, :project_id => project_id)}".sub(/\.xml$/, ''),
:issue_type => Label
)
end
def body_template
@@body_template ||= ERB.new(File.read(Rails.root + "app/views/issue_trackers/lighthouseapp_body.txt.erb").gsub(/^\s*/, ''))
end
def url
"http://#{account}.lighthouseapp.com"
end
end