Getting GitHub branch name
Is there a way to get access to the name of the branch that was pushed to GitHub for a given PR?
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
Support Staff 1 Posted by Feodor Fitsner on 22 Feb, 2017 06:40 PM
Yes, you can take it from
APPVEYOR_REPO_BRANCH
environment variable: https://www.appveyor.com/docs/environment-variables/2 Posted by Chris Harris on 22 Feb, 2017 06:42 PM
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
Support Staff 3 Posted by Feodor Fitsner on 22 Feb, 2017 06:43 PM
Ah, I see. Well, I think the only way right now to grab that info is using GitHub API.
4 Posted by Chris Harris on 22 Feb, 2017 06:47 PM
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
Support Staff 5 Posted by Feodor Fitsner on 22 Feb, 2017 06:48 PM
PR number is in
APPVEYOR_PULL_REQUEST_NUMBER
variable (from here: https://www.appveyor.com/docs/environment-variables/)6 Posted by Chris Harris on 22 Feb, 2017 06:54 PM
Awesome, thanks!
7 Posted by Ivailo Petrov on 22 Mar, 2017 06:42 PM
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 Posted by Ilya Finkelshte... on 22 Mar, 2017 11:53 PM
Right, we have to do that, please watch this GitHub issue.
Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:16 AM.