diff --git a/flake.lock b/flake.lock index 08f008f..eccf6ab 100644 --- a/flake.lock +++ b/flake.lock @@ -542,11 +542,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1741010256, - "narHash": "sha256-WZNlK/KX7Sni0RyqLSqLPbK8k08Kq7H7RijPJbq9KHM=", + "lastModified": 1741173522, + "narHash": "sha256-k7VSqvv0r1r53nUI/IfPHCppkUAddeXn843YlAC5DR0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ba487dbc9d04e0634c64e3b1f0d25839a0a68246", + "rev": "d69ab0d71b22fa1ce3dbeff666e6deb4917db049", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index c385647..0d6b9e2 100644 --- a/flake.nix +++ b/flake.nix @@ -147,6 +147,7 @@ git-checkout-github-pr git-diff-word git-pp + git-show-link harmonia iot-data nix-remove-result-links diff --git a/hosts/krypton/programs.nix b/hosts/krypton/programs.nix index a58eb0b..ebd778f 100644 --- a/hosts/krypton/programs.nix +++ b/hosts/krypton/programs.nix @@ -29,6 +29,7 @@ chromium-incognito print-afra + git-show-link factorio-launcher ]; diff --git a/hosts/monitoring-3/grafana.nix b/hosts/monitoring-3/grafana.nix index 8637c80..b7e88b2 100644 --- a/hosts/monitoring-3/grafana.nix +++ b/hosts/monitoring-3/grafana.nix @@ -38,6 +38,10 @@ enableACME = true; forceSSL = true; locations."/".proxyPass = "http://[::1]:3001/"; + locations."= /api/live/ws" = { + proxyPass = "http://[::1]:3001"; + proxyWebsockets = true; + }; }; }; }; diff --git a/pkgs/git-show-link/default.nix b/pkgs/git-show-link/default.nix new file mode 100644 index 0000000..9fe38bb --- /dev/null +++ b/pkgs/git-show-link/default.nix @@ -0,0 +1,13 @@ +{ pkgs, ... }: + +pkgs.writeTextFile { + name = "git-show-link"; + executable = true; + destination = "/bin/git-show-link"; + allowSubstitutes = true; + preferLocalBuild = false; + text = '' + #!${pkgs.python3.withPackages (ps: with ps; [])}/bin/python3 + ${builtins.readFile ./git-show-link.py} + ''; +} diff --git a/pkgs/git-show-link/git-show-link.py b/pkgs/git-show-link/git-show-link.py new file mode 100755 index 0000000..0364cd3 --- /dev/null +++ b/pkgs/git-show-link/git-show-link.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 + +import argparse +import re +import subprocess + +REMOTE_TYPES = [ + { + # github + "match": re.compile(r'git@github.com:(?P<username>[\w\.-]+)/(?P<project>[\w\.-]+).git'), + "format-branch": lambda g, b: f"https://github.com/{g['username']}/{g['project']}/tree/{b}/", + "format-commit": lambda g, c: f"https://github.com/{g['username']}/{g['project']}/commit/{c}/", + }, + { + # gitea + "match": re.compile(r'(?P<gituser>[\w\.-]+)@(?P<host>[\w\.-]+):(?P<username>[\w\.-]+)/(?P<project>[\w\.-]+).git'), + "format-branch": lambda g, b: f"https://{g['host']}/{g['username']}/{g['project']}/src/branch/{b}/", + "format-commit": lambda g, c: f"https://{g['host']}/{g['username']}/{g['project']}/commit/{c}/", + }, +] + +def get_remote_branch(): + s = subprocess.run(["git", "status", "--porcelain", "-uno", "-b", "--no-ahead-behind"], capture_output=True, text=True) + + git_status_branch_info = s.stdout.splitlines()[0][3:].split()[0] + + branches = git_status_branch_info.split("...") + + if len(branches) != 2: + raise Exception("no branch name found") + + local_branch, remote_branch = branches + + remote, branch = remote_branch.split("/") + + return { + "remote": remote, + "branch": branch, + } + +def get_remote_url(remote): + s = subprocess.run(["git", "remote", "get-url", remote], capture_output=True, text=True) + + remote_url = s.stdout.strip() + + return remote_url + +def get_last_commit(): + s = subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True, text=True) + + commit = s.stdout.strip() + + return commit + +def main(): + parser = argparse.ArgumentParser( + prog='git-show-link', + ) + + parser.add_argument("--branch", dest="display_branch", action='store_true', help="Display link to branch, instead to commit") + + args = parser.parse_args() + + r = get_remote_branch() + + remote_url = get_remote_url(r["remote"]) + + for remote_type in REMOTE_TYPES: + m = remote_type["match"].match(remote_url) + + if m is None: + continue + + g = m.groupdict() + + if args.display_branch: + print(remote_type["format-branch"](g, r["branch"])) + else: + commit = get_last_commit() + print(remote_type["format-commit"](g, commit)) + break + + +if __name__ == "__main__": + main() diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix index e478135..7caa76c 100644 --- a/pkgs/overlay.nix +++ b/pkgs/overlay.nix @@ -14,6 +14,7 @@ final: prev: { git-checkout-github-pr = final.callPackage ./git-checkout-github-pr {}; git-diff-word = final.callPackage ./git-diff-word {}; git-pp = final.callPackage ./git-pp {}; + git-show-link = final.callPackage ./git-show-link {}; iot-data = final.python3.pkgs.callPackage ./iot-data {}; nix-remove-result-links = final.callPackage ./nix-remove-result-links {}; nixfiles-auto-install = final.callPackage ./nixfiles/nixfiles-auto-install.nix {};