简体   繁体   中英

creating a github issue in octokit.net

I am trying to write a script that will open an issue typed in the console.

For some reason the issue variable comes back empty in the debugger.

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 holds my token.

Thanks

I found a solution hope this helps someone else as well.

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


    }
}

Note You need to store your keys in a separate file and write a class for it so your authentication flow might be different.

Note 2 You must replace all text with real values.

Still a little confused the app is OpenSource for transport since it deals with HIPPA data, users who want to use it need GitHub account if they want to do any error reporting. I assume I don't share the authToken in the source of the project but the desktop Binary needs it plus the users GitHub login and password. Any pointers? I have tried just using username password that gets entered when creating issue but that fails with “not found”. It seems like any secret that gets deployed with binary app is potentially an issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM