public void process(Exchange exchange) throws Exception { Issue issue = new Issue(); String issueTitle = exchange.getIn().getHeader(GitHubConstants.GITHUB_ISSUE_TITLE, String.class); if (ObjectHelper.isEmpty(issueTitle)) { throw new IllegalArgumentException("Issue Title must be specified to create an issue"); } issue.setTitle(issueTitle); issue.setBody(exchange.getIn().getBody(String.class)); Issue finalIssue = issueService.createIssue(getRepository(), issue); // copy the header of in message to the out message exchange.getOut().copyFrom(exchange.getIn()); exchange.getOut().setBody(finalIssue); }
/** * Turns collected information of an error into a new (offline) GitHub issue * * @param details A map of the information. Note that I remove items from there when they should not go in the issue * body as well. When creating the body, all remaining items are iterated. * @return The new issue */ private static Issue createNewGibHubIssue(LinkedHashMap<String, String> details) { String errorMessage = details.get("error.message"); if (errorMessage == null || errorMessage.isEmpty()) { errorMessage = "Unspecified error"; } details.remove("error.message"); String errorHash = details.get("error.hash"); if (errorHash == null) { errorHash = ""; } details.remove("error.hash"); final Issue gitHubIssue = new Issue(); final String body = generateGitHubIssueBody(details, true); gitHubIssue.setTitle(ErrorReportBundle.message("git.issue.title", errorHash, errorMessage)); gitHubIssue.setBody(body); Label label = new Label(); label.setName(issueLabel); gitHubIssue.setLabels(Collections.singletonList(label)); return gitHubIssue; }
@Override @Result protected String doInBackground(Void... params) { GitHubClient client; if (login.shouldUseApiToken()) { client = new GitHubClient().setOAuth2Token(login.getApiToken()); } else { client = new GitHubClient().setCredentials(login.getUsername(), login.getPassword()); } Issue issue = new Issue().setTitle(report.getTitle()).setBody(report.getDescription()); try { new IssueService(client).createIssue(target.getUsername(), target.getRepository(), issue); return RESULT_OK; } catch (RequestException e) { switch (e.getStatus()) { case STATUS_BAD_CREDENTIALS: if (login.shouldUseApiToken()) return RESULT_INVALID_TOKEN; return RESULT_BAD_CREDENTIALS; case STATUS_ISSUES_NOT_ENABLED: return RESULT_ISSUES_NOT_ENABLED; default: e.printStackTrace(); return RESULT_UNKNOWN; } } catch (IOException e) { e.printStackTrace(); return RESULT_UNKNOWN; } }