pontil/context

Context for GitHub Actions using pontil.

This provides the Context type built from the GitHub Actions runtime environment, similar to the context object provided by @actions/github. It also provides webhook payload event loading and conversion, similar to the values in the context.payload field.

Basic usage

let ctx = context.new()
use pr <- result.try(context.load_event(
  event_name: ctx.event_name,
  converter: context.event_to_pull_request,
))
let base_sha = pr.pull_request.base.sha
let head_sha = pr.pull_request.head.sha

Context

The new function initializes the context from the GitHub Actions runtime environment. Values missing from or malformed in the runtime environment are set to empty strings (""), zero (0), or None as appropriate. The context repo field may be updated with set_context_repo_from_event.

Event type checking

The action’s event type may be tested in the context with is_ functions (is_push, is_issues, is_pull_request, etc.).

Event Data (Webhook Payload)

The event function reads and parses the event webhook payload as a Dict(String, Dynamic) value from the JSON file at GITHUB_EVENT_PATH. The load_event convenience function combines event with a converter in one step.

Event conversion

The raw payload can be converted to typed event data with the event_to_ conversion functions (event_to_pull_request, event_to_issues, etc.). Each takes an event_name string and the raw event data, returning Error(InvalidEventConversion) if the event name doesn’t match.

Converted event types (PullRequestEvent, DeleteEvent, etc.) contain event-level fields (action, sender, repository) and may contain a detail field (pull_request: PullRequest) with nested data.

Detailed Repository

get_repository decodes a rich Repository from any event’s repository field, which contains more information than is provided by the Context.repo field.

Raw field access

Every event record and its decoded member records includes a raw field (Dict(String, Dynamic)) with all original fields, including those not previously retrieved. Data can be retrieved with the get_ functions (get_string, get_int, get_bool_at, etc.). These can be used to get fields that have not been included in the typed records.

Types

A branch in a repository. Used to represent the head and base branches of a pull request.

