C# OctoKit CreateFile Not found issue

374 views Asked by At

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:

  1. I generated a personal access token
  2. The repo is private
  3. If I put incorrect personal access token I get "Bad Credentials" error. If I put the correct credentials I get the not found error.
2

There are 2 answers

1
Deepak On

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"))
0
Weston Goodwin On

I have decided to use LibGit2Sharp. I was able to get up and running after a few mins.