-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathredmine_issue.rb
73 lines (57 loc) · 1.36 KB
/
redmine_issue.rb
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
class RedmineIssue
attr_reader :url
REDMINE_URL_FORMAT = "https://projects.theforeman.org/issues/%{redmine_id}"
def initialize(url_or_id)
if url_or_id =~ /\A\d+\Z/
@url = format(REDMINE_URL_FORMAT, redmine_id: url_or_id)
else
@url = url_or_id.sub(/\/\Z/, '')
end
@url = @url.chomp('/').sub('http://', 'https://')
response = Faraday.get(@url + '.json')
@attrs = JSON.parse(response.body)['issue']
end
def id
@attrs.fetch('id')
end
def subject
@attrs.fetch('subject')
end
def description
@attrs.fetch('description')
end
def project_name
name_attr('project')
end
def tracker_name
name_attr('tracker')
end
def category_name
name_attr('category')
end
def github_links
@attrs['custom_fields'].select { |f| f['name'] == 'Pull request' }.first['value']
end
def bugzilla
@bugzilla ||= Bugzilla.load(bugzilla_link) if bugzilla_link
end
def bugzilla_id
@attrs['custom_fields'].find { |f| f['name'] == 'Bugzilla link'}['value']
end
def bugzilla_link
"https://bugzilla.redhat.com/show_bug.cgi?id=#{bugzilla_id}" if bugzilla_id
end
def status_id
@attrs['status']['id'].to_i
end
def assigned_to
name_attr('assigned_to')
end
def updated_on
@attrs['updated_on']
end
private
def name_attr(attr)
@attrs.fetch(attr, {})['name']
end
end