pub type Branch {
  Branch(
    sha: String,
    ref: String,
    label: String,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • Branch(
      sha: String,
      ref: String,
      label: String,
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    sha

    The commit SHA at the tip of this branch.

    ref

    The branch ref (e.g., "main" or "fix-branch").

    label

    The label (e.g., "owner:main").

A commit. This is primarily used in push events.

pub type Commit {
  Commit(
    id: String,
    message: String,
    timestamp: String,
    author: GitUser,
    committer: GitUser,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • Commit(
      id: String,
      message: String,
      timestamp: String,
      author: GitUser,
      committer: GitUser,
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    id

    The commit SHA.

    message

    The commit message.

    timestamp

    The ISO 8601 timestamp.

    author

    The commit author.

    committer

    The commit committer.

The GitHub Actions execution context, hydrated from environment variables.

pub type Context {
  Context(
    action: String,
    actor: String,
    api_url: String,
    event_name: String,
    graphql_url: String,
    job: String,
    ref: String,
    repo: option.Option(Repo),
    run_attempt: Int,
    run_id: Int,
    run_number: Int,
    server_url: String,
    sha: String,
    workflow: String,
  )
}

Constructors

  • Context(
      action: String,
      actor: String,
      api_url: String,
      event_name: String,
      graphql_url: String,
      job: String,
      ref: String,
      repo: option.Option(Repo),
      run_attempt: Int,
      run_id: Int,
      run_number: Int,
      server_url: String,
      sha: String,
      workflow: String,
    )

    Arguments

    action

    The name of the action (GITHUB_ACTION).

    actor

    The name of the actor that triggered this event (GITHUB_ACTOR).

    api_url

    The GitHub API URL (GITHUB_API_URL, default https://api.github.com).

    event_name

    The name of the event (GITHUB_EVENT_NAME).

    graphql_url

    The GitHub GraphQL API URL (GITHUB_GRAPHQL_URL, default https://api.github.com/graphql).

    job

    The name of the job running the action (GITHUB_JOB).

    ref

    The ref name (branch, etc.) for this run (GITHUB_REF).

    repo

    The repo for this execution context, derived from GITHUB_REPOSITORY or may be replaced with event_to_repository..

    run_attempt

    The current run attempt (GITHUB_RUN_ATTEMPT).

    run_id

    The current run ID (GITHUB_RUN_ID).

    run_number

    The current run number (GITHUB_RUN_NUMBER).

    server_url

    The GitHub server URL (GITHUB_SERVER_URL, default https://github.com).

    sha

    The SHA for the commit associated with this run (GITHUB_SHA).

    workflow

    The name of the workflow file (GITHUB_WORKFLOW).

A create webhook event (branch or tag created).

pub type CreateEvent {
  CreateEvent(
    ref: String,
    ref_type: String,
    master_branch: String,
    description: option.Option(String),
    repository: dict.Dict(String, dynamic.Dynamic),
    sender: GitHubUserLite,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • CreateEvent(
      ref: String,
      ref_type: String,
      master_branch: String,
      description: option.Option(String),
      repository: dict.Dict(String, dynamic.Dynamic),
      sender: GitHubUserLite,
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    ref

    The git ref (branch or tag name).

    ref_type

    The type of ref: "branch" or "tag".

    master_branch

    The name of the default branch.

    description

    The repository description.

    repository

    The repository where the event occurred.

    sender

    The user that triggered the event.

A delete webhook event (branch or tag deleted).

pub type DeleteEvent {
  DeleteEvent(
    ref: String,
    ref_type: String,
    repository: dict.Dict(String, dynamic.Dynamic),
    sender: GitHubUserLite,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • DeleteEvent(
      ref: String,
      ref_type: String,
      repository: dict.Dict(String, dynamic.Dynamic),
      sender: GitHubUserLite,
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    ref

    The git ref (branch or tag name).

    ref_type

    The type of ref: "branch" or "tag".

    repository

    The repository where the event occurred.

    sender

    The user that triggered the event.

Deployment detail from the deployment key in the event data.

pub type Deployment {
  Deployment(
    id: Int,
    ref: String,
    sha: String,
    environment: String,
    description: option.Option(String),
    creator: option.Option(GitHubUserLite),
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • Deployment(
      id: Int,
      ref: String,
      sha: String,
      environment: String,
      description: option.Option(String),
      creator: option.Option(GitHubUserLite),
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    id

    The deployment ID.

    ref

    The ref that was deployed.

    sha

    The commit SHA that was deployed.

    environment

    The environment name.

    description

    The deployment description.

    creator

    The user who triggered the deployment.

A deployment webhook event.

pub type DeploymentEvent {
  DeploymentEvent(
    action: String,
    deployment: Deployment,
    repository: dict.Dict(String, dynamic.Dynamic),
    sender: GitHubUserLite,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

A lightweight GitHub user account with just the login.

pub type GitHubUserLite {
  GitHubUserLite(
    login: String,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

Git author/committer identity from commit metadata.

pub type GitUser {
  GitUser(
    name: option.Option(String),
    email: option.Option(String),
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

Issue detail from the issue key in the event data.

pub type Issue {
  Issue(
    number: Int,
    html_url: String,
    title: String,
    body: option.Option(String),
    state: IssueState,
    locked: Bool,
    user: option.Option(GitHubUserLite),
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • Issue(
      number: Int,
      html_url: String,
      title: String,
      body: option.Option(String),
      state: IssueState,
      locked: Bool,
      user: option.Option(GitHubUserLite),
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    number

    The issue number.

    html_url

    The URL to the issue in the GitHub interface.

    title

    The title of the issue.

    body

    The body of the issue.

    state

    The state of the issue. Not present in all webhook variants.

    locked

    Whether discussion on the issue has been locked to collaborators only.

    user

    The user that opened this issue.

Comment detail from the comment key in the event data.

pub type IssueComment {
  IssueComment(
    id: Int,
    body: String,
    user: option.Option(GitHubUserLite),
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

An issue_comment webhook event.

pub type IssueCommentEvent {
  IssueCommentEvent(
    action: String,
    comment: IssueComment,
    issue: Issue,
    repository: dict.Dict(String, dynamic.Dynamic),
    sender: GitHubUserLite,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • IssueCommentEvent(
      action: String,
      comment: IssueComment,
      issue: Issue,
      repository: dict.Dict(String, dynamic.Dynamic),
      sender: GitHubUserLite,
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    action

    The event action (e.g., "created", "edited", "deleted").

    comment

    The comment detail.

    issue

    The issue or pull request the comment belongs to.

    repository

    The repository where the event occurred.

    sender

    The user that triggered the event.

The state of an issue or pull request.

pub type IssueState {
  Open
  Closed
}

Constructors

  • Open
  • Closed

An issues webhook event.

pub type IssuesEvent {
  IssuesEvent(
    action: String,
    issue: Issue,
    repository: dict.Dict(String, dynamic.Dynamic),
    sender: GitHubUserLite,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • IssuesEvent(
      action: String,
      issue: Issue,
      repository: dict.Dict(String, dynamic.Dynamic),
      sender: GitHubUserLite,
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    action

    The event action (e.g., "opened", "edited", "closed").

    issue

    The issue detail.

    repository

    The repository where the event occurred.

    sender

    The user that triggered the event.

Errors returned by pontil/context functions.

pub type PontilContextError {
  MissingEventPath
  MissingEventField(field: String, event_name: String)
  InvalidEventConversion(expected: String, provided: String)
  EventParseError(json.DecodeError)
  EventReadError(simplifile.FileError)
  RawObjectKeyMissing(key: String)
  RawObjectInvalidType(key: String, expected: String)
}

Constructors

  • MissingEventPath

    The event data file cannot be loaded because GITHUB_EVENT_PATH is unset.

  • MissingEventField(field: String, event_name: String)

    A required field is missing from the webhook event data.

  • InvalidEventConversion(expected: String, provided: String)

    The event data could not be converted to the requested type.

  • EventParseError(json.DecodeError)

    The webhook event data could not be parsed as JSON.

  • EventReadError(simplifile.FileError)

    The event data file could not be read.

  • RawObjectKeyMissing(key: String)

    A key was not found in a RawObject.

  • RawObjectInvalidType(key: String, expected: String)

    A key was found in a RawObject but the value is not the expected type.

Pull request detail from the pull_request key in the event data.

pub type PullRequest {
  PullRequest(
    number: Int,
    html_url: String,
    title: String,
    body: option.Option(String),
    state: IssueState,
    merged: option.Option(Bool),
    draft: Bool,
    locked: Bool,
    merge_commit_sha: option.Option(String),
    base: Branch,
    head: Branch,
    user: option.Option(GitHubUserLite),
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • PullRequest(
      number: Int,
      html_url: String,
      title: String,
      body: option.Option(String),
      state: IssueState,
      merged: option.Option(Bool),
      draft: Bool,
      locked: Bool,
      merge_commit_sha: option.Option(String),
      base: Branch,
      head: Branch,
      user: option.Option(GitHubUserLite),
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    number

    The pull request number.

    html_url

    The URl to the pull request in the GitHub interface.

    title

    The title of the pull request.

    body

    The body of the pull request.

    state

    The state of the pull request.

    merged

    Whether the pull request has been merged.

    draft

    Whether the pull request is a draft pull request.

    locked

    Whether discussion on the pull request has been locked to collaborators only.

    merge_commit_sha

    The SHA for the commit when this pull request has been merged. Before merging, this holds the SHA of the test merge commit.

    • If merged as a merge commit, merge_commit_sha represents the SHA of the merge commit.
    • If merged via a squash, merge_commit_sha represents the SHA of the squashed commit on the base branch.
    • If rebased, merge_commit_sha represents the commit that the base branch was updated to.
    base

    The base branch for the pull request.

    head

    The head branch for the pull request.

    user

    The user that opened this pull request.

A pull_request or pull_request_target webhook event.

pub type PullRequestEvent {
  PullRequestEvent(
    action: String,
    number: Int,
    pull_request: PullRequest,
    repository: dict.Dict(String, dynamic.Dynamic),
    sender: GitHubUserLite,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • PullRequestEvent(
      action: String,
      number: Int,
      pull_request: PullRequest,
      repository: dict.Dict(String, dynamic.Dynamic),
      sender: GitHubUserLite,
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    action

    The event action (e.g., "opened", "closed", "synchronize").

    number

    The pull request number (top-level event field).

    pull_request

    The pull request detail.

    repository

    The repository where the event occurred.

    sender

    The user that triggered the event.

A push webhook event.

pub type PushEvent {
  PushEvent(
    ref: String,
    before: String,
    after: String,
    created: Bool,
    deleted: Bool,
    forced: Bool,
    base_ref: option.Option(String),
    compare: String,
    commits: List(Commit),
    head_commit: option.Option(Commit),
    pusher: GitUser,
    repository: dict.Dict(String, dynamic.Dynamic),
    sender: GitHubUserLite,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • PushEvent(
      ref: String,
      before: String,
      after: String,
      created: Bool,
      deleted: Bool,
      forced: Bool,
      base_ref: option.Option(String),
      compare: String,
      commits: List(Commit),
      head_commit: option.Option(Commit),
      pusher: GitUser,
      repository: dict.Dict(String, dynamic.Dynamic),
      sender: GitHubUserLite,
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    ref

    The full git ref that was pushed (e.g., "refs/heads/main").

    before

    The SHA of the most recent commit on ref before the push.

    after

    The SHA of the most recent commit on ref after the push.

    created

    Whether this push created the ref.

    deleted

    Whether this push deleted the ref.

    forced

    Whether this push was a force push.

    base_ref

    The base ref, if applicable. Required but nullable.

    compare

    URL showing the changes in this push.

    commits

    The pushed commits. Includes a maximum of 2048 commits.

    head_commit

    The tip commit of the push. Null when a branch is deleted.

    pusher

    The user who pushed (git identity with name and email).

    repository

    The repository where the event occurred.

    sender

    The user that triggered the event.

The raw representation of a JSON object from the webhook event data.

This is a Dict(String, Dynamic) containing all fields from the original JSON object or sub-object. Use get_string, get_int, get_bool, get_object, and related helpers to extract values:

// Single field
context.get_string(pr.raw, "mergeable_state")
// -> Ok("clean")

// Nested path
context.get_string_at(payload, ["pull_request", "user", "login"])
// -> Ok("octocat")

// List of objects
context.get_object_list(issue.raw, "labels")
|> result.unwrap([])
|> list.filter_map(fn(label) { context.get_string(label, "name") })
// -> ["bug", "help wanted"]
pub type RawObject =
  dict.Dict(String, dynamic.Dynamic)

Release detail from the release key in the event data.

pub type Release {
  Release(
    tag_name: String,
    target_commitish: String,
    name: option.Option(String),
    draft: Bool,
    prerelease: Bool,
    body: option.Option(String),
    author: option.Option(GitHubUserLite),
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • Release(
      tag_name: String,
      target_commitish: String,
      name: option.Option(String),
      draft: Bool,
      prerelease: Bool,
      body: option.Option(String),
      author: option.Option(GitHubUserLite),
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    tag_name

    The git tag name (e.g., "v1.0.0").

    target_commitish

    The branch, tag, or SHA the release targets.

    name

    The release name.

    draft

    Whether this is a draft release.

    prerelease

    Whether this is a pre-release.

    body

    The release body/notes in markdown.

    author

    The release author.

A release webhook event.

pub type ReleaseEvent {
  ReleaseEvent(
    action: String,
    release: Release,
    repository: dict.Dict(String, dynamic.Dynamic),
    sender: GitHubUserLite,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • ReleaseEvent(
      action: String,
      release: Release,
      repository: dict.Dict(String, dynamic.Dynamic),
      sender: GitHubUserLite,
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    action

    The event action (e.g., "published", "created", "edited").

    release

    The release detail.

    repository

    The repository where the event occurred.

    sender

    The user that triggered the event.

A simplified repository representation parsed from GITHUB_REPOSITORY.

pub type Repo {
  Repo(full_name: String, name: String, owner: String)
}

Constructors

  • Repo(full_name: String, name: String, owner: String)

    Arguments

    full_name

    The full name of the repository ("halostatue/pontil").

    name

    The name of the repository ("pontil").

    owner

    The name of the repository owner ("owner").

Repository decoded from the webhook event’s repository field.

pub type Repository {
  Repository(
    id: Int,
    name: String,
    full_name: String,
    owner: GitHubUserLite,
    private: Bool,
    html_url: String,
    description: option.Option(String),
    fork: Bool,
    default_branch: String,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • Repository(
      id: Int,
      name: String,
      full_name: String,
      owner: GitHubUserLite,
      private: Bool,
      html_url: String,
      description: option.Option(String),
      fork: Bool,
      default_branch: String,
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    id

    The unique identifier of the repository.

    name

    The name of the repository.

    full_name

    The full name of the repository ("owner/repo").

    owner

    The owner of the repository.

    private

    Whether the repository is private.

    html_url

    The URL to the repository in the GitHub interface.

    description

    The description of the repository.

    fork

    Whether the repository is a fork.

    default_branch

    The default branch of the repository.

A status webhook event (commit status update).

pub type StatusEvent {
  StatusEvent(
    sha: String,
    state: String,
    context: String,
    description: option.Option(String),
    target_url: option.Option(String),
    repository: dict.Dict(String, dynamic.Dynamic),
    sender: GitHubUserLite,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • StatusEvent(
      sha: String,
      state: String,
      context: String,
      description: option.Option(String),
      target_url: option.Option(String),
      repository: dict.Dict(String, dynamic.Dynamic),
      sender: GitHubUserLite,
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    sha

    The commit SHA.

    state

    The status state: "pending", "success", "failure", or "error".

    context

    The status context (e.g., CI system name).

    description

    The status description.

    target_url

    The target URL for the status.

    repository

    The repository where the event occurred.

    sender

    The user that triggered the event.

Workflow run detail from the workflow_run key in the event data.

pub type WorkflowRun {
  WorkflowRun(
    id: Int,
    name: option.Option(String),
    head_branch: option.Option(String),
    head_sha: String,
    status: String,
    conclusion: option.Option(String),
    event: String,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • WorkflowRun(
      id: Int,
      name: option.Option(String),
      head_branch: option.Option(String),
      head_sha: String,
      status: String,
      conclusion: option.Option(String),
      event: String,
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    id

    The workflow run ID.

    name

    The workflow name.

    head_branch

    The head branch.

    head_sha

    The head SHA.

    status

    The current status: "queued", "in_progress", or "completed".

    conclusion

    The conclusion, if completed: "success", "failure", "cancelled", etc.

    event

    The event that triggered this workflow.

A workflow_run webhook event.

pub type WorkflowRunEvent {
  WorkflowRunEvent(
    action: String,
    workflow_run: WorkflowRun,
    repository: dict.Dict(String, dynamic.Dynamic),
    sender: GitHubUserLite,
    raw: dict.Dict(String, dynamic.Dynamic),
  )
}

Constructors

  • WorkflowRunEvent(
      action: String,
      workflow_run: WorkflowRun,
      repository: dict.Dict(String, dynamic.Dynamic),
      sender: GitHubUserLite,
      raw: dict.Dict(String, dynamic.Dynamic),
    )

    Arguments

    action

    The event action (e.g., "requested", "completed").

    workflow_run

    The workflow run detail.

    repository

    The repository where the event occurred.

    sender

    The user that triggered the event.

Values

pub fn describe_error(error: PontilContextError) -> String

Returns a human-readable description of a pontil/context error.

pub fn event() -> Result(
  dict.Dict(String, dynamic.Dynamic),
  PontilContextError,
)

Load and parse the webhook event data from GITHUB_EVENT_PATH.

Event should be created once and passed to functions that require it.

Converting the raw event to a typed event as soon as practical is recommended, if the conversion exists.

pub fn event_to_create(
  event_name event_name: String,
  event event_data: dict.Dict(String, dynamic.Dynamic),
) -> Result(CreateEvent, PontilContextError)

Convert event data to a CreateEvent.

let ctx = context.new()
use event <- result.try(context.event())
use create <- context.event_to_create(ctx.event_name, event)
pub fn event_to_delete(
  event_name event_name: String,
  event event_data: dict.Dict(String, dynamic.Dynamic),
) -> Result(DeleteEvent, PontilContextError)

Convert event data to a DeleteEvent.

let ctx = context.new()
use event <- result.try(context.event())
use delete <- context.event_to_delete(ctx.event_name, event)
pub fn event_to_deployment(
  event_name event_name: String,
  event event_data: dict.Dict(String, dynamic.Dynamic),
) -> Result(DeploymentEvent, PontilContextError)

Convert event data to a DeploymentEvent.

let ctx = context.new()
use event <- result.try(context.event())
use deployment <- context.event_to_deployment(ctx.event_name, event)
pub fn event_to_issue_comment(
  event_name event_name: String,
  event event_data: dict.Dict(String, dynamic.Dynamic),
) -> Result(IssueCommentEvent, PontilContextError)

Convert event data to an IssueCommentEvent.

let ctx = context.new()
use event <- result.try(context.event())
use issue_comment <- context.event_to_issue_comment(ctx.event_name, event)
pub fn event_to_issues(
  event_name event_name: String,
  event event_data: dict.Dict(String, dynamic.Dynamic),
) -> Result(IssuesEvent, PontilContextError)

Convert event data to an IssuesEvent.

let ctx = context.new()
use event <- result.try(context.event())
use issue <- context.event_to_issues(ctx.event_name, event)
pub fn event_to_pull_request(
  event_name event_name: String,
  event event_data: dict.Dict(String, dynamic.Dynamic),
) -> Result(PullRequestEvent, PontilContextError)

Convert event data to a PullRequestEvent.

let ctx = context.new()
use event <- result.try(context.event())
use pr <- context.event_to_pull_request(ctx.event_name, event)

Works for both pull_request and pull_request_target events.

pub fn event_to_push(
  event_name event_name: String,
  event event_data: dict.Dict(String, dynamic.Dynamic),
) -> Result(PushEvent, PontilContextError)

Convert event data to a PushEvent.

let ctx = context.new()
use event <- result.try(context.event())
use push <- context.event_to_push(ctx.event_name, event)
pub fn event_to_release(
  event_name event_name: String,
  event event_data: dict.Dict(String, dynamic.Dynamic),
) -> Result(ReleaseEvent, PontilContextError)

Convert event data to a ReleaseEvent.

let ctx = context.new()
use event <- result.try(context.event())
use release <- context.event_to_release(ctx.event_name, event)
pub fn event_to_status(
  event_name event_name: String,
  event event_data: dict.Dict(String, dynamic.Dynamic),
) -> Result(StatusEvent, PontilContextError)

Convert event data to a StatusEvent.

let ctx = context.new()
use event <- result.try(context.event())
use status <- context.event_to_status(ctx.event_name, event)
pub fn event_to_workflow_run(
  event_name event_name: String,
  event event_data: dict.Dict(String, dynamic.Dynamic),
) -> Result(WorkflowRunEvent, PontilContextError)

Convert event data to a WorkflowRunEvent.

let ctx = context.new()
use event <- result.try(context.event())
use workflow_run <- context.event_to_workflow_run(ctx.event_name, event)
pub fn get_bool(
  raw raw: dict.Dict(String, dynamic.Dynamic),
  key key: String,
) -> Result(Bool, PontilContextError)

Get a bool value from a RawObject by key.

pub fn get_bool_at(
  raw raw: dict.Dict(String, dynamic.Dynamic),
  path path: List(String),
) -> Result(Bool, PontilContextError)

Get a bool value at path within a RawObject.

pub fn get_int(
  raw raw: dict.Dict(String, dynamic.Dynamic),
  key key: String,
) -> Result(Int, PontilContextError)

Get an int value from a RawObject by key.

pub fn get_int_at(
  raw raw: dict.Dict(String, dynamic.Dynamic),
  path path: List(String),
) -> Result(Int, PontilContextError)

Get an int value at path within a RawObject.

pub fn get_list(
  raw raw: dict.Dict(String, dynamic.Dynamic),
  key key: String,
) -> Result(List(dynamic.Dynamic), PontilContextError)

Get a Dynamic list from a RawObject by key.

pub fn get_object(
  raw raw: dict.Dict(String, dynamic.Dynamic),
  key key: String,
) -> Result(
  dict.Dict(String, dynamic.Dynamic),
  PontilContextError,
)

Get a nested object from a RawObject by key.

pub fn get_object_at(
  raw raw: dict.Dict(String, dynamic.Dynamic),
  path path: List(String),
) -> Result(
  dict.Dict(String, dynamic.Dynamic),
  PontilContextError,
)

Get a nested object at path within a RawObject.

pub fn get_object_list(
  raw raw: dict.Dict(String, dynamic.Dynamic),
  key key: String,
) -> Result(
  List(dict.Dict(String, dynamic.Dynamic)),
  PontilContextError,
)

Get a list of objects from a RawObject by key.

pub fn get_string(
  raw raw: dict.Dict(String, dynamic.Dynamic),
  key key: String,
) -> Result(String, PontilContextError)

Get a string value from a RawObject by key.

pub fn get_string_at(
  raw raw: dict.Dict(String, dynamic.Dynamic),
  path path: List(String),
) -> Result(String, PontilContextError)

Get a string value at path within a RawObject.

pub fn get_string_list(
  raw raw: dict.Dict(String, dynamic.Dynamic),
  key key: String,
) -> Result(List(String), PontilContextError)

Get a list of strings from a RawObject by key.

pub fn is_create(ctx: Context) -> Bool

Returns True if this is a create event.

pub fn is_delete(ctx: Context) -> Bool

Returns True if this is a delete event.

pub fn is_deployment(ctx: Context) -> Bool

Returns True if this is a deployment event.

pub fn is_issue_comment(ctx: Context) -> Bool

Returns True if this is an issue_comment event.

pub fn is_issues(ctx: Context) -> Bool

Returns True if this is an issues event.

pub fn is_pull_request(ctx: Context) -> Bool

Returns True if this is a pull_request event.

pub fn is_pull_request_target(ctx: Context) -> Bool

Returns True if this is a pull_request_target event.

pub fn is_push(ctx: Context) -> Bool

Returns True if this is a push event.

pub fn is_release(ctx: Context) -> Bool

Returns True if this is a release event.

pub fn is_status(ctx: Context) -> Bool

Returns True if this is a status event.

pub fn is_workflow_dispatch(ctx: Context) -> Bool

Returns True if this is a workflow_dispatch event.

pub fn is_workflow_run(ctx: Context) -> Bool

Returns True if this is a workflow_run event.

pub fn load_event(
  event_name event_name: String,
  converter converter: fn(
    String,
    dict.Dict(String, dynamic.Dynamic),
  ) -> Result(a, PontilContextError),
) -> Result(a, PontilContextError)

Load, parse, and convert the webhook event in one step.

Reads the event file from GITHUB_EVENT_PATH and converts it to the typed event type withe provided converter function.

let ctx = context.new()
use pr <- result.try(context.load_event(
  event_name: ctx.event_name,
  converter: context.event_to_pull_request,
))

// Equivalent to:
use event <- result.try(context.event())
use pr <- result.try(context.event_to_pull_request(ctx.event_name, event))
pub fn new() -> Context

Return a Context from the runtime environment.

Context should be created once and passed to functions that require it.

pub fn raw_to_repository(
  raw: dict.Dict(String, dynamic.Dynamic),
) -> Result(Repository, PontilContextError)

Convert a RawObject into a Repository (usually found in an event’s repository field).

// From raw event data
use ev <- result.try(context.event())
use repo <- result.try(context.get_object(ev, "repository"))
use repo <- result.try(context.raw_to_repository(repo))

// From a typed event
use pr <- result.try(
  context.load_event("pull_request", context.event_to_pull_request)
)
use repo <- result.try(context.raw_to_repository(pr.repository))
pub fn set_context_repo_from_event(
  context ctx: Context,
  event event_data: dict.Dict(String, dynamic.Dynamic),
) -> Context

Sets Context.repo from the webhook event’s repository object.

Returns the context unchanged if the event data does not contain a valid repository object.

Search Document