1.7 KiB · text 5af55d9
defmodule GitGud.Workflows.CommitStatus do
@moduledoc """
Per-commit CI / build status — one row per `(repository, sha, context)`.
`state` is the GitHub-Actions-flavored summary:
* `pending` — the run is queued or running
* `success` — all jobs in the run finished with `success`/`skipped`
* `failure` — at least one job ended in `failure`/`cancelled`
* `error` — internal error (server-side; not produced by runs today)
`context` identifies the provider; we use `gitgud-actions/<workflow>`
per workflow so multiple workflows on the same SHA stack instead of
overwriting one another.
`target_url` links to the workflow run view in the UI.
Persisted by `Workflows.update_run_commit_status/1` on every
WorkflowRun status transition.
"""
use Ecto.Schema
import Ecto.Changeset
alias GitGud.Repositories.Repository
@valid_states ~w(pending success failure error)
schema "commit_statuses" do
field :sha, :binary
field :context, :string
field :state, :string
field :description, :string
field :target_url, :string
belongs_to :repository, Repository
timestamps(type: :utc_datetime)
end
def changeset(status, attrs) do
status
|> cast(attrs, [:sha, :context, :state, :description, :target_url, :repository_id])
|> validate_required([:sha, :context, :state, :repository_id])
|> validate_inclusion(:state, @valid_states)
|> validate_length(:context, max: 255)
|> validate_length(:description, max: 512)
|> validate_length(:target_url, max: 1024)
|> unique_constraint([:repository_id, :sha, :context],
name: :commit_statuses_repository_id_sha_context_index
)
end
def valid_states, do: @valid_states
end