From 1cfb566d922686d67d9a39060d2f487b413e06d2 Mon Sep 17 00:00:00 2001 From: guilatrova Date: Wed, 30 Oct 2024 13:40:43 -0300 Subject: [PATCH] chore: add script to support testing prs --- bin/pull-contributor-pr | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 bin/pull-contributor-pr diff --git a/bin/pull-contributor-pr b/bin/pull-contributor-pr new file mode 100755 index 0000000..1c3d605 --- /dev/null +++ b/bin/pull-contributor-pr @@ -0,0 +1,30 @@ +#!/bin/bash + +# Usage: ./pull_pr.sh owner:branch [-r] + +# Set repository name +readonly REPO_NAME="tryceratops" + +# Extract owner and branch from the first argument +IFS=":" read -r OWNER BRANCH <<< "$1" + +# Check if -r flag is passed to remove the remote afterward +REMOVE_REMOTE=false +if [[ "$2" == "-r" ]]; then + REMOVE_REMOTE=true +fi + +# Add the contributor's remote +CONTRIBUTOR_REMOTE="${OWNER}_remote" +git remote add "$CONTRIBUTOR_REMOTE" "https://github.com/$OWNER/$REPO_NAME.git" + +git fetch "$CONTRIBUTOR_REMOTE" "$BRANCH" +git checkout -b "${OWNER}_${BRANCH}" "$CONTRIBUTOR_REMOTE/$BRANCH" + +# Remove the remote if -r flag was provided +if [ "$REMOVE_REMOTE" = true ]; then + git remote remove "$CONTRIBUTOR_REMOTE" + echo "Removed remote $CONTRIBUTOR_REMOTE" +fi + +echo "Branch ${OWNER}_${BRANCH} checked out successfully."