2023-07-28 12:11:19 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
remoteName="${1:-origin}"
|
|
|
|
targetBranch="${2:-main}"
|
|
|
|
shift && shift
|
2023-07-28 16:14:43 +00:00
|
|
|
TMPDIR="$(mktemp -d)"
|
2023-07-28 12:11:19 +00:00
|
|
|
currentBranch="$(git rev-parse --abbrev-ref HEAD)"
|
2023-10-31 12:16:19 +00:00
|
|
|
user="$(tea login list -o simple | cut -d" " -f4 | head -n1)"
|
2023-07-28 12:11:19 +00:00
|
|
|
tempRemoteBranch="$user-$currentBranch"
|
|
|
|
|
2023-09-13 13:48:34 +00:00
|
|
|
nix fmt -- --fail-on-change
|
|
|
|
|
2023-07-28 12:11:19 +00:00
|
|
|
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
|
2023-08-03 13:29:50 +00:00
|
|
|
git push --force -u "$remoteName" HEAD:refs/heads/"$tempRemoteBranch"
|
2023-07-28 12:11:19 +00:00
|
|
|
|
|
|
|
tea pr create \
|
|
|
|
--title "$firstLine" \
|
|
|
|
--description "$rest" \
|
|
|
|
--head "$tempRemoteBranch" \
|
|
|
|
--base "$targetBranch" \
|
|
|
|
"$@"
|