1
0

pkgs/git-checkout-github-pr: Add script to checkout GitHub PRs in repos

This commit is contained in:
clerie 2024-07-11 13:18:45 +02:00
parent e082168630
commit 9ddc82b507
Signed by: clerie
GPG Key ID: BD9F56480870BAD2
4 changed files with 55 additions and 0 deletions

View File

@ -114,6 +114,7 @@
clerie-sops-config clerie-sops-config
clerie-sops-edit clerie-sops-edit
chromium-incognito chromium-incognito
git-checkout-github-pr
iot-data iot-data
nix-remove-result-links nix-remove-result-links
nixfiles-auto-install nixfiles-auto-install

View File

@ -0,0 +1,9 @@
{ pkgs, ... }:
pkgs.writeShellApplication {
name = "git-checkout-github-pr";
text = builtins.readFile ./git-checkout-github-pr.sh;
runtimeInputs = with pkgs; [
git
];
}

View File

@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail
ID=""
REMOTE="origin"
LOCAL_BRANCH=""
while [[ $# -gt 0 ]]; do
case $1 in
--remote)
REMOTE="$2"
shift
shift
;;
--local-branch)
LOCAL_BRANCH="$2"
shift
shift
;;
*)
if [[ -z "${ID}" ]]; then
ID="$1"
shift
else
echo "Unknown option $1"
exit 1
fi
;;
esac
done
if [[ -z "${ID}" ]]; then
echo "Specify GitHub PR number"
exit 1
fi
if [[ -z "${LOCAL_BRANCH}" ]]; then
LOCAL_BRANCH="pr/${ID}"
fi
git fetch "${REMOTE}" "pull/${ID}/head:${LOCAL_BRANCH}"
git switch "${LOCAL_BRANCH}"

View File

@ -7,6 +7,7 @@ final: prev: {
clerie-sops-edit = final.callPackage ./clerie-sops/clerie-sops-edit.nix {}; clerie-sops-edit = final.callPackage ./clerie-sops/clerie-sops-edit.nix {};
clerie-update-nixfiles = final.callPackage ./clerie-update-nixfiles/clerie-update-nixfiles.nix {}; clerie-update-nixfiles = final.callPackage ./clerie-update-nixfiles/clerie-update-nixfiles.nix {};
chromium-incognito = final.callPackage ./chromium-incognito {}; chromium-incognito = final.callPackage ./chromium-incognito {};
git-checkout-github-pr = final.callPackage ./git-checkout-github-pr {};
iot-data = final.python3.pkgs.callPackage ./iot-data {}; iot-data = final.python3.pkgs.callPackage ./iot-data {};
nix-remove-result-links = final.callPackage ./nix-remove-result-links {}; nix-remove-result-links = final.callPackage ./nix-remove-result-links {};
nixfiles-auto-install = final.callPackage ./nixfiles/nixfiles-auto-install.nix {}; nixfiles-auto-install = final.callPackage ./nixfiles/nixfiles-auto-install.nix {};