I see that the download path for a GitHub repo is of the form
https://github.com/{username}/{reponame}/archive/{branchname}.zip
For a priva
Here is a pure C# way:
var githubToken = "[token]";
var url = "https://github.com/[username]/[repository]/archive/[sha1|tag].zip";
var path = @"[local path]";
using (var client = new System.Net.Http.HttpClient())
{
var credentials = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:", githubToken);
credentials = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(credentials));
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", credentials);
var contents = client.GetByteArrayAsync(url).Result;
System.IO.File.WriteAllBytes(path, contents);
}
with CURL:
curl -L -F "login=$USER" -F "token=$TOKEN" https://github.com/$USER/$REPO/$PKGTYPE/$BRANCHorTAG
where $TOKEN is the API token on your github profile, not an oAuth2 token used for communicating with the APIv3.
$USER is the user account the token is connected with, not necessarily the organization/other user the repo belongs to. Second Instance of $USER is the user/account the repo is.
$REPO is the name of the private repository
$PKGTYPE is tarball or zipball and $BRANCHorTAG is a branch, like master, or a tag name for a commit.
The first instance of $USER must have access to the repo belonging to the second instance of $USER.
I could not find this documented ANYWHERE, so I also have a little write up about it if you want anything more detailed.
See this guide on creating a personal access token then run the following:
var githubToken = "token";
var request = (HttpWebRequest)WebRequest.Create("https://api.github.com/repos/$OWNER/$REPO/contents/$PATH");
request.Headers.Add(HttpRequestHeader.Authorization, string.Concat("token ", githubToken));
request.Accept = "application/vnd.github.v3.raw";
request.UserAgent = "test app"; //user agent is required https://developer.github.com/v3/#user-agent-required
using (var response = request.GetResponse())
{
var encoding = System.Text.ASCIIEncoding.UTF8;
using (var reader = new System.IO.StreamReader(response.GetResponseStream(), encoding))
{
var fileContent = reader.ReadToEnd();
}
}
I'm looking into the Okctokit.Net currently. Give it a shot. NuGet: Install-Package Octokit