use of org.kohsuke.github.GHRepository in project Rubicon by Rubicon-Bot.
the class CommandGitBug method handle.
public static void handle(MessageReceivedEvent event) {
if (!reportMap.containsKey(event.getAuthor().getIdLong())) {
return;
}
ReportHolder reportHolder = reportMap.get(event.getAuthor().getIdLong());
if (event.getMessage().getContentDisplay().contains(reportHolder.title))
return;
if (!event.getTextChannel().getId().equals(reportHolder.textChannel.getId()))
return;
String description = event.getMessage().getContentDisplay();
try {
GitHub gitHub = GitHub.connectUsingOAuth(Info.GITHUB_TOKEN);
GHRepository repository = gitHub.getOrganization("Rubicon-Bot").getRepository("Rubicon");
GHIssue issue = repository.createIssue(reportHolder.title).body(ISSUE_HEADER + event.getAuthor().getName() + "#" + event.getAuthor().getDiscriminator() + ISSUE_SUFFIX + description).label("Bug").label("Requires Testing").create();
reportHolder.delete(issue.getHtmlUrl().toString());
event.getMessage().delete().queue();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.kohsuke.github.GHRepository in project contribution by checkstyle.
the class Main method runNotesBuilder.
/**
* Executes NotesBuilder based on passed command line options.
* @param cliOptions command line options.
* @return result of NotesBuilder work.
* @throws IOException if an I/O error occurs.
* @throws GitAPIException if an error occurs while accessing GitHub API.
*/
private static Result runNotesBuilder(CliOptions cliOptions) throws IOException, GitAPIException {
final String localRepoPath = cliOptions.getLocalRepoPath();
final String startRef = cliOptions.getStartRef();
final String endRef = cliOptions.getEndRef();
final String authToken = cliOptions.getAuthToken();
final GitHub connection;
if (authToken == null) {
connection = GitHub.connectAnonymously();
} else {
connection = GitHub.connectUsingOAuth(authToken);
}
final GHRepository remoteRepo = connection.getRepository(REMOTE_REPO_PATH);
final Result result = NotesBuilder.buildResult(remoteRepo, localRepoPath, startRef, endRef);
if (result.hasWarnings()) {
printListOf(result.getWarningMessages());
}
if (result.hasErrors()) {
printListOf(result.getErrorMessages());
}
return result;
}
use of org.kohsuke.github.GHRepository in project zaproxy by zaproxy.
the class CreatePullRequest method pullRequest.
@TaskAction
public void pullRequest() throws Exception {
GitHubRepo ghRepo = getRepo().get();
Repository repository = new FileRepositoryBuilder().setGitDir(new File(ghRepo.getDir(), ".git")).build();
try (Git git = new Git(repository)) {
if (git.status().call().getModified().isEmpty()) {
return;
}
GitHubUser ghUser = getUser().get();
URIish originUri = new URIish(GITHUB_BASE_URL + ghUser.getName() + "/" + ghRepo.getName());
git.remoteSetUrl().setRemoteName(GIT_REMOTE_ORIGIN).setRemoteUri(originUri).call();
git.checkout().setCreateBranch(true).setName(getBranchName().get()).setStartPoint(GIT_REMOTE_ORIGIN + "/" + baseBranchName.get()).call();
PersonIdent personIdent = new PersonIdent(ghUser.getName(), ghUser.getEmail());
git.commit().setAll(true).setSign(false).setAuthor(personIdent).setCommitter(personIdent).setMessage(getCommitSummary().get() + "\n\n" + getCommitDescription().get() + signedOffBy(personIdent)).call();
git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(ghUser.getName(), ghUser.getAuthToken())).setForce(true).add(getBranchName().get()).call();
GHRepository ghRepository = GitHub.connect(ghUser.getName(), ghUser.getAuthToken()).getRepository(ghRepo.toString());
List<GHPullRequest> pulls = ghRepository.queryPullRequests().base(baseBranchName.get()).head(ghUser.getName() + ":" + getBranchName().get()).state(GHIssueState.OPEN).list().asList();
String description = getPullRequestDescription().getOrElse(getCommitDescription().get());
if (pulls.isEmpty()) {
String title = getPullRequestTitle().getOrElse(getCommitSummary().get());
createPullRequest(ghRepository, title, description);
} else {
pulls.get(0).setBody(description);
}
}
}
Aggregations