0
votes

Im working on a small school project where i need to update an file from my github repo. Everything worked fine until i got an error out of nowhere. I am using Octokit .net with a C# WPF Application. Here the Exception:

Octokit.ApiException: "is at 1ce907108c4582d5a0986d3a37b2777e271a0105 but expected 47fa57debd39ee6a63f24d39e9513f87814a5ed6"

I dont know why this error shows up, because i didn't change anything before the error happend and now nothing works anymore. Can someone help me with this? Here the code:

private static async void UpdateFile(string fileName, string fileContent)
{
    var ghClient = new GitHubClient(new ProductHeaderValue(HEADER));
    ghClient.Credentials = new Credentials(API_KEY);

    // github variables
    var owner = OWNER;
    var repo = REPO;
    var branch = "main";

    var targetFile = fileName;

    try
    {
        // try to get the file (and with the file the last commit sha)
        var existingFile = await ghClient.Repository.Content.GetAllContentsByRef(owner, repo, targetFile, branch);

        // update the file
        var updateChangeSet = await ghClient.Repository.Content.UpdateFile(owner, repo, targetFile,
           new UpdateFileRequest("API Config Updated", fileContent, existingFile.First().Sha, branch));
    }
    catch (Octokit.NotFoundException)
    {
        // if file is not found, create it
        var createChangeSet = await ghClient.Repository.Content.CreateFile(owner, repo, targetFile, new CreateFileRequest("API Config Created", fileContent, branch));
    }
}