Search in sources :

Example 1 with GHIssue

use of org.kohsuke.github.GHIssue in project Rubicon by Rubicon-Bot.

the class CommandFeedback 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("Enhancement").label("Up for grabs").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 2 with GHIssue

use of org.kohsuke.github.GHIssue in project Ublisk by Derkades.

the class GitHubCommand method onCommand.

@Override
protected void onCommand(UPlayer player, String[] args) {
    if (args.length == 0) {
        player.sendMessage("Wrong usage: /u " + this.getAliases()[0] + " [description]");
        return;
    }
    final String description = String.join(" ", args);
    new URunnable() {

        public void run() {
            try {
                GHIssue issue = GitHubModule.createIssue(player.getName(), description);
                player.sendMessage(Ublisk.getPrefix() + "Your message has been recorded. We'll take a look at it soon! View your issue at " + issue.getHtmlUrl());
            } catch (IOException e) {
                player.sendMessage(ChatColor.RED + "An error has occured :(");
                e.printStackTrace();
            }
        }
    }.runAsync();
}
Also used : URunnable(xyz.derkades.ublisk.utils.URunnable) GHIssue(org.kohsuke.github.GHIssue) IOException(java.io.IOException)

Example 3 with GHIssue

use of org.kohsuke.github.GHIssue in project contribution by checkstyle.

the class TemplateProcessorTest method getMockGithubIssue.

private static GHIssue getMockGithubIssue(int issueNo, String issueTitle) throws IllegalAccessException, NoSuchFieldException {
    final GHIssue issue = new GHIssue();
    final Field title = issue.getClass().getDeclaredField("title");
    title.setAccessible(true);
    title.set(issue, issueTitle);
    final Field number = issue.getClass().getDeclaredField("number");
    number.setAccessible(true);
    number.set(issue, issueNo);
    return issue;
}
Also used : Field(java.lang.reflect.Field) GHIssue(org.kohsuke.github.GHIssue)

Example 4 with GHIssue

use of org.kohsuke.github.GHIssue in project contribution by checkstyle.

the class NotesBuilder method buildResult.

/**
 * Forms release notes as a map.
 * @param remoteRepo git remote repository object.
 * @param localRepoPath path to local git repository.
 * @param startRef start reference.
 * @param endRef end reference.
 * @return a map which represents release notes.
 * @throws IOException if an I/O error occurs.
 * @throws GitAPIException if an error occurs when accessing Git API.
 */
public static Result buildResult(GHRepository remoteRepo, String localRepoPath, String startRef, String endRef) throws IOException, GitAPIException {
    final Result result = new Result();
    final Set<RevCommit> commitsForRelease = getCommitsBetweenReferences(localRepoPath, startRef, endRef);
    commitsForRelease.removeAll(getIgnoredCommits(commitsForRelease));
    final Set<Integer> processedIssueNumbers = new HashSet<>();
    for (RevCommit commit : commitsForRelease) {
        String commitMessage = commit.getFullMessage();
        if (isRevertCommit(commitMessage)) {
            System.out.println(commitMessage);
            final int firstQuoteIndex = commitMessage.indexOf('"');
            final int lastQuoteIndex = commitMessage.lastIndexOf('"');
            commitMessage = commitMessage.substring(firstQuoteIndex, lastQuoteIndex);
        }
        if (isIssueOrPull(commitMessage)) {
            final int issueNo = getIssueNumberFrom(commitMessage);
            if (processedIssueNumbers.contains(issueNo)) {
                continue;
            }
            processedIssueNumbers.add(issueNo);
            final GHIssue issue = remoteRepo.getIssue(issueNo);
            if (issue.getState() != GHIssueState.CLOSED) {
                result.addWarning(String.format("[WARN] Issue #%d \"%s\" is not closed!", issueNo, issue.getTitle()));
            }
            final String issueLabel = getIssueLabelFrom(issue);
            if (issueLabel.isEmpty()) {
                final String error = String.format("[ERROR] Issue #%d does not have %s label!", issueNo, Arrays.stream(Constants.ISSUE_LABELS).collect(Collectors.joining(SEPARATOR)));
                result.addError(error);
            }
            final Set<RevCommit> issueCommits = getCommitsForIssue(commitsForRelease, issueNo);
            final String authors = getAuthorsOf(issueCommits);
            final ReleaseNotesMessage releaseNotesMessage = new ReleaseNotesMessage(issue, authors);
            result.putReleaseNotesMessage(issueLabel, releaseNotesMessage);
        } else {
            // Commits that have messages which do not contain issue or pull number
            final String commitShortMessage = commit.getShortMessage();
            final String author = commit.getAuthorIdent().getName();
            final ReleaseNotesMessage releaseNotesMessage = new ReleaseNotesMessage(commitShortMessage, author);
            result.putReleaseNotesMessage(Constants.MISCELLANEOUS_LABEL, releaseNotesMessage);
        }
    }
    return result;
}
Also used : GHIssue(org.kohsuke.github.GHIssue) RevCommit(org.eclipse.jgit.revwalk.RevCommit) HashSet(java.util.HashSet)

Example 5 with GHIssue

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

GHIssue (org.kohsuke.github.GHIssue)7 IOException (java.io.IOException)4 GHRepository (org.kohsuke.github.GHRepository)3 GitHub (org.kohsuke.github.GitHub)3 ArrayList (java.util.ArrayList)2 Field (java.lang.reflect.Field)1 PathMatcher (java.nio.file.PathMatcher)1 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 ParseException (org.json.simple.parser.ParseException)1 GHIssueComment (org.kohsuke.github.GHIssueComment)1 GHLabel (org.kohsuke.github.GHLabel)1 GHPullRequest (org.kohsuke.github.GHPullRequest)1 HttpException (org.kohsuke.github.HttpException)1 URunnable (xyz.derkades.ublisk.utils.URunnable)1