Class: Xambassador::PeerReview
Overview
Constant Summary
collapse
- BACKEND_OK =
"backend approved".freeze
- FRONTEND_OK =
"frontend approved".freeze
- NEEDS_WORK =
"needs work".freeze
Instance Method Summary
collapse
Methods inherited from StatusCheck
#failure, #pending, #success
Constructor Details
#initialize(connection, pull_request) ⇒ PeerReview
Returns a new instance of PeerReview.
14
15
16
17
18
19
20
21
22
|
# File 'lib/xambassador/status_checks/peer_review.rb', line 14
def initialize(connection, pull_request)
super(connection, pull_request, "Peer Review")
@description_pending = "Labels '#{BACKEND_OK}'"\
" and '#{FRONTEND_OK}' are required"
@description_failure = "Needs work"
fetch_labels(pull_request["issue_url"])
end
|
Instance Method Details
#check_labels(labels) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/xambassador/status_checks/peer_review.rb', line 36
def check_labels(labels)
count = 0
needs_work = false
labels.each do |label|
if label["name"] == BACKEND_OK || label["name"] == FRONTEND_OK
count += 1
elsif label["name"] == NEEDS_WORK
needs_work = true
end
end
report_status(count, needs_work)
end
|
#fetch_labels(url) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/xambassador/status_checks/peer_review.rb', line 24
def fetch_labels(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = http.request(Net::HTTP::Get.new(url))
body = JSON.parse(response.body)
check_labels(body["labels"])
end
|
#report_status(count, needs_work) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/xambassador/status_checks/peer_review.rb', line 51
def report_status(count, needs_work)
if needs_work == true
failure
elsif count == 2
success
else
pending
end
end
|