Search in sources :

Example 1 with GHTree

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

the class GitHubServiceImpl method getNews.

@Override
@Cacheable(value = "github-news")
public List<NextProtNews> getNews() {
    List<NextProtNews> news = new ArrayList<>();
    try {
        GitHub github = getGitHubConnection();
        GHRepository repo = github.getRepository("calipho-sib/nextprot-docs");
        GHTree tree = repo.getTreeRecursive(githubDocBranch, 1);
        newsFileNames.clear();
        for (GHTreeEntry te : tree.getTree()) {
            if (te.getPath().startsWith("news")) {
                // Add only file on news
                if (te.getType().equalsIgnoreCase("blob")) {
                    // file
                    String fileName = te.getPath().replaceAll("news/", "");
                    NextProtNews n = parseGitHubNewsFilePath(fileName);
                    if (n != null) {
                        news.add(n);
                        String fileEncoded = URLEncoder.encode(fileName.replace(".md", ""), "UTF-8").replace("+", "%20");
                        newsFileNames.put(n.getUrl(), fileEncoded);
                    }
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new NextProtException("News not available, sorry for the inconvenience");
    }
    Collections.sort(news);
    return news;
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) ArrayList(java.util.ArrayList) GHTree(org.kohsuke.github.GHTree) IOException(java.io.IOException) NextProtNews(org.nextprot.api.web.domain.NextProtNews) GHTreeEntry(org.kohsuke.github.GHTree.GHTreeEntry) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 2 with GHTree

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

IOException (java.io.IOException)2 GHRepository (org.kohsuke.github.GHRepository)2 GHTree (org.kohsuke.github.GHTree)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 GHBranch (org.kohsuke.github.GHBranch)1 GHTreeEntry (org.kohsuke.github.GHTree.GHTreeEntry)1 GitHub (org.kohsuke.github.GitHub)1 NextProtException (org.nextprot.api.commons.exception.NextProtException)1 NextProtNews (org.nextprot.api.web.domain.NextProtNews)1 Cacheable (org.springframework.cache.annotation.Cacheable)1