Repository: parroty/excoveralls (elixir)

Issue:
Semaphore CI 2.0 uses different CI environment variables
The current Semaphore task supports only Semaphore's "classic" CI environment, whereas in 2.0 they changed up the environment variables:

https://docs.semaphoreci.com/article/12-environment-variables

`REVISION` -> `SEMAPHORE_GIT_SHA`
`BRANCH_NAME` -> `SEMAPHORE_GIT_BRANCH `
`SEMAPHORE_BUILD_NUMBER` -> `SEMAPHORE_JOB_ID `

I'm not sure if `PULL_REQUEST_NUMBER` hash changed or not, though—the documentation doesn't mention it at all.

Pull request description:
Updated Semaphore variables
This should fix #179.

This is a breaking change for people who haven't migrated to the new Semaphore.

Patch:
diff --git a/lib/excoveralls/semaphore.ex b/lib/excoveralls/semaphore.ex
index 2765ce6..5854efb 100644
--- a/lib/excoveralls/semaphore.ex
+++ b/lib/excoveralls/semaphore.ex
@@ -36,7 +36,7 @@ defmodule ExCoveralls.Semaphore do
   end
 
   defp get_pull_request do
-    case Regex.run(~r/(\d+)$/, System.get_env("PULL_REQUEST_NUMBER") || "") do
+    case Regex.run(~r/(\d+)$/, System.get_env("SEMAPHORE_GIT_PR_NUMBER") || "") do
       [_, id] -> id
       _ -> nil
     end
@@ -50,15 +50,15 @@ defmodule ExCoveralls.Semaphore do
   end
 
   defp get_sha do
-    System.get_env("REVISION")
+    System.get_env("SEMAPHORE_GIT_SHA")
   end
 
   defp get_branch do
-    System.get_env("BRANCH_NAME")
+    System.get_env("SEMAPHORE_GIT_BRANCH")
   end
 
   defp get_build_num do
-    System.get_env("SEMAPHORE_BUILD_NUMBER")
+    System.get_env("SEMAPHORE_JOB_ID")
   end
 
   defp get_repo_token do


Test patch:
diff --git a/test/semaphore_test.exs b/test/semaphore_test.exs
index 0462ed5..161674a 100644
--- a/test/semaphore_test.exs
+++ b/test/semaphore_test.exs
@@ -3,19 +3,17 @@ defmodule ExCoveralls.SemaphoreTest do
   import Mock
   alias ExCoveralls.Semaphore
 
-  @content     "defmodule Test do\n  def test do\n  end\nend\n"
-  @counts      [0, 1, nil, nil]
-  @source_info [%{name: "test/fixtures/test.ex",
-                 source: @content,
-                 coverage: @counts
-               }]
+  @content "defmodule Test do\n  def test do\n  end\nend\n"
+  @counts [0, 1, nil, nil]
+  @source_info [%{name: "test/fixtures/test.ex", source: @content, coverage: @counts}]
 
   setup do
     # Capture existing values
-    orig_vars = ~w(PULL_REQUEST_NUMBER REVISION BRANCH_NAME SEMAPHORE_BUILD_NUMBER COVERALLS_REPO_TOKEN)
-    |> Enum.map(fn var -> {var, System.get_env(var)} end)
+    orig_vars =
+      ~w(SEMAPHORE_GIT_PR_NUMBER SEMAPHORE_GIT_SHA SEMAPHORE_GIT_BRANCH SEMAPHORE_JOB_ID COVERALLS_REPO_TOKEN)
+      |> Enum.map(fn var -> {var, System.get_env(var)} end)
 
-    on_exit fn ->
+    on_exit(fn ->
       # Reset env vars
       for {k, v} <- orig_vars do
         if v != nil do
@@ -24,14 +22,14 @@ defmodule ExCoveralls.SemaphoreTest do
           System.delete_env(k)
         end
       end
-    end
+    end)
 
     # No additional context
     {:ok, []}
   end
 
-  test_with_mock "execute", ExCoveralls.Poster, [execute: fn(_) -> "result" end] do
-    assert(Semaphore.execute(@source_info,[]) == "result")
+  test_with_mock "execute", ExCoveralls.Poster, execute: fn _ -> "result" end do
+    assert(Semaphore.execute(@source_info, []) == "result")
   end
 
   test "generate json for semaphore" do
@@ -44,21 +42,19 @@ defmodule ExCoveralls.SemaphoreTest do
   end
 
   test "submits as `semaphore-ci` by default" do
-    parsed = Semaphore.generate_json(@source_info) |> Jason.decode!
-    assert(%{ "service_name" => "semaphore" } = parsed)
+    parsed = Semaphore.generate_json(@source_info) |> Jason.decode!()
+    assert(%{"service_name" => "semaphore"} = parsed)
   end
 
   test "generate from env vars" do
-    System.put_env("PULL_REQUEST_NUMBER", "39")
-    System.put_env("REVISION", "sha1")
-    System.put_env("BRANCH_NAME", "branch")
-    System.put_env("SEMAPHORE_BUILD_NUMBER", "0")
+    System.put_env("SEMAPHORE_GIT_PR_NUMBER", "39")
+    System.put_env("SEMAPHORE_GIT_SHA", "sha1")
+    System.put_env("SEMAPHORE_GIT_BRANCH", "branch")
+    System.put_env("SEMAPHORE_JOB_ID", "0")
     System.put_env("COVERALLS_REPO_TOKEN", "token")
 
     {:ok, payload} = Jason.decode(Semaphore.generate_json(@source_info))
-    %{"git" =>
-      %{"branch" => branch,
-        "head" => %{ "id" => id}}} = payload
+    %{"git" => %{"branch" => branch, "head" => %{"id" => id}}} = payload
 
     assert(payload["service_pull_request"] == "39")
     assert(branch == "branch")
@@ -66,5 +62,4 @@ defmodule ExCoveralls.SemaphoreTest do
     assert(payload["service_number"] == "0")
     assert(payload["repo_token"] == "token")
   end
-
 end