merge_base_branch.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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! Assuming merge target is develop."
  10. # It probably hasn't had a PR opened yet. Since all PRs land on develop, we
  11. # can probably assume it's based on it and will be merged into it.
  12. GITBASE="develop"
  13. else
  14. # Get the reference, using the GitHub API
  15. GITBASE=`wget -O- https://api.github.com/repos/matrix-org/synapse/pulls/${CIRCLE_PR_NUMBER} | jq -r '.base.ref'`
  16. fi
  17. # Show what we are before
  18. git --no-pager show -s
  19. # Set up username so it can do a merge
  20. git config --global user.email bot@matrix.org
  21. git config --global user.name "A robot"
  22. # Fetch and merge. If it doesn't work, it will raise due to set -e.
  23. git fetch -u origin $GITBASE
  24. git merge --no-edit origin/$GITBASE
  25. # Show what we are after.
  26. git --no-pager show -s