forked from clan/clan-core
tea-create-pr: Require fork and upstream branch
This commit is contained in:
parent
b18d7bfeac
commit
f63e3618c2
26
pkgs/merge-after-ci/merge-after-ci.py
Normal file → Executable file
26
pkgs/merge-after-ci/merge-after-ci.py
Normal file → Executable file
|
@ -1,4 +1,5 @@
|
|||
import argparse
|
||||
import shlex
|
||||
import subprocess
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
|
@ -11,14 +12,17 @@ args = parser.parse_args()
|
|||
if not args.reviewers and not args.no_review:
|
||||
parser.error("either --reviewers or --no-review must be given")
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
"tea-create-pr",
|
||||
"origin",
|
||||
"main",
|
||||
"--assignees",
|
||||
",".join(["clan-bot", *args.reviewers]),
|
||||
*(["--labels", "needs-review"] if not args.no_review else []),
|
||||
*args.args,
|
||||
]
|
||||
)
|
||||
cmd = [
|
||||
"tea-create-pr",
|
||||
"origin",
|
||||
"upstream",
|
||||
"main",
|
||||
"--assignees",
|
||||
",".join(["clan-bot", *args.reviewers]),
|
||||
*(["--labels", "needs-review"] if not args.no_review else []),
|
||||
*args.args,
|
||||
]
|
||||
|
||||
print("Running:", shlex.join(cmd))
|
||||
|
||||
subprocess.run(cmd)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
coreutils,
|
||||
git,
|
||||
tea,
|
||||
gawk,
|
||||
openssh,
|
||||
}:
|
||||
writeShellApplication {
|
||||
|
@ -14,6 +15,7 @@ writeShellApplication {
|
|||
git
|
||||
tea
|
||||
openssh
|
||||
gawk
|
||||
];
|
||||
text = builtins.readFile ./script.sh;
|
||||
}
|
||||
|
|
41
pkgs/tea-create-pr/script.sh
Normal file → Executable file
41
pkgs/tea-create-pr/script.sh
Normal file → Executable file
|
@ -1,17 +1,39 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
remoteName="${1:-origin}"
|
||||
targetBranch="${2:-main}"
|
||||
remoteFork="${1:-origin}"
|
||||
remoteUpstream="${2:-upstream}"
|
||||
targetBranch="${3:-main}"
|
||||
shift && shift
|
||||
TMPDIR="$(mktemp -d)"
|
||||
currentBranch="$(git rev-parse --abbrev-ref HEAD)"
|
||||
user="$(tea login list -o simple | cut -d" " -f4 | head -n1)"
|
||||
user="$(git config --get remote.origin.url | awk -F'[@:/]' '{print $3}' | tr -d '\n')"
|
||||
tempRemoteBranch="$user-$currentBranch"
|
||||
root_dir=$(git rev-parse --show-toplevel)
|
||||
|
||||
nix fmt -- --fail-on-change
|
||||
# Function to check if a remote exists
|
||||
check_remote() {
|
||||
if git remote get-url "$1" > /dev/null 2>&1; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Check if the remote 'upstream' is defined
|
||||
if ! check_remote "$remoteUpstream"; then
|
||||
echo "Error: $remoteUpstream remote is not defined."
|
||||
echo "Please fork the repository and add the $remoteUpstream remote."
|
||||
echo "$ git remote add $remoteUpstream <upstream-url>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
upstream_url=$(git remote get-url "$remoteUpstream")
|
||||
repo=$(echo "$upstream_url" | sed -E 's#.*:([^/]+/[^.]+)\.git#\1#')
|
||||
|
||||
treefmt -C "$root_dir"
|
||||
git log --reverse --pretty="format:%s%n%n%b%n%n" "$remoteUpstream/$targetBranch..HEAD" > "$TMPDIR"/commit-msg
|
||||
|
||||
git log --reverse --pretty="format:%s%n%n%b%n%n" "$remoteName/$targetBranch..HEAD" > "$TMPDIR"/commit-msg
|
||||
|
||||
$EDITOR "$TMPDIR"/commit-msg
|
||||
|
||||
|
@ -23,11 +45,12 @@ rest=$(echo "$COMMIT_MSG" | tail -n+2)
|
|||
if [[ "$firstLine" == "$rest" ]]; then
|
||||
rest=""
|
||||
fi
|
||||
git push --force -u "$remoteName" HEAD:refs/heads/"$tempRemoteBranch"
|
||||
|
||||
git push --force -u "$remoteFork" HEAD:refs/heads/"$tempRemoteBranch"
|
||||
|
||||
tea pr create \
|
||||
--repo "$repo" \
|
||||
--head "$user:$tempRemoteBranch" \
|
||||
--title "$firstLine" \
|
||||
--description "$rest" \
|
||||
--head "$tempRemoteBranch" \
|
||||
--base "$targetBranch" \
|
||||
"$@"
|
||||
"$@"
|
Loading…
Reference in New Issue
Block a user