Skip to content

Commit

Permalink
feat: bring features from node-coveralls
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed Mar 3, 2023
1 parent 7720066 commit d27ee85
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 43 deletions.
12 changes: 1 addition & 11 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

## ENV variables

These variables are always used if provided.

| Name | Description |
| ------------------------------ | ----------- |
| `COVERALLS_REPO_TOKEN` | Repository token |
Expand All @@ -20,23 +18,15 @@ These variables are always used if provided.
| `COVERALLS_RUN_AT` | A date string for the time that the job ran in RFC 3339 format. Default: current timestamp. |
| `COVERALLS_FLAG_NAME` | Job flag name, e.g. "Unit", "Functional", or "Integration". Will be shown in the Coveralls UI. |
| `COVERALLS_PARALLEL` | set to true when running jobs in parallel, requires a completion webhook. More info here: https://docs.coveralls.io/parallel-build-webhook |
| `COVERALLS_CARRYFORWARD_FLAGS` | Comma-separated list of parallel job flags to use carry-forwarding for. |

## YAML config

This config is optional.

Its values are used in favor of CI-specific options but can be overwritten with [COVERALLS_* ENVs](#env-variables).
Filename: `.coveralls.yml`

```yml
# .coveralls.yml

# Repository token
repo_token: abcde12345

# Repository name
repo_name: myorg/myrepo

# The name of your build system
service_name: my-ci
```
12 changes: 1 addition & 11 deletions spec/coverage_reporter/parsers/lcov_parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,7 @@ Spectator.describe CoverageReporter::LcovParser do
describe "#parse" do
let(filename) { "spec/fixtures/test.lcov" }
let(coverage) do
[
1, 1, 1, nil, 1, 66, 66, nil, nil, 1, 323, 63, 63, 63, 60, nil, 3, nil, 63, 32,
nil, 63, 63, 63, 3, nil, 63, 60, nil, 3, nil, 63, 27, 27, 27, nil, nil, 323, nil,
nil, 1, 5, 5, nil, 2, nil, nil, 3, 3, 1, 1, 1, 1, nil, 0, nil, nil, 2, 2, 2, 0,
nil, 2, nil, nil, 2, 2, nil, nil, nil, nil, 1, 1, 1, 1, 1, 1, nil, 1, 1, nil, 1,
87, 87, 6, 6, 6, 6, 9, 6, 6, nil, 81, nil, nil, nil, 1, 1, nil, nil, 1, 1, nil,
nil, 1, nil, 2, 2, 2, 1, nil, 2, nil, nil, 1, 3, 1, 1, nil, nil, 2, 2, 2, nil,
1, 1, nil, 2, nil, nil, nil, 1, 1, nil, nil, 1, 50, 50, 50, 50, 20, nil, 50, 50,
2, nil, 50, 50, 50, 31, nil, 50, 24, nil, 50, nil, nil, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
] of Int64?
[1, 1, 1, nil, 1, 66, 66, nil, nil, 1, 323, 63, 63, 63, 60, nil, 3, nil, 63, 32, nil, 63, 63, 63, 3, nil, 63, 60, nil, 3, nil, 63, 27, 27, 27, nil, nil, 323, nil, nil, 1, 5, 5, nil, 2, nil, nil, 3, 3, 1, 1, 1, 1, nil, 0, nil, nil, 2, 2, 2, 0, nil, 2, nil, nil, 2, 2, nil, nil, nil, nil, 1, 1, 1, 1, 1, 1, nil, 1, 1, nil, 1, 87, 87, 6, 6, 6, 6, 9, 6, 6, nil, 81, nil, nil, nil, 1, 1, nil, nil, 1, 1, nil, nil, 1, nil, 2, 2, 2, 1, nil, 2, nil, nil, 1, 3, 1, 1, nil, nil, 2, 2, 2, nil, 1, 1, nil, 2, nil, nil, nil, 1, 1, nil, nil, 1, 50, 50, 50, 50, 20, nil, 50, 50, 2, nil, 50, 50, 50, 31, nil, 50, 24, nil, 50, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
end

it "parses correctly" do
Expand Down
4 changes: 2 additions & 2 deletions src/coverage_reporter/api/jobs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require "json"

module CoverageReporter
class Api::Jobs
@source : Array(Hash(Symbol, String | Array(Int64?) | Array(Int64)))
@source : Array(Hash(Symbol, String | Array(Int32?)))

def initialize(
@config : Config,
Expand All @@ -19,7 +19,7 @@ module CoverageReporter
"You must call the webhook after all jobs finish: `coveralls --done`"
end

@source = source_files.map(&.to_h)
@source = source_files.map &.to_h
end

def send_request(dry_run : Bool = false)
Expand Down
7 changes: 6 additions & 1 deletion src/coverage_reporter/api/webhook.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ require "json"

module CoverageReporter
class Api::Webhook
def initialize(@config : Config, @carryforward : String?)
@token : String | Nil
@build_num : String | Nil

def initialize(config : Config)
@token = config.repo_token
@build_num = config[:service_number]?
end

def send_request(dry_run : Bool = false)
Expand Down
5 changes: 2 additions & 3 deletions src/coverage_reporter/cli/cmd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ module CoverageReporter::Cli
property filename : String?
property repo_token : String?
property base_path : String?
property carryforward : String? = ENV["COVERALLS_CARRYFORWARD_FLAGS"]?.presence
property job_flag_name : String? = ENV["COVERALLS_FLAG_NAME"]?.presence
property job_flag_name = ENV["COVERALLS_FLAG_NAME"]?
property config_path = CoverageReporter::YamlConfig::DEFAULT_LOCATION
property? no_logo = false
property? parallel = !!(ENV["COVERALLS_PARALLEL"]?.presence && ENV["COVERALLS_PARALLEL"] != "false")
property? parallel = !!(ENV["COVERALLS_PARALLEL"]? && ENV["COVERALLS_PARALLEL"] != "false")
property? parallel_done = false
property? dry_run = false
end
Expand Down
3 changes: 1 addition & 2 deletions src/coverage_reporter/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ module CoverageReporter

private def custom_options : Hash(Symbol, String)
CI::Options.new(
service_name: ENV["COVERALLS_SERVICE_NAME"]?.presence || @yaml["service_name"]?.try(&.to_s).presence,
service_name: ENV["COVERALLS_SERVICE_NAME"]? || @yaml["service_name"]?.try(&.to_s),
service_number: ENV["COVERALLS_SERVICE_NUMBER"]?.presence,
service_job_id: ENV["COVERALLS_SERVICE_JOB_ID"]?.presence,
service_job_number: ENV["COVERALLS_SERVICE_JOB_NUMBER"]?.presence,
service_branch: ENV["COVERALLS_GIT_BRANCH"]?.presence,
commit_sha: ENV["COVERALLS_GIT_COMMIT"]?.presence,
repo_name: ENV["COVERALLS_REPO_NAME"]?.presence || @yaml["repo_name"]?.try(&.to_s).presence,
).to_h
end
end
Expand Down
14 changes: 7 additions & 7 deletions src/coverage_reporter/git.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module CoverageReporter
:head => {
:id => config[:commit_sha]? || head.commit,
:committer_email => head.committer_email,
:committer_name => head.committer_name,
:committer_name => head.committer_email,
:author_email => head.author_email,
:author_name => head.author_name,
:message => head.message,
Expand All @@ -26,27 +26,27 @@ module CoverageReporter
@info : Array(String)?

def commit
ENV["GIT_ID"]? || info[0]?.presence
ENV["GIT_ID"]? || info[0].presence
end

def author_name
ENV["GIT_AUTHOR_NAME"]? || info[1]?.presence
ENV["GIT_AUTHOR_NAME"]? || info[1].presence
end

def author_email
ENV["GIT_AUTHOR_EMAIL"]? || info[2]?.presence
ENV["GIT_AUTHOR_EMAIL"]? || info[2].presence
end

def committer_name
ENV["GIT_COMMITTER_NAME"]? || info[3]?.presence
ENV["GIT_COMMITTER_NAME"]? || info[3].presence
end

def committer_email
ENV["GIT_COMMITTER_EMAIL"]? || info[4]?.presence
ENV["GIT_COMMITTER_EMAIL"]? || info[4].presence
end

def message
ENV["GIT_MESSAGE"]? || info[5]?.presence
ENV["GIT_MESSAGE"]? || info[5].presence
end

# Returns git-related info about the HEAD.
Expand Down
1 change: 0 additions & 1 deletion src/coverage_reporter/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module CoverageReporter
PARSERS = {
LcovParser,
SimplecovParser,
CoberturaParser,
}

def initialize(@file : String?, base_path : String?)
Expand Down
4 changes: 4 additions & 0 deletions src/coverage_reporter/parsers/lcov_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ module CoverageReporter
def initialize(@base_path : String?)
end

# Use *base_path* to join with paths found in reports.
def initialize(@base_path : String?)
end

def globs : Array(String)
[
"*.lcov",
Expand Down
9 changes: 4 additions & 5 deletions src/coverage_reporter/parsers/simplecov_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ module CoverageReporter
#
# See: [https://github.com/simplecov-ruby/simplecov](https://github.com/simplecov-ruby/simplecov)
class SimplecovParser < BaseParser
alias Coverage = Array(Int64?)
alias Branches = Hash(String, Hash(String, Int64?))
alias LinesAndBranches = Hash(String, Array(Int64?) | Branches)
alias Timestamp = Int64
alias FileStats = Hash(String, Coverage | LinesAndBranches)
alias Coverage = Array(Int32?)
alias Stats = Hash(String, Array(Int32?))
alias Timestamp = Int32
alias FileStats = Hash(String, Coverage | Stats)
alias SimplecovFormat = Hash(String, Hash(String, FileStats | Timestamp))

def globs : Array(String)
Expand Down

0 comments on commit d27ee85

Please sign in to comment.