diff --git a/flake-parts/tea-create-pr/default.nix b/flake-parts/tea-create-pr/default.nix new file mode 100644 index 00000000..c2c7df2e --- /dev/null +++ b/flake-parts/tea-create-pr/default.nix @@ -0,0 +1,26 @@ +{ + perSystem = + { config + , pkgs + , ... + }: + let + name = builtins.baseNameOf ./.; + script = config.writers.writePureShellScriptBin + name + [ + pkgs.bash + pkgs.coreutils + pkgs.git + pkgs.tea + pkgs.openssh + ] + '' + export EDITOR=${pkgs.vim}/bin/vim + bash ${./script.sh} "$@" + ''; + in + { + packages.${name} = script; + }; +} diff --git a/flake-parts/tea-create-pr/script.sh b/flake-parts/tea-create-pr/script.sh new file mode 100644 index 00000000..f2cd6fb0 --- /dev/null +++ b/flake-parts/tea-create-pr/script.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -euo pipefail + +remoteName="${1:-origin}" +targetBranch="${2:-main}" +shift && shift +currentBranch="$(git rev-parse --abbrev-ref HEAD)" +user="$(tea login list -o simple | cut -d" " -f4)" +tempRemoteBranch="$user-$currentBranch" + +git log --reverse --pretty="format:%s%n%n%b%n%n" "$remoteName/$targetBranch..HEAD" > "$TMPDIR"/commit-msg + +$EDITOR "$TMPDIR"/commit-msg + +COMMIT_MSG=$(cat "$TMPDIR"/commit-msg) + +firstLine=$(echo "$COMMIT_MSG" | head -n1) +rest=$(echo "$COMMIT_MSG" | tail -n+2) + +if [[ "$firstLine" == "$rest" ]]; then + rest="" +fi + +git push "$remoteName" HEAD:refs/heads/"$tempRemoteBranch" + +tea pr create \ + --title "$firstLine" \ + --description "$rest" \ + --head "$tempRemoteBranch" \ + --base "$targetBranch" \ + "$@" diff --git a/flake.nix b/flake.nix index a889ed2b..8463cb6b 100644 --- a/flake.nix +++ b/flake.nix @@ -21,6 +21,7 @@ ./flake-parts/formatting.nix ./flake-parts/modules.nix ./flake-parts/packages.nix + ./flake-parts/tea-create-pr ./flake-parts/writers ./templates/flake-module.nix ./templates/python-project/flake-module.nix