Search in sources :

Example 1 with GHTreeEntry

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

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GHRepository (org.kohsuke.github.GHRepository)1 GHTree (org.kohsuke.github.GHTree)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