diff --git a/README.md b/README.md index 495078f..b381d7d 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,18 @@ But no need to generate any new token, you can use the Github action token (`${{ token: ${{ github.token }} ``` +#### Report name + +```yml +- uses: devmasx/coverage-check-action@v1.2.0 + with: + type: lcov + result_path: coverage/example.lcov + min_coverage: 90 + token: ${{ github.token }} + report_name: "My Github Action Check Name" +``` + ## Screenshots ![Success](./screenshots/success.png) diff --git a/action.yml b/action.yml index 673b54e..b8c4ad1 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,9 @@ inputs: min_coverage: description: "Minimum coverage" default: "80" + report_name: + description: "Name of the github action check" + default: "Coverage" result_path: description: "Json with coverage result" required: true diff --git a/lib/github_check_run_service.rb b/lib/github_check_run_service.rb index 6d8feca..878d81e 100644 --- a/lib/github_check_run_service.rb +++ b/lib/github_check_run_service.rb @@ -1,11 +1,10 @@ # frozen_string_literal: true class GithubCheckRunService - CHECK_NAME = 'Coverage' - - def initialize(report, github_data, report_adapter) + def initialize(report, github_data, report_name, report_adapter) @report = report @github_data = github_data + @report_name = report_name @report_adapter = report_adapter @client = GithubClient.new(@github_data[:token], user_agent: 'coverage-action') end @@ -34,7 +33,7 @@ def endpoint_url def create_check_payload { - name: CHECK_NAME, + name: @report_name, head_sha: @github_data[:sha], status: 'in_progress', started_at: Time.now.iso8601 @@ -43,13 +42,13 @@ def create_check_payload def update_check_payload { - name: CHECK_NAME, + name: @report_name, head_sha: @github_data[:sha], status: 'completed', completed_at: Time.now.iso8601, conclusion: @conclusion, output: { - title: "#{CHECK_NAME} #{@percent}%", + title: "#{@report_name} #{@percent}%", summary: @summary, annotations: @annotations } diff --git a/lib/index.rb b/lib/index.rb index e888441..0b2e64c 100644 --- a/lib/index.rb +++ b/lib/index.rb @@ -17,13 +17,14 @@ def read_json(path) sha: ENV['GITHUB_SHA'], token: ENV['INPUT_TOKEN'], owner: ENV['GITHUB_REPOSITORY_OWNER'] || @event_json.dig('repository', 'owner', 'login'), - repo: ENV['GITHUB_REPOSITORY_NAME'] || @event_json.dig('repository', 'name') + repo: ENV['GITHUB_REPOSITORY_NAME'] || @event_json.dig('repository', 'name'), } @coverage_type = ENV['INPUT_TYPE'] @report_path = ENV['INPUT_RESULT_PATH'] +@report_name = ENV['INPUT_REPORT_NAME'] @data = { min: ENV['INPUT_MIN_COVERAGE'] } @report = CoverageReport.generate(@coverage_type, @report_path, @data) -GithubCheckRunService.new(@report, @github_data, ReportAdapter).run +GithubCheckRunService.new(@report, @github_data, @report_name, ReportAdapter).run diff --git a/spec/github_check_run_service_spec.rb b/spec/github_check_run_service_spec.rb index b76cb51..036a85e 100644 --- a/spec/github_check_run_service_spec.rb +++ b/spec/github_check_run_service_spec.rb @@ -7,7 +7,8 @@ { 'lines' => { 'covered_percent' => 80, 'minumum_percent' => 80 } } end let(:github_data) { { sha: 'sha', token: 'token', owner: 'owner', repo: 'repository_name' } } - let(:service) { GithubCheckRunService.new(report, github_data, ReportAdapter) } + let(:report_name) { 'Coverage' } + let(:service) { GithubCheckRunService.new(report, github_data, report_name, ReportAdapter) } it '#run' do stub_request(:any, 'https://api.github.com/repos/owner/repository_name/check-runs/id')