merge_base_branch.sh 923 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env bash
  2. set -e
  3. # CircleCI doesn't give CIRCLE_PR_NUMBER in the environment for non-forked PRs. Wonderful.
  4. # In this case, we just need to do some ~shell magic~ to strip it out of the PULL_REQUEST URL.
  5. echo 'export CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"' >> $BASH_ENV
  6. source $BASH_ENV
  7. if [[ -z "${CIRCLE_PR_NUMBER}" ]]
  8. then
  9. echo "Can't figure out what the PR number is!"
  10. exit 1
  11. fi
  12. # Get the reference, using the GitHub API
  13. GITBASE=`curl -q https://api.github.com/repos/matrix-org/synapse/pulls/${CIRCLE_PR_NUMBER} | jq -r '.base.ref'`
  14. # Show what we are before
  15. git show -s
  16. # Set up username so it can do a merge
  17. git config --global user.email bot@matrix.org
  18. git config --global user.name "A robot"
  19. # Fetch and merge. If it doesn't work, it will raise due to set -e.
  20. git fetch -u origin $GITBASE
  21. git merge --no-edit origin/$GITBASE
  22. # Show what we are after.
  23. git show -s