Search in sources :

Example 1 with GitHub

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

the class UpdateUtils method getVersion.

public static String getVersion() {
    try {
        GitHub gitHub = GitHub.connectAnonymously();
        GHRepository repository = gitHub.getRepository(CONSTANTS.GITHUB_URI);
        GHRelease latest = repository.getLatestRelease();
        return latest.getTagName().replaceAll("v", "");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) IOException(java.io.IOException) GHRelease(org.kohsuke.github.GHRelease)

Example 2 with GitHub

use of org.kohsuke.github.GitHub in project Gargoyle by callakrsos.

the class GitTest method getGargoyleRepository.

@Test
public void getGargoyleRepository() throws IOException {
    GitHub github = GitHub.connect();
    GHUser user = github.getUser("callakrsos");
    Map<String, GHRepository> repositories = user.getRepositories();
    //Repository를 모두 출력
    Iterator<Entry<String, GHRepository>> iterator = repositories.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, GHRepository> next = iterator.next();
        System.out.println(next.getKey() + " - " + next.getValue().getName());
    }
    //Gargoyle Repository 정보 출력
    GHRepository repository = user.getRepository("Gargoyle");
    System.out.println(repository);
    List<GHContent> directoryContent = repository.getDirectoryContent("/");
    //루트 디렉토리 정보 출력
    directoryContent.forEach(con -> {
        System.out.println(String.format("Path : %s\t\t\tsize : %d\t\t\t\tUrl:%s ", con.getPath(), con.getSize(), con.getUrl()));
    });
}
Also used : Entry(java.util.Map.Entry) GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) GHContent(org.kohsuke.github.GHContent) GHUser(org.kohsuke.github.GHUser) Test(org.junit.Test)

Example 3 with GitHub

use of org.kohsuke.github.GitHub 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 4 with GitHub

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

the class UpdateUtils method getInfo.

public static GitHubReleaseInfo getInfo() {
    GitHubReleaseInfo info = GitHubReleaseInfo.builder().build();
    try {
        GitHub gitHub = GitHub.connectAnonymously();
        GHRepository repository = gitHub.getRepository(CONSTANTS.GITHUB_URI);
        GHRelease latest = repository.getLatestRelease();
        String version = latest.getTagName().replaceAll("v", "");
        info.setVersion(version);
        info.setMessage(latest.getBody());
        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", ""));
        } else {
            Logger.info("detected new version");
            Logger.info("current version: " + CONSTANTS.VERSION);
            Logger.info("latest version: " + latest.getTagName().replaceAll("v", ""));
            info.setAvailable(true);
        }
        return info;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return info;
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) Semver(com.vdurmont.semver4j.Semver) GHRelease(org.kohsuke.github.GHRelease)

Example 5 with GitHub

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

GitHub (org.kohsuke.github.GitHub)21 GHRepository (org.kohsuke.github.GHRepository)17 IOException (java.io.IOException)10 Test (org.junit.Test)5 GHRelease (org.kohsuke.github.GHRelease)5 Semver (com.vdurmont.semver4j.Semver)4 File (java.io.File)3 ArrayList (java.util.ArrayList)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 FileInputStream (java.io.FileInputStream)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 GHAsset (org.kohsuke.github.GHAsset)2 GHUser (org.kohsuke.github.GHUser)2 HttpException (org.kohsuke.github.HttpException)2 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)1 ServiceException (io.jenkins.blueocean.commons.ServiceException)1