Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support travis pro. #37

Merged
merged 1 commit into from
Jan 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ script:
- "MIX_ENV=test mix do deps.get, compile, coveralls.travis"
```

If you're using [Travis Pro](https://travis-ci.com/) for a private
project, Use `coveralls.travis --pro` and ensure your coveralls.io
repo token is available via the `COVERALLS_REPO_TOKEN` environment
variable.

### [mix coveralls.post] Post coverage from localhost
Acquire the repository token of coveralls.io in advance, and run the `mix coveralls.post` command.
It is for submitting the result to coveralls server from localhost.
Expand Down
4 changes: 2 additions & 2 deletions lib/excoveralls/task/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Usage: mix coveralls.detail [--filter file-name-pattern]
Used to display coverage with detail
[--filter file-name-pattern] can be used to limit the files to be displayed in detail

Usage: mix coveralls.travis
Used to post coverage from Travis CI server
Usage: mix coveralls.travis [--pro]
Used to post coverage from Travis CI server.

Usage: mix coveralls.post [options] [coveralls-token]
Used to post coverage from local server using token
Expand Down
17 changes: 15 additions & 2 deletions lib/excoveralls/travis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@ defmodule ExCoveralls.Travis do
alias ExCoveralls.Poster

def execute(stats, options) do
json = generate_json(stats)
json = generate_json(stats, Enum.into(options, %{}))
if options[:verbose] do
IO.puts JSX.prettify!(json)
end
Poster.execute(json)
end

def generate_json(stats) do
def generate_json(stats, options \\ %{})
def generate_json(stats, %{ pro: true }) do
JSX.encode!([
service_job_id: get_job_id,
service_name: "travis-pro",
repo_token: get_repo_token,
source_files: stats
])
end
def generate_json(stats, _options) do
JSX.encode!([
service_job_id: get_job_id,
service_name: "travis-ci",
Expand All @@ -23,4 +32,8 @@ defmodule ExCoveralls.Travis do
defp get_job_id do
System.get_env("TRAVIS_JOB_ID")
end

defp get_repo_token do
System.get_env("COVERALLS_REPO_TOKEN")
end
end
6 changes: 6 additions & 0 deletions test/mix/tasks_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ defmodule Mix.Tasks.CoverallsTest do
assert(ExCoveralls.ConfServer.get == [type: "travis", args: []])
end

test_with_mock "travis --pro", Mix.Task, [run: fn(_, _) -> nil end] do
Mix.Tasks.Coveralls.Travis.run(["--pro"])
assert(called Mix.Task.run("test", ["--cover"]))
assert(ExCoveralls.ConfServer.get == [type: "travis", pro: true, args: []])
end

test_with_mock "post", Mix.Task, [run: fn(_, _) -> nil end] do
org_token = System.get_env("COVERALLS_REPO_TOKEN") || ""
org_name = System.get_env("COVERALLS_SERVICE_NAME") || ""
Expand Down
11 changes: 11 additions & 0 deletions test/travis_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ defmodule ExCoveralls.TravisTest do
assert(json =~ ~r/service_name/)
assert(json =~ ~r/source_files/)
end

test "submits as `travis-ci` by default" do
parsed = Travis.generate_json(@source_info) |> JSX.decode!
assert(%{ "service_name" => "travis-ci" } = parsed)
end

test "can be overriden to submit as `travis-pro`" do
parsed = Travis.generate_json(@source_info, %{ pro: true, another_key: 3 }) |> JSX.decode!
assert(%{ "service_name" => "travis-pro" } = parsed)
assert("repo_token" in Map.keys(parsed))
end
end