How to get the pull request upstream branch?


In Travis TRAVIS_BRANCH yields the upstream branch, e.g. master for a PR.
However CIRCLE_BRANCH yields pull/6003 - how do we I get the upstream branch on CircleCI?


Is anyone actually reading this? I think getting the target branch for a PR is a major use case …
CC @CircleCI-Employees


Right now I’m using sth. like this, subject to rate limiting by github.

    if [ -n ${CIRCLE_PR_NUMBER:-} ]; then
        local base_branch=$(curl -fsSL$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls/$CIRCLE_PR_NUMBER | jq -r '.base.ref')
        local base_branch=$CIRCLE_BRANCH

Since this information is contained in the webhook CircleCI receives from GH (.base.ref in PullRequestEvent), it would be helpful to just expose this information.


This is a great idea! I’ve opened a feature request here: Expose the title and upstream branch of a Pull Request build as an env

Please :heart: the post to show your support as that is how the CircleCi product team prioritizes requests.