aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update')
-rw-r--r--nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update/cli.ex71
-rw-r--r--nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update/github_latest_version.ex42
-rw-r--r--nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update/nix.ex85
3 files changed, 0 insertions, 198 deletions
diff --git a/nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update/cli.ex b/nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update/cli.ex
deleted file mode 100644
index e735c428516..00000000000
--- a/nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update/cli.ex
+++ /dev/null
@@ -1,71 +0,0 @@
-defmodule NixpkgsGitHubUpdate.CLI do
- @moduledoc """
- Run updates on Nix Expressions that use fetchFromGitHub.
-
- Arguments the script accepts:
- --attribute <attribute_path>
-
- Example usage:
- ```
- ./nixpkgs_github_update --attribute "notes-up"
- ```
- """
- alias NixpkgsGitHubUpdate.{Nix, GitHubLatestVersion}
-
- def help do
- IO.puts("""
- Run updates on Nix Expressions that use fetchFromGitHub.
-
- Arguments the script accepts:
- --attribute <attribute_path>
-
- Example usage:
- ./nixpkgs_github_update --attribute "notes-up"
- """)
- end
-
- def main([]) do
- help()
- end
-
- def main(args) do
- opts = parse_args(args)
-
- attribute = opts[:attribute]
-
- case Nix.attribute_exists?(attribute) do
- true -> update(attribute)
- _ -> exit("Requested attribute doesn't exist.")
- end
- end
-
- def parse_args(args) do
- {options, _, _} =
- args
- |> OptionParser.parse(strict: [attribute: :string])
-
- options
- end
-
- def update(attribute) do
- version =
- Nix.get_owner_repo(attribute)
- |> GitHubLatestVersion.fetch()
- |> decode_response()
- |> construct_version()
-
- Nix.update_source_version(attribute, version)
- end
-
- def decode_response({:ok, response}), do: response
-
- def decode_response({:error, error}) do
- IO.puts("Error getting latest release from GitHub: #{error["message"]}")
- System.halt(2)
- end
-
- def construct_version(response) do
- Map.get(response, "tag_name")
- |> String.trim_leading("v")
- end
-end
diff --git a/nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update/github_latest_version.ex b/nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update/github_latest_version.ex
deleted file mode 100644
index 5333ad154f5..00000000000
--- a/nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update/github_latest_version.ex
+++ /dev/null
@@ -1,42 +0,0 @@
-defmodule NixpkgsGitHubUpdate.GitHubLatestVersion do
- @user_agent 'httpc'
-
- def fetch({owner, repo}) do
- endpoint = releases_endpoint(owner, repo)
- headers = construct_headers()
-
- :httpc.request(:get, {endpoint, headers}, [], [])
- |> handle_response
- end
-
- def releases_endpoint(owner, repo) 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
- System.get_env("OAUTH_TOKEN")
- end
-
- defp put_token(headers, token) when token != nil do
- Map.put_new(headers, 'Authorization', 'token #{String.to_charlist(token)}')
- end
-
- defp put_token(headers, _), do: headers
-
- def handle_response({_, {{_httpv, status_code, _}, _headers, response}}) do
- {
- status_code |> check_for_error(),
- response |> Poison.Parser.parse!(%{})
- }
- end
-
- defp check_for_error(200), do: :ok
- defp check_for_error(_), do: :error
-end
diff --git a/nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update/nix.ex b/nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update/nix.ex
deleted file mode 100644
index d5d9af84a6b..00000000000
--- a/nixpkgs/pkgs/desktops/pantheon/nixpkgs_github_update/lib/nixpkgs_github_update/nix.ex
+++ /dev/null
@@ -1,85 +0,0 @@
-defmodule NixpkgsGitHubUpdate.Nix do
- def executable do
- nix = System.find_executable("nix")
-
- if nix == nil do
- raise RuntimeError, message: "missing executable for 'nix'"
- end
-
- nix
- end
-
- def eval!(attribute) do
- System.cmd(
- executable(),
- [
- "eval",
- "--json",
- attribute
- ],
- stderr_to_stdout: true
- )
- |> handle_eval
- end
-
- defp handle_eval({eval_result, 0}) do
- case eval_result do
- "" -> eval_result
- _ -> Poison.Parser.parse!(eval_result, %{})
- end
- end
-
- defp handle_eval({eval_result, _}) do
- raise RuntimeError, message: "Error running nix eval: #{eval_result}"
- end
-
- def attribute_exists?(attribute) do
- attr_exist_expression = """
- with import <nixpkgs> {};
-
- let
- attrSet = pkgs.lib.attrByPath (pkgs.lib.splitString "." "#{attribute}") null pkgs;
- in
- if attrSet == null then false
- else true
- """
-
- eval!("(#{attr_exist_expression})")
- end
-
- def update_source_version(attribute, version) do
- System.cmd("update-source-version", [
- attribute,
- version
- ])
- end
-
- def get_url_attr(attribute) do
- case attribute_exists?("#{attribute}.src.fetchSubmodules") do
- true -> "url"
- false -> "urls"
- end
- end
-
- def get_owner_repo(attribute) do
- url_attr = get_url_attr(attribute)
-
- eval!("nixpkgs.#{attribute}.src.#{url_attr}")
- |> case do
- # It's fetchFromGitHub if we got a list
- [url | _] ->
- URI.parse(url).path
- |> String.split("/archive", trim: true)
- |> List.first()
- |> String.split("/", trim: true)
-
- # It's fetchgit if we got a plain string
- url ->
- URI.parse(url).path
- |> String.split(".git", trim: true)
- |> List.first()
- |> String.split("/", trim: true)
- end
- |> List.to_tuple()
- end
-end