jira_tracker.rb
3.14 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
if defined? JIRA
class IssueTrackers::JiraTracker < IssueTracker
Label = 'jira'
Fields = [
[:base_url, {
:label => 'Jira URL without trailing slash',
:placeholder => 'https://jira.example.org/'
}],
[:context_path, {
:optional => true,
:label => 'Context Path (Just "/" if empty otherwise with leading slash)',
:placeholder => "/jira"
}],
[:username, {
:optional => true,
:label => 'HTTP Basic Auth User',
:placeholder => 'johndoe'
}],
[:password, {
:optional => true,
:label => 'HTTP Basic Auth Password',
:placeholder => 'p@assW0rd'
}],
[:project_id, {
:label => 'Project Key',
:placeholder => 'The project Key where the issue will be created'
}],
[:account, {
:optional => true,
:label => 'Assign to this user. If empty, Jira takes the project default.',
:placeholder => "username"
}],
[:issue_component, {
:label => 'Issue category',
:placeholder => 'Website - Other'
}],
[:issue_type, {
:label => 'Issue type',
:placeholder => 'Bug'
}],
[:issue_priority, {
:label => 'Priority',
:placeholder => 'Normal'
}]
]
def check_params
if Fields.detect { |f| self[f[0]].blank? && !f[1][:optional] }
errors.add :base, 'You must specify all non optional values!'
end
end
#
# @param problem Problem
def create_issue(problem, reported_by = nil)
options = {
:username => username,
:password => password,
:site => base_url,
:context_path => context_path,
:auth_type => :basic,
:use_ssl => base_url.match(/^https/) ? true : false
}
client = JIRA::Client.new(options)
issue = {
:fields => {
:project => {
:key => project_id
},
:summary => issue_title(problem),
:description => body_template.result(binding),
:issuetype => {
:name => issue_type
},
:priority => {
:name => issue_priority,
},
:components => [{:name => issue_component}]
}
}
issue[:fields][:assignee] = {:name => account} if account
issue_build = client.Issue.build
issue_build.save(issue)
issue_build.fetch
problem.update_attributes(
:issue_link => "#{base_url}#{context_path}browse/#{issue_build.key}",
:issue_type => Label
)
# Maybe in a later version?
#remote_link = {
# :url => app_problem_url(problem.app, problem),
# :name => "Link to Errbit Issue"
#}
#remote_link_build = issue_build.remotelink.build
#remote_link_build.save(remote_link)
end
def body_template
@@body_template ||= ERB.new(File.read(Rails.root + "app/views/issue_trackers/jira_body.txt.erb"))
end
end
end