tea-create-pr: init

This commit is contained in:
DavHau
2023-07-28 14:11:19 +02:00
parent 4950694270
commit 0d0df11897
3 changed files with 58 additions and 0 deletions

View File

@@ -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" \
"$@"