Search in sources :

Example 1 with GHIssueComment

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

Aggregations

IOException (java.io.IOException)1 PathMatcher (java.nio.file.PathMatcher)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 ParseException (org.json.simple.parser.ParseException)1 GHIssue (org.kohsuke.github.GHIssue)1 GHIssueComment (org.kohsuke.github.GHIssueComment)1 GHLabel (org.kohsuke.github.GHLabel)1 GHPullRequest (org.kohsuke.github.GHPullRequest)1 GHRepository (org.kohsuke.github.GHRepository)1 GitHub (org.kohsuke.github.GitHub)1 HttpException (org.kohsuke.github.HttpException)1