gitgithub

Cloning a private GitHub repo, authenticated as a GitHub app


I'm building a CI application that does some work on the contents of a GitHub repo on a schedule, or every time new code is merged, via a Webhook.

I've created a GitHub app and got everything set up so users can sign in with it, grant it access to their repos, and configure their CI jobs.

I'm unable to find documentation on how to clone the full repo contents, if it is private, by authenticating as the user who connected my GitHub app. I found the docs on getting the tree for a repo but it seems like I'd still have to go through that JSON response and download every file separately, which feels like re-implementing Git clone myself.

Right now I'm just launching the git clone command as a subprocess from my CI script. Just wondering what the solution is here. Should I use libgit2? Or use that tree API and download all the files?


Solution

  • Probably a little late to answer this, GitHub has an option to clone a repository through access tokens requested by the application.

    Github Documentation

    git clone https://x-access-token:<token>@github.com/owner/repo.git