Search in sources :

Example 21 with GHRepository

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();
    }
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) GHIssue(org.kohsuke.github.GHIssue) IOException(java.io.IOException)

Example 22 with GHRepository

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;
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub)

Example 23 with GHRepository

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);
        }
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) GitHubUser(org.zaproxy.zap.GitHubUser) GHRepository(org.kohsuke.github.GHRepository) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) GHRepository(org.kohsuke.github.GHRepository) Repository(org.eclipse.jgit.lib.Repository) GHPullRequest(org.kohsuke.github.GHPullRequest) Git(org.eclipse.jgit.api.Git) PersonIdent(org.eclipse.jgit.lib.PersonIdent) File(java.io.File) GitHubRepo(org.zaproxy.zap.GitHubRepo) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

GHRepository (org.kohsuke.github.GHRepository)23 GitHub (org.kohsuke.github.GitHub)15 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)4 GHRelease (org.kohsuke.github.GHRelease)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 Test (org.junit.Test)3 GHContent (org.kohsuke.github.GHContent)3 GHIssue (org.kohsuke.github.GHIssue)3 NextProtException (org.nextprot.api.commons.exception.NextProtException)3 Cacheable (org.springframework.cache.annotation.Cacheable)3 Semver (com.vdurmont.semver4j.Semver)2 HashMap (java.util.HashMap)2 TaskAction (org.gradle.api.tasks.TaskAction)2 GHPullRequest (org.kohsuke.github.GHPullRequest)2 GHTree (org.kohsuke.github.GHTree)2 GHUser (org.kohsuke.github.GHUser)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 BufferedReader (java.io.BufferedReader)1