1

我正在尝试编写一个脚本,该脚本将打开在控制台中键入的问题。

由于某种原因,该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 持有我的令牌。

谢谢

4

1 回答 1

0

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

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


    }
}

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

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

于 2019-08-15T12:20:49.137 回答