Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading private patches from Github

Tags:

git

github

curl

When a PR is created in the private repos of my organization, I receive emails from Github with links such as http://github.com/<my org>/<project>/<PR #>.patch. I would like to download such links with curl; as-is, I get a 404, and I can't seem to find the right incantation with -H "Authorization: <oauth token>" to make it work.

like image 974
Vincent Foley Avatar asked Oct 18 '22 10:10

Vincent Foley


1 Answers

You can use Github API to do this, get the pull request with this API :

GET /repos/:owner/:repo/pulls/:number

You can use a personal access token with repos scope to get the result for a private repo with the authorization header : -H 'Authorization: token YOUR_TOKEN'

Use commits comparison and pull request media types :

  • patch : application/vnd.github.VERSION.patch
  • diff : application/vnd.github.VERSION.diff

The curl requests are :

  • request patch for PR #18 :

    curl -H 'Authorization: token YOUR_TOKEN' \
         -H 'Accept: application/vnd.github.VERSION.patch' \
         https://api.github.com/repos/<my org>/<project>/pulls/18 
    
  • request diff for PR #18

    curl -H 'Authorization: token YOUR_TOKEN' \
         -H 'Accept: application/vnd.github.VERSION.diff' \
         https://api.github.com/repos/<my org>/<project>/pulls/18 
    
like image 73
Bertrand Martel Avatar answered Oct 21 '22 04:10

Bertrand Martel