From b07c6f56a0a6a81c62c5d6e1beed5dc38293969a Mon Sep 17 00:00:00 2001 From: Jekri Preclaro Orlina Date: Wed, 28 Sep 2022 14:37:29 +0100 Subject: [PATCH] Allows flag_name to pass thru --- README.md | 2 +- lib/excoveralls/circle.ex | 3 ++- lib/excoveralls/drone.ex | 3 ++- lib/excoveralls/github.ex | 1 + lib/excoveralls/gitlab.ex | 3 ++- lib/excoveralls/post.ex | 1 + lib/excoveralls/semaphore.ex | 3 ++- lib/excoveralls/task/util.ex | 1 + lib/mix/tasks.ex | 6 ++++-- test/mix/tasks_test.exs | 12 +++++++++--- test/post_test.exs | 5 +++-- 11 files changed, 28 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 6bb75bc5..f53a6d33 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ Usage: mix coveralls github repo, so must be exact. Example: If your source file path is "/home/runs/app/test.ex", and your git repo resides in "app", then the root path should be: "/home/runs/app/" (from coveralls.io) - + --flagname Job flag name which will be shown in the Coveralls UI Usage: mix coveralls.detail [--filter file-name-pattern] Used to display coverage with detail diff --git a/lib/excoveralls/circle.ex b/lib/excoveralls/circle.ex index 6259cd2e..627f6dc4 100644 --- a/lib/excoveralls/circle.ex +++ b/lib/excoveralls/circle.ex @@ -22,7 +22,8 @@ defmodule ExCoveralls.Circle do service_pull_request: get_pull_request(), source_files: stats, git: generate_git_info(), - parallel: options[:parallel] + parallel: options[:parallel], + flag_name: options[:flagname] }) end diff --git a/lib/excoveralls/drone.ex b/lib/excoveralls/drone.ex index e970fe9b..6dbd45f6 100644 --- a/lib/excoveralls/drone.ex +++ b/lib/excoveralls/drone.ex @@ -22,7 +22,8 @@ defmodule ExCoveralls.Drone do service_pull_request: get_pull_request(), source_files: stats, git: generate_git_info(), - parallel: options[:parallel] + parallel: options[:parallel], + flag_name: options[:flagname] }) end diff --git a/lib/excoveralls/github.ex b/lib/excoveralls/github.ex index 49b71ed3..f5a04fb3 100644 --- a/lib/excoveralls/github.ex +++ b/lib/excoveralls/github.ex @@ -22,6 +22,7 @@ defmodule ExCoveralls.Github do service_name: "github", source_files: stats, parallel: options[:parallel], + flag_name: options[:flagname], git: git_info() } |> Map.merge(job_data()) diff --git a/lib/excoveralls/gitlab.ex b/lib/excoveralls/gitlab.ex index 8a0c54ca..b801d970 100644 --- a/lib/excoveralls/gitlab.ex +++ b/lib/excoveralls/gitlab.ex @@ -25,7 +25,8 @@ defmodule ExCoveralls.Gitlab do service_pull_request: get_pull_request(), source_files: stats, git: generate_git_info(), - parallel: options[:parallel] + parallel: options[:parallel], + flag_name: options[:flagname] }) end diff --git a/lib/excoveralls/post.ex b/lib/excoveralls/post.ex index 4cc7e889..0f546f8f 100644 --- a/lib/excoveralls/post.ex +++ b/lib/excoveralls/post.ex @@ -19,6 +19,7 @@ defmodule ExCoveralls.Post do service_number: options[:service_number], source_files: source_info, parallel: options[:parallel], + flag_name: options[:flagname], git: generate_git_info(options) }) end diff --git a/lib/excoveralls/semaphore.ex b/lib/excoveralls/semaphore.ex index 5854efb2..5a91fc06 100644 --- a/lib/excoveralls/semaphore.ex +++ b/lib/excoveralls/semaphore.ex @@ -22,7 +22,8 @@ defmodule ExCoveralls.Semaphore do service_pull_request: get_pull_request(), source_files: stats, git: generate_git_info(), - parallel: options[:parallel] + parallel: options[:parallel], + flag_name: options[:flagname] }) end diff --git a/lib/excoveralls/task/util.ex b/lib/excoveralls/task/util.ex index 91b6c827..d588ae81 100644 --- a/lib/excoveralls/task/util.ex +++ b/lib/excoveralls/task/util.ex @@ -26,6 +26,7 @@ Usage: mix coveralls github repo, so must be exact. Example: If your source file path is "/home/runs/app/test.ex", and your git repo resides in "app", then the root path should be: "/home/runs/app/" (from coveralls.io) + --flagname Job flag name which will be shown in the Coveralls UI Usage: mix coveralls.detail [--filter file-name-pattern] Used to display coverage with detail diff --git a/lib/mix/tasks.ex b/lib/mix/tasks.ex index e8d8342e..fb9a1e47 100644 --- a/lib/mix/tasks.ex +++ b/lib/mix/tasks.ex @@ -33,7 +33,7 @@ defmodule Mix.Tasks.Coveralls do message: "Please specify 'test_coverage: [tool: ExCoveralls]' in the 'project' section of mix.exs" end - switches = [filter: :string, umbrella: :boolean, verbose: :boolean, pro: :boolean, parallel: :boolean, sort: :string, output_dir: :string, subdir: :string, rootdir: :string] + switches = [filter: :string, umbrella: :boolean, verbose: :boolean, pro: :boolean, parallel: :boolean, sort: :string, output_dir: :string, subdir: :string, rootdir: :string, flagname: :string] aliases = [f: :filter, u: :umbrella, v: :verbose, o: :output_dir] {args, common_options} = parse_common_options(args, switches: switches, aliases: aliases) all_options = options ++ common_options @@ -65,6 +65,7 @@ defmodule Mix.Tasks.Coveralls do def parse_common_options(args, common_options) do common_switches = Keyword.get(common_options, :switches, []) common_aliases = Keyword.get(common_options, :aliases, []) + {common_options, _remaining, _invalid} = OptionParser.parse(args, common_options) # the switches that excoveralls supports @@ -272,7 +273,7 @@ defmodule Mix.Tasks.Coveralls do aliases = [f: :filter, u: :umbrella, v: :verbose] {remaining, options} = Mix.Tasks.Coveralls.parse_common_options( args, - switches: switches ++ [sha: :string, token: :string, committer: :string, branch: :string, message: :string, name: :string], + switches: switches ++ [sha: :string, token: :string, committer: :string, branch: :string, message: :string, name: :string, flagname: :string], aliases: aliases ++ [n: :name, b: :branch, c: :committer, m: :message, s: :sha, t: :token] ) @@ -289,6 +290,7 @@ defmodule Mix.Tasks.Coveralls do umbrella: options[:umbrella], verbose: options[:verbose], parallel: options[:parallel], + flag_name: options[:flagname] || "", rootdir: options[:rootdir] || "", subdir: options[:subdir] || "" ]) diff --git a/test/mix/tasks_test.exs b/test/mix/tasks_test.exs index 68f5c99b..5dd1bb69 100644 --- a/test/mix/tasks_test.exs +++ b/test/mix/tasks_test.exs @@ -117,6 +117,12 @@ defmodule Mix.Tasks.CoverallsTest do assert(ExCoveralls.ConfServer.get == [type: "circle", parallel: true, args: []]) end + test_with_mock "circle --parallel --flagname someflag", Runner, [run: fn(_, _) -> nil end] do + Mix.Tasks.Coveralls.Circle.run(["--parallel", "--flagname", "someflag"]) + assert(called Runner.run("test", ["--cover"])) + assert(ExCoveralls.ConfServer.get == [type: "circle", parallel: true, flagname: "someflag", args: []]) + end + test_with_mock "semaphore", Runner, [run: fn(_, _) -> nil end] do Mix.Tasks.Coveralls.Semaphore.run([]) assert(called Runner.run("test", ["--cover"])) @@ -142,14 +148,14 @@ defmodule Mix.Tasks.CoverallsTest do System.put_env("COVERALLS_REPO_TOKEN", "dummy_token") System.put_env("COVERALLS_SERVICE_NAME", "dummy_service_name") - args = ["-b", "branch", "-c", "committer", "-m", "message", "-s", "asdf", "--rootdir", "umbrella0/", "--subdir", "", "--build", "1"] + args = ["-b", "branch", "-c", "committer", "-m", "message", "-s", "asdf", "--rootdir", "umbrella0/", "--subdir", "", "--build", "1", "--flagname", "arbitrary_value"] Mix.Tasks.Coveralls.Post.run(args) assert(called Runner.run("test", ["--cover"])) assert(ExCoveralls.ConfServer.get == [type: "post", endpoint: nil, token: "dummy_token", service_name: "dummy_service_name", service_number: "1", branch: "branch", committer: "committer", sha: "asdf", message: "message", - umbrella: nil, verbose: nil, parallel: nil, rootdir: "umbrella0/", subdir: "", args: []]) + umbrella: nil, verbose: nil, parallel: nil, flag_name: "arbitrary_value", rootdir: "umbrella0/", subdir: "", args: []]) System.put_env("COVERALLS_REPO_TOKEN", org_token) System.put_env("COVERALLS_SERVICE_NAME", org_name) @@ -169,7 +175,7 @@ defmodule Mix.Tasks.CoverallsTest do [type: "post", endpoint: nil, token: "token", service_name: "excoveralls", service_number: "", branch: "", committer: "", sha: "", message: "[no commit message]", - umbrella: nil, verbose: nil, parallel: nil, rootdir: "", subdir: "", args: []]) + umbrella: nil, verbose: nil, parallel: nil, flag_name: "", rootdir: "", subdir: "", args: []]) if org_token != nil do System.put_env("COVERALLS_REPO_TOKEN", org_token) diff --git a/test/post_test.exs b/test/post_test.exs index 937a98b6..810ca75a 100644 --- a/test/post_test.exs +++ b/test/post_test.exs @@ -30,11 +30,12 @@ defmodule ExCoveralls.PostTest do branch: "", committer: "", message: "", - sha: "" + sha: "", + flagname: "arbitrary_value" ]) assert json == - "{\"git\":{\"branch\":\"\",\"head\":{\"committer_name\":\"\",\"id\":\"\",\"message\":\"\"}}," <> + "{\"flag_name\":\"arbitrary_value\",\"git\":{\"branch\":\"\",\"head\":{\"committer_name\":\"\",\"id\":\"\",\"message\":\"\"}}," <> "\"parallel\":null," <> "\"repo_token\":\"1234567890\"," <> "\"service_name\":\"local\"," <>