Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Merge #444
Browse files Browse the repository at this point in the history
444: Add pagination support for github reviews r=notriddle a=notriddle

Fixes #437

Co-authored-by: Michael Howell <michael@notriddle.com>
  • Loading branch information
bors[bot] and notriddle committed Aug 9, 2018
2 parents bc4a647 + a2c0a79 commit 2d465e2
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions lib/github/github/server.ex
Expand Up @@ -270,19 +270,11 @@ defmodule BorsNG.GitHub.Server do
end
end

def do_handle_call(:get_reviews, repo_conn, {issue_xref}) do
repo_conn
|> get!("pulls/#{issue_xref}/reviews")
|> case do
%{body: raw, status_code: 200} ->
res = raw
|> Poison.decode!()
|> GitHub.Reviews.from_json!()

{:ok, res}
_ ->
{:error, :get_reviews}
end
def do_handle_call(:get_reviews, {{:raw, token}, repo_xref}, {issue_xref}) do
reviews = token
|> get_reviews_json_!("#{site()}/repositories/#{repo_xref}/pulls/#{issue_xref}/reviews", [])
|> GitHub.Reviews.from_json!()
{:ok, reviews}
end

def do_handle_call(:get_file, repo_conn, {branch, path}) do
Expand Down Expand Up @@ -355,6 +347,26 @@ defmodule BorsNG.GitHub.Server do
[])}
end

defp get_reviews_json_!(_, nil, append) do
append
end

defp get_reviews_json_!(token, url, append) do
params = get_url_params(url)
%{body: raw, status_code: 200, headers: headers} = HTTPoison.get!(
url,
[
{"Authorization", "token #{token}"},
{"Accept", @installation_content_type}],
[params: params])
json = Enum.concat(append, Poison.decode!(raw))
next_headers = get_next_headers(headers)
case next_headers do
[] -> json
[next] -> get_reviews_json_!(token, next.next.url, json)
end
end

@spec get_installation_repos_!(binary, binary, [trepo]) :: [trepo]
defp get_installation_repos_!(_, nil, repos) do
repos
Expand Down

0 comments on commit 2d465e2

Please sign in to comment.