forked from mirrors/nixpkgs
nixpkgs-github-update: don't malform header
This commit is contained in:
parent
c269c27f77
commit
3d00064872
|
@ -3,15 +3,9 @@ defmodule NixpkgsGitHubUpdate.GitHubLatestVersion do
|
||||||
|
|
||||||
def fetch({owner, repo}) do
|
def fetch({owner, repo}) do
|
||||||
endpoint = releases_endpoint(owner, repo)
|
endpoint = releases_endpoint(owner, repo)
|
||||||
|
headers = construct_headers()
|
||||||
|
|
||||||
oauth_token = String.to_charlist("#{System.get_env("OAUTH_TOKEN")}")
|
:httpc.request(:get, {endpoint, headers}, [], [])
|
||||||
|
|
||||||
headers = %{
|
|
||||||
'User-Agent' => @user_agent,
|
|
||||||
'Authorization' => 'token #{oauth_token}'
|
|
||||||
}
|
|
||||||
|
|
||||||
:httpc.request(:get, {endpoint, Map.to_list(headers)}, [], [])
|
|
||||||
|> handle_response
|
|> handle_response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,6 +13,23 @@ defmodule NixpkgsGitHubUpdate.GitHubLatestVersion do
|
||||||
'https://api.github.com/repos/#{owner}/#{repo}/releases/latest'
|
'https://api.github.com/repos/#{owner}/#{repo}/releases/latest'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def construct_headers do
|
||||||
|
headers = %{'User-Agent' => @user_agent}
|
||||||
|
|
||||||
|
put_token(headers, get_token())
|
||||||
|
|> Map.to_list
|
||||||
|
end
|
||||||
|
|
||||||
|
defp get_token do
|
||||||
|
String.to_charlist("#{System.get_env("OAUTH_TOKEN")}")
|
||||||
|
end
|
||||||
|
|
||||||
|
defp put_token(headers, token) when is_binary(token) do
|
||||||
|
Map.put_new(headers, 'Authorization', 'token #{token}')
|
||||||
|
end
|
||||||
|
|
||||||
|
defp put_token(headers, _), do: headers
|
||||||
|
|
||||||
def handle_response({_, {{_httpv, status_code, _}, _headers, response}}) do
|
def handle_response({_, {{_httpv, status_code, _}, _headers, response}}) do
|
||||||
{
|
{
|
||||||
status_code |> check_for_error(),
|
status_code |> check_for_error(),
|
||||||
|
|
Loading…
Reference in a new issue