# `Pipette.Context`
[🔗](https://github.com/tommeier/pipette-buildkite-plugin/blob/main/lib/pipette/context.ex#L1)

Runtime context built from Buildkite environment variables.

Captures the CI environment (branch, commit, PR info) into a struct
that other modules use for decision-making.

## Fields

  * `:branch` — current branch name (`BUILDKITE_BRANCH`)
  * `:default_branch` — pipeline default branch (`BUILDKITE_PIPELINE_DEFAULT_BRANCH`, defaults to `"main"`)
  * `:commit` — current commit SHA (`BUILDKITE_COMMIT`)
  * `:message` — commit message (`BUILDKITE_MESSAGE`)
  * `:pull_request_base_branch` — PR base branch, if any (`BUILDKITE_PULL_REQUEST_BASE_BRANCH`)
  * `:ci_target` — explicit targeting via env var (`CI_TARGET`)
  * `:is_default_branch` — `true` when `:branch` equals `:default_branch`

## Example

    ctx = Pipette.Context.from_env(%{
      "BUILDKITE_BRANCH" => "feature/login",
      "BUILDKITE_PIPELINE_DEFAULT_BRANCH" => "main",
      "BUILDKITE_COMMIT" => "abc123",
      "BUILDKITE_MESSAGE" => "[ci:api] Fix login bug",
      "BUILDKITE_PULL_REQUEST_BASE_BRANCH" => "main"
    })

    ctx.branch             #=> "feature/login"
    ctx.is_default_branch  #=> false

# `t`

```elixir
@type t() :: %Pipette.Context{
  branch: String.t(),
  ci_target: String.t() | nil,
  commit: String.t(),
  default_branch: String.t(),
  is_default_branch: boolean(),
  message: String.t(),
  pull_request_base_branch: String.t() | nil
}
```

# `from_env`

```elixir
@spec from_env(%{required(String.t()) =&gt; String.t()}) :: t()
```

Build a context from a map of environment variables.

This is the primary constructor. In tests, pass a map with the
Buildkite environment variables you want to simulate.

## Examples

    ctx = Pipette.Context.from_env(%{
      "BUILDKITE_BRANCH" => "feature/login",
      "BUILDKITE_PIPELINE_DEFAULT_BRANCH" => "main",
      "BUILDKITE_COMMIT" => "abc123",
      "BUILDKITE_MESSAGE" => "Fix login"
    })

    ctx.branch  #=> "feature/login"

# `from_system_env`

```elixir
@spec from_system_env() :: t()
```

Build a context from the current system environment.

Convenience wrapper that calls `from_env(System.get_env())`.
Used in production when running inside a Buildkite agent.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
