Skip to content

Instantly share code, notes, and snippets.

@FarisHijazi
Created January 16, 2023 12:32
Show Gist options
  • Save FarisHijazi/eaa66fc1982b0e7017d4f2dd625aaa8d to your computer and use it in GitHub Desktop.
Save FarisHijazi/eaa66fc1982b0e7017d4f2dd625aaa8d to your computer and use it in GitHub Desktop.
git push, create pr, approve, and merge for azure devops (using `az` azure devops cli)
#!/bin/bash
# create pull request for current git branch and merge using azurecli
git push --set-upstream origin "$(git branch --show-current)" || exit
if pr_list=$(az repos pr list --output json --source-branch "$(git branch --show-current)"); then
if [ $(echo "$pr_list" | jq '. | length') -gt 0 ]; then
pullRequestId=$(echo "$pr_list" | jq '.[0].pullRequestId')
echo "A pull request already exists for the current branch with ID: $pullRequestId"
else
resp=$(az repos pr create --auto-complete true --delete-source-branch true --source-branch "$(git branch --show-current)" --output json) && \
pullRequestId=$(echo "$resp" | jq .pullRequestId) && \
# use semi-linear merge
az repos policy merge-strategy update --id "$pullRequestId" --allow-no-fast-forward true --allow-rebase-merge true
fi
az repos pr set-vote --id "$pullRequestId" --vote approve && \
az repos pr update --id "$pullRequestId" --status completed && \
git pull --all && \
echo -e 'you may now run:\n\n $ git stash -m "before merge master with $(git branch --show-current)" && git checkout master && git pull --all && git stash pop\n\n'
else
echo "An error occurred while checking for existing pull requests"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment