Permalink
Browse files

Merge #444

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 2d465e27caac59ba3945f54c3ba10594b7cf329a
Showing with 25 additions and 13 deletions.
  1. +25 −13 lib/github/github/server.ex
@@ -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
@@ -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

0 comments on commit 2d465e2

Please sign in to comment.