Reputation: 45
I want to read the contents of a private GitHub repo file and declare the value in a variable in a C# Visual Studio .NET Application. What's easiest the way of going about this?
Upvotes: 2
Views: 1264
Reputation: 1329122
You can call the Get Repository content API from your CSharp program, assuming:
You can see an example here, using var request = (HttpWebRequest)WebRequest.Create("https://api.github.com/repos/$OWNER/$REPO/contents/$PATH");
For example, for a given file https://github.com/VonC/gitw/blob/master/version/version.go
$OWNER
would be VonC
$REPO
would be gitw
$PATH
would be version/version.go
As in:
curl -H "Accept: application/vnd.github.VERSION.raw" https://api.github.com/repos/VonC/gitw/contents/version/version.go
Do use application/vnd.github.VERSION.raw
in your request.Accept
:
request.Accept = "application/vnd.github.VERSION.raw";
That way, you get the content of the file.
Upvotes: 1