Skip to content

Commit

Permalink
Merge pull request #37 from seomoz/support-travis-pro
Browse files Browse the repository at this point in the history
Support travis pro.
  • Loading branch information
parroty committed Jan 6, 2016
2 parents 47ebc74 + 83abe25 commit fbdfdef
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
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

0 comments on commit fbdfdef

Please sign in to comment.