Octokit API 异常:"is at xx but expected yy"



我正在做一个小的学校项目,我需要从我的github仓库更新一个文件。一切都很好,直到我得到了一个错误。我正在使用。net与c# WPF应用程序。这里的异常:

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

我不知道为什么这个错误出现,因为我没有改变任何错误发生之前,现在没有任何工作了有人能帮我一下吗?下面的代码是:

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));
}
}

我在做了一些实验后发现了这个问题。我同时更新了3个文件,结果发现Octokit不能同时处理1个以上的请求…

如果你也被这个问题困住了,就在发布新请求之前增加2秒的延迟。

相关内容

最新更新