This repository has been archived on 2023-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
coverage-check-action/lib/github_check_run_service.rb
Miguel Savignano 6ae146e422
Coverage check (#1)
* adapter for coverage

* report adapter

* generate coverage report

* use inputs
2019-11-02 23:25:41 +01:00

58 lines
1.2 KiB
Ruby

# 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)
@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,
summary: @summary,
annotations: @annotations
}
}
end
end