【问题标题】:creating a github issue in octokit.net在 octokit.net 中创建 github 问题
【发布时间】:2019-08-12 07:30:53
【问题描述】:

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

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

谢谢

【问题讨论】:

    标签: c# octokit.net


    【解决方案1】:

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

    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 您必须将所有文本替换为实际值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-22
      • 1970-01-01
      • 2015-08-30
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 2014-03-04
      相关资源
      最近更新 更多