I have a file in a private GitHub repository that contains several properties, such as ‘status=operational’. How can I verify that the ‘status’ property is correctly set to ‘operational’?
Is there an API or library available that can read and verify the content of a file stored in a GitHub repository?
>Solution :
For a private repository try this
private static readonly string SERVER_URL = $"https://raw.githubusercontent.com/{GITHUB_OWNER}/{GITHUB_REPO}/main/";
private static string GetFileContentFromGitHub(string fileName)
{
var webRequest = (HttpWebRequest)WebRequest.Create(SERVER_URL + fileName);
webRequest.Headers.Add(HttpRequestHeader.Authorization, "token " + GITHUB_TOKEN);
webRequest.Method = "GET";
using (var response = webRequest.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
}
You can create a GitHub token under the developer settings.