5

I want to create issue over GitHub using java EGIT API.

I have tried it:

GitHubClient client = new GitHubClient().setCredentials("abc", "xyz");

IssueService service = new IssueService(client);

Repository repo = new Repository();
maskacovnik
  • 3,080
  • 5
  • 20
  • 26
  • 1
    I think this feature would be incredibly useful for error reporting in applications. Too bad you need an account to do it. – SirMathhman Nov 08 '17 at 14:08

1 Answers1

1

I was able to achieve this using EGit 2.1.5. Here are the steps I took:

  1. I created a Personal Access Token in the project https://github.com/settings/tokens. When creating the Token, specify the scope to your needs. For my case (just Issue creation), I opted for repo scope. enter image description here

Sweet, now that we have our token let's jump into the code.

GitHubClient client = new GitHubClient();
client.setOAuth2Token("PUT_YOUR_PERSONAL_ACCESS_TOKEN_HERE"); // Use the token generated above
IssueService issueService = new IssueService(client);
try {
    Issue issue = new Issue();
    issue.setTitle("Test issue"); // Title of the issue
    issue.setBody("Some stuff"); // Body of the issue
    // Other stuff can be included in the Issue as you'd expect .. like labels, authors, dates, etc. 
    // Check out the API per your needs
    
    // In my case, we utilize a private issue-only-repository "RepositoryIssueTracker" that is maintainted under our Organization "MyCompany"
    issueService.createIssue("MyCompany", "RepositoryIssueTracker", issue);
} catch (Exception e) {
    System.out.println("Failed");
    e.printStackTrace();
}

Summary: I think OP's issue was related to not providing proper credentials, possibly to a private repo. I also was unable to get Basic auth working with a username/password to our private repo (possibly because our organization requires 2-factor). Instead, using a Personal Access Token Authorization worked per the above instructions.

More info on creating an issue-only repository can be found here.

VILLAIN bryan
  • 701
  • 5
  • 24