Octokit.net创建新的存储库 [英] Octokit.net Creating new repository

查看:68
本文介绍了Octokit.net创建新的存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用Octokit.net创建新存储库时遇到问题.

I have a problem with creating new repository with 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/7h63fz我得到ctokit.NotFoundException:未找到.我已经尝试了一切,每次发生错误.我在做什么错了?

I've put breakpoints and there I see that everything is OK. http://prntscr.com/7h62iq which can be seen here. And when I let the program run the code for creating a new repository, this is my result: http://prntscr.com/7h63fz I get ctokit.NotFoundException: Not Found. I have tried everything and each time error occurs. What am I doing wrong?

推荐答案

我认为在 await client.Respository.Create(newRepo); 第60行中存在内部错误./strong>尝试使用 basicAuth 创建具有MIT许可证的存储库的客户端.并使用try catch,查看error.Message(如果有).

I think there is an inner error in the line 60 at await client.Respository.Create(newRepo); Try this to create a client with basicAuth, a repository with a MIT licence. And with the try catch, see the error.Message if any.

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

如果存储库已经存在,则可以删除旧的存储库.警告,此代码肯定会删除存储库,而无需确认.

If the repository already exists, you can remove the old one. Warning, this code definitely remove the repository without confirmation.

// 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.");

这篇关于Octokit.net创建新的存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