Search code examples
c#octokit.net

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


Solution

  • 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.