我在使用 Octokit.net 创建新存储库时遇到问题。
这是我的代码:
public async Task stvoriNovi(FormCollection collection)
{
string name = collection.Get("name");
NewRepository newRepo = new NewRepository(name);
newRepo.AutoInit = true;
var accessToken = Session["OAuthToken"] as string;
if (accessToken != null)
{
client.Credentials = new Credentials(accessToken);
}
await client.Repository.Create(newRepo);
}
我设置了断点,发现一切正常。http://prntscr.com/7h62iq http://prntscr.com/7h62iq可以在这里看到。当我让程序运行创建新存储库的代码时,这是我的结果:http://prntscr.com/7h63fz http://prntscr.com/7h63fz我得到 ctokit.NotFoundException:未找到。我已经尝试了所有方法,但每次都会出现错误。我究竟做错了什么?
我认为存在内部错误line 60 at 等待 client.Repository.Create(new Repo);尝试创建一个客户端基本验证,一个拥有 MIT 许可证的存储库。
并使用 try catch 查看错误消息(如果有)。
using Octokit;
// Authentification
var basicAuth = new Credentials(Owner, Password);
var Client = new GitHubClient(new ProductHeaderValue("my-cool-app"));
Client.Credentials = basicAuth;
// Create
try {
var repository = new NewRepository(RepositoryName) {
AutoInit = false,
Description = "",
LicenseTemplate = "mit",
Private = false
};
var context = Client.Repository.Create(repository);
RespositoryGitHub = context.Result;
Console.WriteLine($"The respository {RepositoryName} was created.");
} catch (AggregateException e) {
Console.WriteLine($"E: For some reason, the repository {RepositoryName} can't be created. It may already exist. {e.Message}");
}
}
如果存储库已存在,您可以删除旧的存储库。警告,这段代码确实删除存储库而不确认。
// Remove the previous repository if exists
var contextDelete = Client.Repository.Get(Owner, RepositoryName).Result;
var repositoryID = contextDelete.Id;
var context = Client.Repository.Delete(repositoryID);
Console.WriteLine($"The respository {RepositoryName} was deleted.");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)