I am trying to develop a windows forms application that can create, update and delete files in a GitHub repository using Octokit.
public Form1()
{
InitializeComponent();
var ghClient = new GitHubClient(new ProductHeaderValue("Octokit-Test"));
ghClient.Credentials = new Credentials("-personal access token here-");
// github variables
var owner = "username";
var repo = "repository name";
var branch = "master";
// create file
//var createChangeSet = ghClient.Repository.Content.CreateFile(owner,repo,"path/file2.txt",new CreateFileRequest("File creation", "Hello World!", branch));
// update file
var updateChangeSet = ghClient.Repository.Content.UpdateFile(owner, repo,"path/file2.txt", new UpdateFileRequest("File update","Hello Universe!", "SHA value should be here", branch));
}
Firstly, I managed to create a file (check the commented out code), which is fully functional. Then I tried to update that file using,
var updateChangeSet = ghClient.Repository.Content.UpdateFile(owner, repo,"path/file2.txt", new UpdateFileRequest("File update","Hello Universe!", "SHA value should be here", branch));
As you can see, in this situation, I have to get the sha value since the requirement for the "UpdateFileRequest" is,
UpdateFileRequest(string message, string content, string sha, string branch)
How can I receive this Sha value for my file from GitHub?
I am following this tutorial but when I try "createChangeSet.Content.Sha"(without commenting out createChangeSet), it draws a red line underneath "Content" and says,
Task<RepositoryChangeSet> does not contain a definition for 'Content' and no extention method 'Content' accepting a first argument of type Task<RepositoryChangeSet> could be found
I looked at GitHub Documentation and it says I should use,
GET /repos/:owner/:repo/contents/:path
to return the contents of a file or directory in a repository so I assume I will be able to obtain the sha value this way.
How can I implement this method to receive the sha value for my file in the repository so I can use that value to update the file?