Getting GitHub branch name

Chris Harris's Avatar

Chris Harris

22 Feb, 2017 04:34 PM

Is there a way to get access to the name of the branch that was pushed to GitHub for a given PR?

  1. Support Staff 1 Posted by Feodor Fitsner on 22 Feb, 2017 06:40 PM

    Feodor Fitsner's Avatar

    Yes, you can take it from APPVEYOR_REPO_BRANCH environment variable: https://www.appveyor.com/docs/environment-variables/

  2. 2 Posted by Chris Harris on 22 Feb, 2017 06:42 PM

    Chris Harris's Avatar

    I saw that, but that is the name of the target branch ( for example master ), rather than the branch associated with the PR, for example my_super_cool_fix

  3. Support Staff 3 Posted by Feodor Fitsner on 22 Feb, 2017 06:43 PM

    Feodor Fitsner's Avatar

    Ah, I see. Well, I think the only way right now to grab that info is using GitHub API.

  4. 4 Posted by Chris Harris on 22 Feb, 2017 06:47 PM

    Chris Harris's Avatar

    I'm not familiar with the GitHub API, but i'm not sure there is enough information to look that up? For example the is no pull request number exposed?

    Thanks,

    Chris

  5. Support Staff 5 Posted by Feodor Fitsner on 22 Feb, 2017 06:48 PM

    Feodor Fitsner's Avatar

    PR number is in APPVEYOR_PULL_REQUEST_NUMBER variable (from here: https://www.appveyor.com/docs/environment-variables/)

  6. 6 Posted by Chris Harris on 22 Feb, 2017 06:54 PM

    Chris Harris's Avatar

    Awesome, thanks!

  7. 7 Posted by Ivailo Petrov on 22 Mar, 2017 06:42 PM

    Ivailo Petrov's Avatar

    Yes, it is possible to obtain the PR originating `repo` and `branch` using the GitHub API, but it is quite complicated (here is PS pseudo code):
    ```
    $PR_DATA = Invoke-WebRequest https://api.github.com/repos/$APPVEYOR_REPO_NAME/pulls/$APPVEYOR_PULL_REQUEST_NUMBER | ConvertFrom-Json
    $env:PR_REPO_NAME = $PR_DATA.head.repo.full_name
    $env:PR_REPO_BRANCH = $PR_DATA.head.ref
    ```

    Besides that, for `private` repos it requites GitHub token!

    And Bitbucket would need a separate solution...

    It would be best (like other CIs - Travis, Shippable, CircleCI) to simply provide the PR originating `repo` and `branch` environment variables.

  8. 8 Posted by Ilya Finkelshte... on 22 Mar, 2017 11:53 PM

    Ilya Finkelshteyn's Avatar

    Right, we have to do that, please watch this GitHub issue.

  9. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:16 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac