From 31b87c71776187803a88e29ee956194fb126e434 Mon Sep 17 00:00:00 2001 From: Christoph Schmatzler Date: Mon, 30 Mar 2026 12:32:47 +0200 Subject: [PATCH] tuist-pr clone --- modules/_dev-tools/tuist-pr.nu | 67 ++++++++++++++++++++++++++++++++++ modules/dev-tools.nix | 7 ++++ 2 files changed, 74 insertions(+) create mode 100644 modules/_dev-tools/tuist-pr.nu diff --git a/modules/_dev-tools/tuist-pr.nu b/modules/_dev-tools/tuist-pr.nu new file mode 100644 index 0000000..4304d57 --- /dev/null +++ b/modules/_dev-tools/tuist-pr.nu @@ -0,0 +1,67 @@ +#!/usr/bin/env nu + +const repo = "tuist/tuist" + +def fail [msg: string] { + error make {msg: $msg} +} + +def clean [s: string] { + $s | str replace --all "\t" " " | str replace --all "\n" " " +} + +def pick-pr [] { + let prs = ( + gh pr list --repo $repo --state open --limit 200 --json number,title,headRefName,author + | from json + ) + + if ($prs | is-empty) { + fail $"No open PRs found for ($repo)" + } + + let choice = ( + $prs + | each {|pr| + let title = (clean $pr.title) + let branch = (clean $pr.headRefName) + let author = $pr.author.login + $"($pr.number)\t($title)\t($author)\t($branch)" + } + | str join (char newline) + | fzf --prompt "tuist pr > " --delimiter "\t" --with-nth "1,2,3,4" --preview "gh pr view --repo tuist/tuist {1}" --preview-window "right:70%" + ) + + if ($choice | str trim | is-empty) { + exit 130 + } + + $choice | split row "\t" | first | into int +} + +def main [pr_number?: int] { + let number = if ($pr_number | is-empty) { pick-pr } else { $pr_number } + let pr = ( + gh pr view --repo $repo $number --json number,title,url + | from json + ) + + let base = ([$env.HOME "Projects" "Work"] | path join) + let dest = ([$base $"tuist-pr-($pr.number)"] | path join) + + if ($dest | path exists) { + fail $"Destination already exists: ($dest)" + } + + ^mkdir -p $base + + print $"Cloning ($repo) PR #($pr.number): ($pr.title)" + gh repo clone $repo $dest + + do { + cd $dest + gh pr checkout $pr.number + } + + print $"Ready: ($dest)" +} diff --git a/modules/dev-tools.nix b/modules/dev-tools.nix index 00c2455..5796108 100644 --- a/modules/dev-tools.nix +++ b/modules/dev-tools.nix @@ -36,6 +36,13 @@ in { tea tokei tree-sitter + (pkgs.writeShellApplication { + name = "tuist-pr"; + runtimeInputs = with pkgs; [coreutils fzf gh git nushell]; + text = '' + exec nu ${./_dev-tools/tuist-pr.nu} "$@" + ''; + }) ] ++ lib.optionals stdenv.isDarwin [ xcodes