简体   繁体   中英

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:

  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.

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"))

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM