I am trying to download a single file from github enterprise, given the URL, in C#, with OctoKit. This is the head version from master (or the default branch).
I want to do the equivalent of:
curl -H 'Authorization: token INSERTACCESSTOKENHERE' -H 'Accept:application/vnd.github.v3.raw' -O -L https://private.github.enterprise.com/repos/owner/repo/contents/path/foo.txt
I have found a way to do this, but the repo is extremely large and it takes a long time. The reason is, I have to spider the entire tree in order to find the identifiers for the specific files that I want.
Uri url = new Uri(URL);
String trans_fullname = String.Format("/{0}/", repo.FullName);
String basePath = url.AbsolutePath.Replace(trans_fullname, "");
/* this, and the linq line, are what is taking all the time */
var cannotuseawait = client.Git.Tree.GetRecursive(repo.Id, "heads/master" );
cannotuseawait.Wait();
TreeResponse tree = cannotuseawait.Result;
/* searching through a lot of items!!!!! */
TreeItem Found = (from foo in tree.Tree where foo.Path.Contains(basePath) select foo).SingleOrDefault<TreeItem>();
var fwait = client.Git.Blob.Get(Repo.Id, Found.Sha);
fwait.wait();
var contents_64 = fwait.Result;
Again, this takes over 4 minutes because our repository is so huge. While, the curl command above is relatively instant... so, I know there is a way. I would prefer not to abandon Octokit, since I have other functionality in the project that already works with it.