-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgithub_check_run_service.rb
58 lines (50 loc) · 1.3 KB
/
github_check_run_service.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
# frozen_string_literal: true
class GithubCheckRunService
CHECK_NAME = 'Coverage'
def initialize(report, github_data, report_adapter)
@report = report
@github_data = github_data
@report_adapter = report_adapter
@client = GithubClient.new(@github_data[:token], user_agent: 'coverage-action')
end
def run
id = @client.post(
endpoint_url,
create_check_payload
)['id']
@summary = @report_adapter.summary(@report)
@annotations = @report_adapter.annotations(@report)
@conclusion = @report_adapter.conslusion(@report)
@percent = @report_adapter.lines_covered_percent(@report)
@client.patch(
"#{endpoint_url}/#{id}",
update_check_payload
)
end
private
def endpoint_url
"/repos/#{@github_data[:owner]}/#{@github_data[:repo]}/check-runs"
end
def create_check_payload
{
name: CHECK_NAME,
head_sha: @github_data[:sha],
status: 'in_progress',
started_at: Time.now.iso8601
}
end
def update_check_payload
{
name: CHECK_NAME,
head_sha: @github_data[:sha],
status: 'completed',
completed_at: Time.now.iso8601,
conclusion: @conclusion,
output: {
title: "#{CHECK_NAME} #{@percent}%",
summary: @summary,
annotations: @annotations
}
}
end
end