scikit-build / scikit-ci-addons

Command line tool and a set of scripts useful to help drive CI
http://scikit-ci-addons.readthedocs.org/
Apache License 2.0
6 stars 9 forks source link

appveyor: Add add-on allowing to get branch from PR number (code provided) #24

Closed jcfr closed 2 years ago

jcfr commented 8 years ago

It would be useful to create an appveyor add-on allowing to get the branch associated with a PR number.

Possible filename: appveyor/get_pullrequest_branch.ps1

$env:BOOTSRAP_BRANCH = $env:APPVEYOR_REPO_BRANCH
if($env:APPVEYOR_PULL_REQUEST_NUMBER -ne $null) {
  #
  # Since AppVeyor provides only the PR numbder, retrieve
  # PR branch name directly from GitHub
  #
  # See also https://developer.github.com/v3/pulls/#get-a-single-pull-request
  #
  $GitHubUri="https://api.github.com/repos/scikit-build/scikit-ci/pulls/$env:APPVEYOR_PULL_REQUEST_NUMBER"
  $env:BOOTSRAP_BRANCH=(Invoke-WebRequest            `
    -Uri $GitHubUri                                  `
    -Headers @{                                      `
      "Authorization"="token $env:GH_CMDLINE_TOKEN"; `
      "Accept"= "application/vnd.github.v3.raw"      `
    } | ConvertFrom-Json).head.ref
}
Write-Host "BOOTSRAP_BRANCH:$env:BOOTSRAP_BRANCH"

# Clear GH_CMDLINE_TOKEN variable
Remove-Item Env:GH_CMDLINE_TOKEN