Skip to content

Commit

Permalink
Merge pull request #13 from buildkite/pie-1354-add-collector-name-and…
Browse files Browse the repository at this point in the history
…-version-to-elixir

PIE-1354: Add collector and version to Analytics API payload
  • Loading branch information
KatieWright26 authored Jan 12, 2023
2 parents e1fd6f3 + cc0254d commit 94bb939
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 4 deletions.
9 changes: 9 additions & 0 deletions lib/buildkite_test_collector/ci_env.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ defmodule BuildkiteTestCollector.CiEnv do
"""
@callback message() :: nil | String.t()

@doc """
Name of test collector
"""
@callback collector() :: String.t()
@doc """
Version of test collector
"""
@callback version() :: String.t()

@optional_callbacks url: 0, branch: 0, commit_sha: 0, number: 0, job_id: 0, message: 0

@doc """
Expand Down
6 changes: 6 additions & 0 deletions lib/buildkite_test_collector/ci_env/buildkite.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ defmodule BuildkiteTestCollector.CiEnv.Buildkite do

@impl true
def message, do: System.get_env("BUILDKITE_MESSAGE")

@impl true
def collector, do: BuildkiteTestCollector.MixProject.collector_name()

@impl true
def version, do: BuildkiteTestCollector.MixProject.version()
end
6 changes: 6 additions & 0 deletions lib/buildkite_test_collector/ci_env/circle_ci.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ defmodule BuildkiteTestCollector.CiEnv.CircleCi do

@impl true
def number, do: System.get_env("CIRCLE_BUILD_NUM")

@impl true
def collector, do: BuildkiteTestCollector.MixProject.collector_name()

@impl true
def version, do: BuildkiteTestCollector.MixProject.version()
end
6 changes: 6 additions & 0 deletions lib/buildkite_test_collector/ci_env/generic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ defmodule BuildkiteTestCollector.CiEnv.Generic do

@impl true
def key, do: Ecto.UUID.generate()

@impl true
def collector, do: BuildkiteTestCollector.MixProject.collector_name()

@impl true
def version, do: BuildkiteTestCollector.MixProject.version()
end
6 changes: 6 additions & 0 deletions lib/buildkite_test_collector/ci_env/github_actions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ defmodule BuildkiteTestCollector.CiEnv.GithubActions do

@impl true
def number, do: System.get_env("GITHUB_RUN_NUMBER")

@impl true
def collector, do: BuildkiteTestCollector.MixProject.collector_name()

@impl true
def version, do: BuildkiteTestCollector.MixProject.version()
end
6 changes: 6 additions & 0 deletions lib/buildkite_test_collector/ci_env/local.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ defmodule BuildkiteTestCollector.CiEnv.Local do

@impl true
def key, do: Ecto.UUID.generate()

@impl true
def collector, do: BuildkiteTestCollector.MixProject.collector_name()

@impl true
def version, do: BuildkiteTestCollector.MixProject.version()
end
6 changes: 4 additions & 2 deletions lib/buildkite_test_collector/payload.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ defmodule BuildkiteTestCollector.Payload do
optional(:branch) => String.t(),
optional(:commit_sha) => String.t(),
optional(:message) => String.t(),
optional(:url) => String.t()
optional(:url) => String.t(),
required(:collector) => String.t(),
required(:version) => String.t()
}

@doc """
Expand Down Expand Up @@ -52,7 +54,7 @@ defmodule BuildkiteTestCollector.Payload do
def set_start_time(%Payload{} = payload, started_at), do: %{payload | started_at: started_at}

defp serialise_env(ci_env_mod) do
~w[CI key number job_id branch commit_sha message url]a
~w[CI key number job_id branch commit_sha message url collector version]a
|> Enum.reduce(%{}, fn
:CI, env -> Map.put(env, :CI, ci_env_mod.ci())
key, env -> Map.put(env, key, apply(ci_env_mod, key, []))
Expand Down
7 changes: 5 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ defmodule BuildkiteTestCollector.MixProject do
use Mix.Project
@moduledoc false

@version "0.2.0"
@version "0.2.2"
def version, do: @version
@collector_name :buildkite_test_collector
def collector_name, do: "elixir-#{@collector_name}"

def project do
[
app: :buildkite_test_collector,
app: @collector_name,
description: "Official Buildkite Test Analytics Collector",
version: @version,
elixir: "~> 1.13",
Expand Down
2 changes: 2 additions & 0 deletions test/buildkite_test_collector/payload_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ defmodule BuildkiteTestCollector.PayloadTest do
assert run_env.message == env["BUILDKITE_MESSAGE"]
assert run_env.url =~ "http"
assert run_env.url =~ env["BUILDKITE_BUILD_ID"]
assert run_env.collector == BuildkiteTestCollector.MixProject.collector_name()
assert run_env.version == BuildkiteTestCollector.MixProject.version()
end

test "it initialises with empty data" do
Expand Down

0 comments on commit 94bb939

Please sign in to comment.