GhEx.Repositories (gh_ex v0.3.4)

Copy Markdown View Source

Convenience functions for the GitHub Repositories REST API.

Thin wrappers over GhEx.REST that fill in the endpoint path and return the same {:ok, body, meta} / {:error, reason} shape; opts pass through to Req (so :params, headers, and a Req.Test plug all work). For an endpoint without a wrapper, call GhEx.REST directly.

Summary

Functions

Creates a repository in an organization. attrs is the JSON body (name, private, ...).

Lists activity events for a repository.

Gets a user's effective repository permission and role.

Checks whether username is a repository collaborator.

Lists branches on a repository.

Lists commits on a repository. Use params: for sha, path, since, until.

Lists repositories for an organization. Use params: for type, sort, per_page.

Lists public repositories for a user.

Auto-paginates a repository's branches into a lazy Stream.

Auto-paginates a repository's commits into a lazy Stream.

Auto-paginates a repository's activity events into a lazy Stream.

Auto-paginates an organization's repositories into a lazy Stream.

Auto-paginates a user's public repositories into a lazy Stream.

Functions

create_in_org(client, org, attrs, opts \\ [])

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

Creates a repository in an organization. attrs is the JSON body (name, private, ...).

delete(client, owner, repo, opts \\ [])

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

Deletes a repository.

events(client, owner, repo, opts \\ [])

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

Lists activity events for a repository.

GitHub optimizes event feeds for conditional polling. Store meta.etag from a successful response and send it back with headers: [{"if-none-match", etag}]; an unchanged feed returns {:ok, :not_modified, meta} without consuming the primary rate limit. The current polling interval remains available in meta.headers["x-poll-interval"].

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

Gets a repository.

get_collaborator_permission(client, owner, repo, username, opts \\ [])

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

Gets a user's effective repository permission and role.

The response includes the legacy base "permission", the assigned "role_name" (including custom roles), and a nested "user" object.

is_collaborator(client, owner, repo, username, opts \\ [])

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

Checks whether username is a repository collaborator.

Returns {:ok, true, meta} for GitHub's 204 collaborator response and {:ok, false, meta} for 404. Other failures retain the usual {:error, reason} shape.

list_branches(client, owner, repo, opts \\ [])

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

Lists branches on a repository.

list_commits(client, owner, repo, opts \\ [])

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

Lists commits on a repository. Use params: for sha, path, since, until.

list_for_org(client, org, opts \\ [])

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

Lists repositories for an organization. Use params: for type, sort, per_page.

list_for_user(client, username, opts \\ [])

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

Lists public repositories for a user.

stream_branches(client, owner, repo, opts \\ [])

@spec stream_branches(GhEx.Client.t(), String.t(), String.t(), keyword()) ::
  Enumerable.t()

Auto-paginates a repository's branches into a lazy Stream.

stream_commits(client, owner, repo, opts \\ [])

@spec stream_commits(GhEx.Client.t(), String.t(), String.t(), keyword()) ::
  Enumerable.t()

Auto-paginates a repository's commits into a lazy Stream.

stream_events(client, owner, repo, opts \\ [])

@spec stream_events(GhEx.Client.t(), String.t(), String.t(), keyword()) ::
  Enumerable.t()

Auto-paginates a repository's activity events into a lazy Stream.

Use events/4 instead when implementing an ETag-conditional polling loop, because a stream yields events rather than response metadata.

stream_for_org(client, org, opts \\ [])

@spec stream_for_org(GhEx.Client.t(), String.t(), keyword()) :: Enumerable.t()

Auto-paginates an organization's repositories into a lazy Stream.

stream_for_user(client, username, opts \\ [])

@spec stream_for_user(GhEx.Client.t(), String.t(), keyword()) :: Enumerable.t()

Auto-paginates a user's public repositories into a lazy Stream.

update(client, owner, repo, attrs, opts \\ [])

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

Updates a repository.