Trebejo.GitHub (Trebejo v2.0.0)

Copy Markdown View Source

GitHub CLI wrapper around gh.

Covers the three highest-ROI subcommands used by agents and humans alike: pr, issue, release. For the full gh surface area, call Trebejo.GitHub.run/2 with any gh args.

Routes everything through Trebejo.Util.run_cmd/3 (via Trebejo.Runner) so it picks up :timeout, the circuit breaker, and Trebejo.Mox mocking.

Options (shared)

  • :repo — owner/repo (e.g. "Lorenzo-SF/arrea"). Defaults to the value of gh repo set-default if gh is logged in.
  • :cwd — run from this directory (where the local clone lives)
  • :timeout — passed through to the underlying runner
  • :breaker — circuit breaker name

Authentication

gh itself manages auth (gh auth login). Trebejo does not pass tokens — it relies on the gh CLI finding a valid session.

Examples

iex> Trebejo.GitHub.run(["pr", "list", "--state", "open"], repo: "Lorenzo-SF/arrea")
{:ok, "12\tMigrate to arrea 3.0\t...\n", 0}

Summary

Functions

Create an issue. Pass :title and :body (or :body-file).

List issues. Thin wrapper over gh issue list.

View a single issue. Thin wrapper over gh issue view.

Create a pull request. Thin wrapper over gh pr create.

List pull requests. Thin wrapper over gh pr list.

View a single PR (number, title, body, diff). Thin wrapper over gh pr view.

Create a release. Pass :tag (required) and optionally :title, :notes (or :notes-file), :target, :draft, :prerelease.

List releases. Thin wrapper over gh release list.

Generic gh invocation. Use this for subcommands not covered by the specialised helpers below.

Functions

issue_create(opts)

@spec issue_create(keyword()) :: {:ok, String.t(), 0} | {:error, Trebejo.Error.t()}

Create an issue. Pass :title and :body (or :body-file).

issue_list(args \\ [], opts \\ [])

@spec issue_list(
  [String.t()],
  keyword()
) :: {:ok, String.t(), 0} | {:error, Trebejo.Error.t()}

List issues. Thin wrapper over gh issue list.

issue_view(issue, opts \\ [])

@spec issue_view(
  String.t() | pos_integer(),
  keyword()
) :: {:ok, String.t(), 0} | {:error, Trebejo.Error.t()}

View a single issue. Thin wrapper over gh issue view.

pr_create(opts)

@spec pr_create(keyword()) :: {:ok, String.t(), 0} | {:error, Trebejo.Error.t()}

Create a pull request. Thin wrapper over gh pr create.

At minimum pass :title and :body; pass :base to target a specific branch.

pr_list(args \\ [], opts \\ [])

@spec pr_list(
  [String.t()],
  keyword()
) :: {:ok, String.t(), 0} | {:error, Trebejo.Error.t()}

List pull requests. Thin wrapper over gh pr list.

See https://cli.github.com/manual/gh_pr_list for the available flags you can pass in args.

pr_view(pr, opts \\ [])

@spec pr_view(
  String.t() | pos_integer(),
  keyword()
) :: {:ok, String.t(), 0} | {:error, Trebejo.Error.t()}

View a single PR (number, title, body, diff). Thin wrapper over gh pr view.

Pass :comments, :diff, or no extra arg for the default view.

release_create(opts)

@spec release_create(keyword()) :: {:ok, String.t(), 0} | {:error, Trebejo.Error.t()}

Create a release. Pass :tag (required) and optionally :title, :notes (or :notes-file), :target, :draft, :prerelease.

release_list(args \\ [], opts \\ [])

@spec release_list(
  [String.t()],
  keyword()
) :: {:ok, String.t(), 0} | {:error, Trebejo.Error.t()}

List releases. Thin wrapper over gh release list.

run(args, opts \\ [])

@spec run(
  [String.t()],
  keyword()
) :: {:ok, String.t(), 0} | {:error, Trebejo.Error.t()}

Generic gh invocation. Use this for subcommands not covered by the specialised helpers below.