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();
I was able to achieve this using EGit 2.1.5. Here are the steps I took:
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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With