Search in sources :

Example 1 with GHPullRequest

use of org.kohsuke.github.GHPullRequest in project che by eclipse.

the class GitHubDTOFactory method createPullRequestsList.

/**
     * Create DTO object of GitHub pull-requests collection from given pull-requests
     * @param ghPullRequestsList collection of pull-requests from kohsuke GitHub library
     * @return DTO object
     * @throws IOException
     */
public GitHubPullRequestList createPullRequestsList(PagedIterable<GHPullRequest> ghPullRequestsList) throws IOException {
    GitHubPullRequestList gitHubPullRequestList = DtoFactory.getInstance().createDto(GitHubPullRequestList.class);
    List<GitHubPullRequest> dtoPullRequestsList = new ArrayList<>();
    for (GHPullRequest ghPullRequest : ghPullRequestsList) {
        dtoPullRequestsList.add(createPullRequest(ghPullRequest));
    }
    gitHubPullRequestList.setPullRequests(dtoPullRequestsList);
    return gitHubPullRequestList;
}
Also used : GHPullRequest(org.kohsuke.github.GHPullRequest) ArrayList(java.util.ArrayList) GitHubPullRequestList(org.eclipse.che.plugin.github.shared.GitHubPullRequestList) GitHubPullRequest(org.eclipse.che.plugin.github.shared.GitHubPullRequest)

Example 2 with GHPullRequest

use of org.kohsuke.github.GHPullRequest in project che by eclipse.

the class GitHubService method updatePullRequest.

@PUT
@Path("pullrequest/{user}/{repository}/{pullRequestId}")
@Produces(MediaType.APPLICATION_JSON)
public GitHubPullRequest updatePullRequest(@PathParam("user") String user, @PathParam("repository") String repository, @PathParam("pullRequestId") String pullRequestId, GitHubPullRequest pullRequest) throws ServerException, UnauthorizedException {
    try {
        final GHPullRequest ghPullRequest = gitHubFactory.connect().getUser(user).getRepository(repository).getPullRequest(Integer.valueOf(pullRequestId));
        final String body = pullRequest.getBody();
        if (body != null && !body.equals(ghPullRequest.getBody())) {
            ghPullRequest.setBody(body);
        }
        final String title = pullRequest.getTitle();
        if (title != null && !title.equals(ghPullRequest.getTitle())) {
            ghPullRequest.setTitle(title);
        }
        return gitHubDTOFactory.createPullRequest(ghPullRequest);
    } catch (IOException ioEx) {
        throw new ServerException(ioEx.getMessage());
    }
}
Also used : GHPullRequest(org.kohsuke.github.GHPullRequest) ServerException(org.eclipse.che.api.core.ServerException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 3 with GHPullRequest

use of org.kohsuke.github.GHPullRequest in project repairnator by Spirals-Team.

the class EvaluatePotentialBug method computeScore.

private int computeScore(RepairInfo repairInfo) throws IOException {
    int score = 0;
    GitHub gitHub = GitHubBuilder.fromEnvironment().withOAuthToken(this.githubToken, this.githubLogin).build();
    GHRepository ghRepo = gitHub.getRepository(repairInfo.getGithubProject());
    String commitMsg = ghRepo.getCommit(repairInfo.getPatchCommit()).getCommitShortInfo().getMessage();
    score += this.computeScoreForMessage(commitMsg, 10, 20);
    if (repairInfo.getPrId() != null) {
        GHPullRequest pullRequest = ghRepo.getPullRequest(Integer.parseInt(repairInfo.getPrId()));
        score += this.computeScoreForMessage(pullRequest.getTitle(), 100, 120);
        try {
            for (GHLabel label : pullRequest.getLabels()) {
                score += this.computeScoreForMessage(label.getName(), 100, 120);
            }
        } catch (HttpException e) {
        }
        for (GHIssueComment comment : pullRequest.getComments()) {
            if (comment.getUser().equals(pullRequest.getUser())) {
                score += this.computeScoreForMessage(commitMsg, 10, 20);
            } else {
                score += this.computeScoreForMessage(commitMsg, 1, 2);
            }
        }
    }
    Matcher matcher = ISSUE_PATTERN.matcher(commitMsg);
    List<Integer> issuesOrPr = new ArrayList<>();
    while (matcher.find()) {
        int newIssueOrPRId = Integer.parseInt(matcher.group().substring(1));
        issuesOrPr.add(newIssueOrPRId);
    }
    for (int issueOrPRId : issuesOrPr) {
        GHIssue prOrIssue;
        try {
            prOrIssue = ghRepo.getPullRequest(issueOrPRId);
            if (prOrIssue == null) {
                prOrIssue = ghRepo.getIssue(issueOrPRId);
            }
        } catch (Exception e) {
            prOrIssue = ghRepo.getIssue(issueOrPRId);
        }
        if (prOrIssue != null) {
            score += this.computeScoreForMessage(prOrIssue.getTitle(), 80, 100);
            for (GHIssueComment comment : prOrIssue.getComments()) {
                if (comment.getUserName().equals(prOrIssue.getUser().getLogin())) {
                    score += this.computeScoreForMessage(commitMsg, 10, 20);
                } else {
                    score += this.computeScoreForMessage(commitMsg, 1, 2);
                }
            }
            try {
                for (GHLabel label : prOrIssue.getLabels()) {
                    score += this.computeScoreForMessage(label.getName(), 100, 120);
                }
            } catch (HttpException e) {
            }
        }
    }
    return score;
}
Also used : GHLabel(org.kohsuke.github.GHLabel) GHRepository(org.kohsuke.github.GHRepository) Matcher(java.util.regex.Matcher) PathMatcher(java.nio.file.PathMatcher) GitHub(org.kohsuke.github.GitHub) ArrayList(java.util.ArrayList) GHIssue(org.kohsuke.github.GHIssue) ParseException(org.json.simple.parser.ParseException) HttpException(org.kohsuke.github.HttpException) IOException(java.io.IOException) GHPullRequest(org.kohsuke.github.GHPullRequest) HttpException(org.kohsuke.github.HttpException) GHIssueComment(org.kohsuke.github.GHIssueComment)

Example 4 with GHPullRequest

use of org.kohsuke.github.GHPullRequest 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

GHPullRequest (org.kohsuke.github.GHPullRequest)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 GHRepository (org.kohsuke.github.GHRepository)2 File (java.io.File)1 PathMatcher (java.nio.file.PathMatcher)1 Matcher (java.util.regex.Matcher)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ServerException (org.eclipse.che.api.core.ServerException)1 GitHubPullRequest (org.eclipse.che.plugin.github.shared.GitHubPullRequest)1 GitHubPullRequestList (org.eclipse.che.plugin.github.shared.GitHubPullRequestList)1 Git (org.eclipse.jgit.api.Git)1 PersonIdent (org.eclipse.jgit.lib.PersonIdent)1 Repository (org.eclipse.jgit.lib.Repository)1 FileRepositoryBuilder (org.eclipse.jgit.storage.file.FileRepositoryBuilder)1 URIish (org.eclipse.jgit.transport.URIish)1 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)1 TaskAction (org.gradle.api.tasks.TaskAction)1