GhEx.Contents (gh_ex v0.3.0)

Copy Markdown View Source

Convenience functions for the GitHub repository Contents REST API (reading and writing files).

Thin wrappers over GhEx.REST that return the same {:ok, body, meta} / {:error, reason} shape; opts pass through to Req. The write endpoints take the GitHub body as-is: content must be Base64-encoded, and an update needs the blob sha.

Summary

Functions

Creates or updates a file. attrs is the JSON body: message, content (Base64-encoded), sha (required when updating an existing file), and an optional branch.

Deletes a file. attrs is the JSON body: message, the blob sha, and an optional branch.

Gets the contents of a file or directory. Use params: [ref: "..."] to select a branch, tag, or commit.

Functions

create_or_update_file(client, owner, repo, path, attrs, opts \\ [])

@spec create_or_update_file(
  GhEx.Client.t(),
  String.t(),
  String.t(),
  String.t(),
  map(),
  keyword()
) ::
  GhEx.REST.result()

Creates or updates a file. attrs is the JSON body: message, content (Base64-encoded), sha (required when updating an existing file), and an optional branch.

delete_file(client, owner, repo, path, attrs, opts \\ [])

@spec delete_file(
  GhEx.Client.t(),
  String.t(),
  String.t(),
  String.t(),
  map(),
  keyword()
) ::
  GhEx.REST.result()

Deletes a file. attrs is the JSON body: message, the blob sha, and an optional branch.

get(client, owner, repo, path, opts \\ [])

Gets the contents of a file or directory. Use params: [ref: "..."] to select a branch, tag, or commit.