Some user may use master or other openwrt repo as the pr repo. This is
problematic as we checkout with the pr repo name and this may conflict
with the current openwrt branch name.
Fix it and checkout the local branch with the pr repo name + the pr
author.
Example:
usertest123:master is checkout to master-usertest123
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
PR_USER="$(echo "$PR_INFO" | jq -r ".head.user.login")"
PR_BRANCH="$(echo "$PR_INFO" | jq -r ".head.ref")"
PR_USER="$(echo "$PR_INFO" | jq -r ".head.user.login")"
PR_BRANCH="$(echo "$PR_INFO" | jq -r ".head.ref")"
+LOCAL_PR_BRANCH="$PR_BRANCH"-"$PR_USER"
PR_REPO="$(echo "$PR_INFO" | jq -r ".head.repo.html_url")"
if ! $GIT remote get-url $PR_USER &> /dev/null || [ -n "$DRY_RUN" ]; then
PR_REPO="$(echo "$PR_INFO" | jq -r ".head.repo.html_url")"
if ! $GIT remote get-url $PR_USER &> /dev/null || [ -n "$DRY_RUN" ]; then
echo "Fetching remote $PR_USER"
$GIT fetch $PR_USER
echo "Fetching remote $PR_USER"
$GIT fetch $PR_USER
-echo "Creating branch $PR_BRANCH"
-if ! $GIT checkout -b $PR_BRANCH $PR_USER/$PR_BRANCH; then
+echo "Creating branch $LOCAL_PR_BRANCH for $PR_BRANCH"
+if ! $GIT checkout -b $LOCAL_PR_BRANCH $PR_USER/$PR_BRANCH; then
echo "Failed to checkout new branch $PR_BRANCH from $PR_USER/$PR_BRANCH" >&2
exit 8
fi
echo "Failed to checkout new branch $PR_BRANCH from $PR_USER/$PR_BRANCH" >&2
exit 8
fi
-echo "Rebasing $PR_BRANCH on top of $BRANCH"
+echo "Rebasing $LOCAL_PR_BRANCH on top of $BRANCH"
if ! $GIT rebase origin/$BRANCH; then
echo "Failed to rebase $PR_BRANCH with origin/$BRANCH" >&2
exit 9
fi
if ! $GIT rebase origin/$BRANCH; then
echo "Failed to rebase $PR_BRANCH with origin/$BRANCH" >&2
exit 9
fi
-echo "Force pushing $PR_BRANCH to $PR_USER"
-if ! $GIT push $PR_USER HEAD --force; then
+echo "Force pushing $LOCAL_PR_BRANCH to HEAD:$PR_BRANCH for $PR_USER"
+if ! $GIT push $PR_USER HEAD:$PR_BRANCH --force; then
echo "Failed to force push HEAD to $PR_USER" >&2
exit 10
fi
echo "Failed to force push HEAD to $PR_USER" >&2
exit 10
fi
-echo "Deleting branch $PR_BRANCH"
-$GIT branch -D $PR_BRANCH
+echo "Deleting branch $LOCAL_PR_BRANCH"
+$GIT branch -D $LOCAL_PR_BRANCH
# Default close comment
COMMENT="Thanks! Rebased on top of $BRANCH and merged!"
# Default close comment
COMMENT="Thanks! Rebased on top of $BRANCH and merged!"