mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-20 04:31:52 +00:00
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
|
||||
endpoint = releases_endpoint(owner, repo)
|
||||
headers = construct_headers()
|
||||
|
||||
oauth_token = String.to_charlist("#{System.get_env("OAUTH_TOKEN")}")
|
||||
|
||||
headers = %{
|
||||
'User-Agent' => @user_agent,
|
||||
'Authorization' => 'token #{oauth_token}'
|
||||
}
|
||||
|
||||
:httpc.request(:get, {endpoint, Map.to_list(headers)}, [], [])
|
||||
:httpc.request(:get, {endpoint, headers}, [], [])
|
||||
|> handle_response
|
||||
end
|
||||
|
||||
|
@ -19,6 +13,23 @@ defmodule NixpkgsGitHubUpdate.GitHubLatestVersion do
|
|||
'https://api.github.com/repos/#{owner}/#{repo}/releases/latest'
|
||||
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
|
||||
{
|
||||
status_code |> check_for_error(),
|
||||
|
|
Loading…
Reference in a new issue