'C# OctoKit CreateFile Not found issue
I trying to commit a file to a github repo using C# and OctoKit using the following code:
static async void CommitFile()
{
var ghClient = new GitHubClient(new ProductHeaderValue("Octokit-Test"));
ghClient.Credentials = new Credentials("//...//");
// github variables
var owner = "owner";
var repo = "repo";
var branch = "main";
// create file
var createChangeSet = await ghClient.Repository.Content.CreateFile(owner,repo, "file2.txt",new CreateFileRequest("File creation", "Hello World!", branch));
}
Whenever I execute it I get:
Octokit.NotFoundException: 'Not Found'
Here are the following things I want to mention:
- I generated a personal access token
- The repo is private
- If I put incorrect personal access token I get "Bad Credentials" error. If I put the correct credentials I get the not found error.
Solution 1:[1]
var gitHubClient = new GitHubClient(new ProductHeaderValue(repoName)); gitHubClient.Credentials = new Credentials(authorizedKey);
var path = "test.txt";
var resp = await gitHubClient.Repository.Content.CreateFile(owner, repoName, path, new CreateFileRequest($"First commit ", "Hello World" , "BranchName"))
Solution 2:[2]
I have decided to use LibGit2Sharp. I was able to get up and running after a few mins.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Deepak |
| Solution 2 | Weston Goodwin |
