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;
}
Aggregations