Reputation: 123
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.
Upvotes: 1
Views: 1287
Reputation: 123
So, it turns out, in the client.Repository.Content object there are methods called things like UpdateFile, GetReadMe, DeleteFile, CreateFile, but there is no "GetFile".
But, counter intuitively (at least for me), there is a function called "GetAllContents", which normally, as one would expect, gets all the contents for a repo. But, one of the overloads takes a path as a parameter, so you can limit it to a file. I will limit expression of my frustration here and just say that this is not intuitive.
var cannotuseawait = client.Repository.Content.GetAllContents(Repo.Id, basePath);
cannotuseawait.Wait();
var res = cannotuseawait.Result;
Upvotes: 1