在 octokit.net 中创建了一个 github 问题

creating a github issue in octokit.net

我正在尝试编写一个脚本来打开在控制台中输入的问题。

出于某种原因,issue 变量在调试器中返回为空。

class Program
{
    public async static Task Main()
    {
        var client = new GitHubClient(new ProductHeaderValue("test-app"));
        var user = await client.User.Get("medic17");
        var tokenAuth = new Credentials(APIKeys.GithubPersinalAccessToken);
        client.Credentials = tokenAuth;

        var exampleIssue = new NewIssue("test body");
        var issue = await client.Issue.Create("owner","name", exampleIssue);

    }
}

APIKeys 持有我的令牌。

谢谢

我找到了解决方案,希望这对其他人也有帮助。

class Program
{
    public async static Task Main()
    {
        // client initialization and authentication 
        var client = new GitHubClient(new ProductHeaderValue("<anything>"));
        var user = await client.User.Get("<user>");
        var tokenAuth = new Credentials(APIKeys.GithubPersinalAccessToken);
        client.Credentials = tokenAuth;


        // user input
        Console.WriteLine("Give a title for your issue: ");
        string userIssueTitle = Console.ReadLine().Trim();

        Console.WriteLine("Describe your issue:", Environment.NewLine);
        string userIssue = Console.ReadLine().Trim();

        // input validation
        while (string.IsNullOrEmpty(userIssue) || string.IsNullOrEmpty(userIssueTitle))
        {
            Console.WriteLine("ERROR: Both fields must contain text");
            Console.ReadLine();
            break;

        }

        var newIssue = new NewIssue(userIssueTitle) { Body = userIssue };
        var issue = await client.Issue.Create(<owner>, <repo> newIssue);

        var issueId = issue.Id;

        Console.WriteLine($"SUCCESS: your issue id is {issueId} ");
        Console.ReadLine();


    }
}

备注 您需要将您的密钥存储在一个单独的文件中并为其编写一个 class,这样您的身份验证流程可能会有所不同。

注2 您必须用实际值替换所有文本。