Search in sources :

Example 16 with GHRepository

use of org.kohsuke.github.GHRepository in project Robot by fo0.

the class UpdateUtils method isAvailable.

public static boolean isAvailable() {
    try {
        GitHub gitHub = GitHub.connectAnonymously();
        GHRepository repository = gitHub.getRepository(CONSTANTS.GITHUB_URI);
        GHRelease latest = repository.getLatestRelease();
        boolean newerVersionAvailable = new Semver(latest.getTagName().replaceAll("v", "")).isGreaterThan(new Semver(CONSTANTS.VERSION));
        if (!newerVersionAvailable) {
            Logger.info("no newer version available, skipping now");
            Logger.info("current version: " + CONSTANTS.VERSION);
            Logger.info("latest version: " + latest.getTagName().replaceAll("v", ""));
            return false;
        } else {
            Logger.info("detected new version");
            Logger.info("current version: " + CONSTANTS.VERSION);
            Logger.info("latest version: " + latest.getTagName().replaceAll("v", ""));
            return true;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) IOException(java.io.IOException) Semver(com.vdurmont.semver4j.Semver) GHRelease(org.kohsuke.github.GHRelease)

Example 17 with GHRepository

use of org.kohsuke.github.GHRepository in project nextprot-api by calipho-sib.

the class GitHubServiceImpl method getTree.

@Override
@Cacheable(value = "github-tree")
public GHTree getTree() {
    try {
        GitHub github = getGitHubConnection();
        GHRepository repo = github.getRepository("calipho-sib/nextprot-docs");
        return repo.getTreeRecursive(githubDocBranch, 1);
    } catch (IOException e) {
        e.printStackTrace();
        throw new NextProtException("Documentation not available, sorry for the inconvenience");
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) IOException(java.io.IOException) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 18 with GHRepository

use of org.kohsuke.github.GHRepository in project nextprot-api by calipho-sib.

the class GitHubServiceImpl method getPage.

@Override
@Cacheable(value = "github-pages")
public String getPage(String folder, String page) {
    String finalPage = page;
    if ("news".equalsIgnoreCase(folder)) {
        finalPage = getCorrespondingPageForNews(page);
    }
    try {
        GitHub github = getGitHubConnection();
        GHRepository repo = github.getRepository("calipho-sib/nextprot-docs");
        GHContent content = null;
        String extension = ".md";
        if (folder.contains("json")) {
            // if folder contains json
            extension = ".json";
        }
        content = repo.getFileContent(folder + "/" + finalPage + extension, githubDocBranch);
        return content.getContent();
    } catch (IOException e) {
        e.printStackTrace();
        throw new NextProtException("Documentation not available, sorry for the inconvenience");
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) GHContent(org.kohsuke.github.GHContent) IOException(java.io.IOException) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 19 with GHRepository

use of org.kohsuke.github.GHRepository 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 20 with GHRepository

use of org.kohsuke.github.GHRepository in project faber by mkuschov.

the class GitLoader method GetWatchedReposTrees.

public HashMap<GHRepository, HashMap<GHBranch, GHTree>> GetWatchedReposTrees() {
    HashMap<GHRepository, HashMap<GHBranch, GHTree>> watchedReposTrees = new HashMap<>();
    this.watchedRepos.forEach(i -> {
        HashMap<GHBranch, GHTree> tmp = new HashMap<>();
        try {
            i.getBranches().forEach((name, branch) -> {
                try {
                    GHTree urlToBracnhTree = i.getTreeRecursive(branch.getSHA1(), 1);
                    tmp.put(branch, urlToBracnhTree);
                    System.out.println(i.getName() + "    " + branch.getName() + "    " + urlToBracnhTree.toString());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
            watchedReposTrees.put(i, tmp);
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
    return watchedReposTrees;
}
Also used : GHRepository(org.kohsuke.github.GHRepository) HashMap(java.util.HashMap) GHTree(org.kohsuke.github.GHTree) GHBranch(org.kohsuke.github.GHBranch) IOException(java.io.IOException)

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