GhEx.PullRequests (gh_ex v0.3.4)

Copy Markdown View Source

Convenience functions for the GitHub Pull Requests REST API.

Each function is a thin wrapper over GhEx.REST that fills in the endpoint path. They return the same {:ok, body, meta} / {:error, reason} shape as GhEx.REST and pass opts 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 pull request. attrs is the JSON body (title, head, base, body, draft, ...).

Creates a review comment anchored to a pull request diff.

Creates a review on a pull request. attrs sets event (APPROVE, REQUEST_CHANGES, COMMENT), body, comments.

Gets a single pull request by number.

Gets a pull request's unified diff as a string.

Gets the current result of an asynchronous merge request.

Gets a pull request's mailbox-format patch as a string.

Checks whether a pull request has been merged.

Lists pull requests in a repository. Use params: for state, base, head, and the other query options.

Lists review comments on a pull request.

Lists the commits on a pull request. GitHub returns at most 250 commits.

Lists the files changed in a pull request.

Lists the reviews on a pull request.

Merges a standalone pull request using GitHub's legacy synchronous endpoint.

Removes review requests from users and/or teams.

Requests reviews from users and/or teams.

Auto-paginates pull requests in a repository into a lazy Stream of individual pull requests (see GhEx.REST.stream/3).

Auto-paginates a pull request's review comments into a lazy Stream.

Auto-paginates the commits on a pull request into a lazy Stream.

Auto-paginates the files changed in a pull request into a lazy Stream.

Auto-paginates the reviews on a pull request into a lazy Stream.

Updates a pull request. attrs may set title, body, state, base, and so on.

Types

number_ref()

@type number_ref() :: integer() | String.t()

Functions

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

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

Creates a pull request. attrs is the JSON body (title, head, base, body, draft, ...).

create_comment(client, owner, repo, number, attrs, opts \\ [])

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

Creates a review comment anchored to a pull request diff.

attrs requires body, commit_id, and path. For a line comment, provide line and side ("LEFT" or "RIGHT"). A multi-line comment also uses start_line and start_side. For a file-level comment, set subject_type: "file"; line is then optional. GitHub is closing down the older position parameter, so prefer the line-based fields.

create_review(client, owner, repo, number, attrs, opts \\ [])

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

Creates a review on a pull request. attrs sets event (APPROVE, REQUEST_CHANGES, COMMENT), body, comments.

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

Gets a single pull request by number.

get_diff(client, owner, repo, number, opts \\ [])

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

Gets a pull request's unified diff as a string.

This forces GitHub's application/vnd.github.diff media type while preserving any other request headers supplied through opts.

get_merge_result(client, owner, repo, number, uuid, opts \\ [])

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

Gets the current result of an asynchronous merge request.

Pending results are retained by GitHub for 24 hours after their most recent update.

get_patch(client, owner, repo, number, opts \\ [])

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

Gets a pull request's mailbox-format patch as a string.

This forces GitHub's application/vnd.github.patch media type while preserving any other request headers supplied through opts.

is_merged(client, owner, repo, number, opts \\ [])

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

Checks whether a pull request has been merged.

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

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

Lists pull requests in a repository. Use params: for state, base, head, and the other query options.

list_comments(client, owner, repo, number, opts \\ [])

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

Lists review comments on a pull request.

These are comments anchored to a diff, not issue comments from the pull request's Conversation tab. Use params: for sort, direction, and since.

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

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

Lists the commits on a pull request. GitHub returns at most 250 commits.

list_files(client, owner, repo, number, opts \\ [])

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

Lists the files changed in a pull request.

list_reviews(client, owner, repo, number, opts \\ [])

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

Lists the reviews on a pull request.

merge(client, owner, repo, number, attrs \\ %{}, opts \\ [])

Merges a standalone pull request using GitHub's legacy synchronous endpoint.

attrs may set commit_title, commit_message, and merge_method ("merge", "squash", or "rebase"). This endpoint cannot merge a stacked pull request; use merge_async/6 for stacks.

merge_async(client, owner, repo, number, attrs \\ %{}, opts \\ [])

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

Submits an asynchronous merge request.

For a stacked pull request, GitHub merges the selected pull request and every unmerged pull request below it as one atomic operation. attrs may set merge_method ("merge", "squash", or "rebase"), merge_action ("default", "direct_merge", or "merge_queue"), commit_title, commit_message, and sha.

A 202 response has status "pending" and includes a UUID. Poll it with get_merge_result/6 until the status is "merged", "enqueued", or "failed".

GitHub may return a 409 with the existing pending request when a merge is already running. As with every non-2xx REST response in gh_ex, that is returned as {:error, %GhEx.Error{}}; the pending result remains available in the error's body field.

remove_requested_reviewers(client, owner, repo, number, attrs, opts \\ [])

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

Removes review requests from users and/or teams.

attrs accepts the same reviewers and team_reviewers arrays as request_reviewers/6.

reply_to_comment(client, owner, repo, number, comment_id, body, opts \\ [])

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

Replies to a top-level review comment.

GitHub does not support replies to replies; comment_id must identify the top-level comment in the thread.

request_reviewers(client, owner, repo, number, attrs, opts \\ [])

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

Requests reviews from users and/or teams.

attrs may contain reviewers, an array of user logins, and team_reviewers, an array of team slugs.

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

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

Auto-paginates pull requests in a repository into a lazy Stream of individual pull requests (see GhEx.REST.stream/3).

stream_comments(client, owner, repo, number, opts \\ [])

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

Auto-paginates a pull request's review comments into a lazy Stream.

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

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

Auto-paginates the commits on a pull request into a lazy Stream.

stream_files(client, owner, repo, number, opts \\ [])

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

Auto-paginates the files changed in a pull request into a lazy Stream.

stream_reviews(client, owner, repo, number, opts \\ [])

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

Auto-paginates the reviews on a pull request into a lazy Stream.

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

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

Updates a pull request. attrs may set title, body, state, base, and so on.