Search in sources :

Example 6 with GHRepository

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

use of org.kohsuke.github.GHRepository in project repairnator by Spirals-Team.

the class CheckIfIdsHaveABranch method main.

public static void main(String[] args) throws IOException {
    List<String> allIds = Files.readAllLines(new File(args[0]).toPath());
    String ghLogin = args[1];
    String ghToken = args[2];
    GitHub gitHub = GitHubBuilder.fromEnvironment().withOAuthToken(ghToken, ghLogin).build();
    GHRepository repo = gitHub.getRepository("surli/bugs-collection");
    Set<String> branchNames = repo.getBranches().keySet();
    Map<String, String> branchById = new HashMap<>();
    for (String branchName : branchNames) {
        String[] splitted = branchName.split("-");
        if (splitted.length > 1) {
            String key = "";
            for (int i = 0; i < splitted.length - 2; i++) {
                key += splitted[i];
                if (i < splitted.length - 3) {
                    key += "-";
                }
            }
            branchById.put(key, branchName);
        }
    }
    List<String> branchToDelete = new ArrayList<>();
    String slug = null;
    for (String line : allIds) {
        if (line.startsWith("Project")) {
            String[] splitted = line.split(" ");
            slug = splitted[1];
        } else {
            String key = slug + "-" + line.trim();
            if (branchById.containsKey(key)) {
                System.out.println(key + " -> " + branchById.get(key));
                branchToDelete.add(branchById.get(key));
            }
        }
    }
}
Also used : GHRepository(org.kohsuke.github.GHRepository) HashMap(java.util.HashMap) GitHub(org.kohsuke.github.GitHub) ArrayList(java.util.ArrayList) File(java.io.File)

Example 8 with GHRepository

use of org.kohsuke.github.GHRepository in project sts4 by spring-projects.

the class DefaultGithubInfoProvider method getOwners.

@Override
public Collection<String> getOwners() throws Exception {
    if (connectionError != null) {
        throw connectionError;
    }
    if (github != null) {
        if (owners == null) {
            ImmutableSet.Builder<String> owners = ImmutableSet.builder();
            for (GHRepository repo : github.getMyself().listRepositories()) {
                owners.add(repo.getOwnerName());
            }
            this.owners = owners.build();
        }
        return owners;
    }
    return ImmutableList.of();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) GHRepository(org.kohsuke.github.GHRepository)

Example 9 with GHRepository

use of org.kohsuke.github.GHRepository in project zaproxy by zaproxy.

the class CreateGitHubRelease method createRelease.

@TaskAction
public void createRelease() throws IOException {
    if (bodyFile.isPresent() && body.isPresent()) {
        throw new InvalidUserDataException("Only one type of body property must be set.");
    }
    if (checksumAlgorithm.get().isEmpty()) {
        throw new IllegalArgumentException("The checksum algorithm must not be empty.");
    }
    GitHubUser ghUser = getUser().get();
    GHRepository ghRepo = GitHub.connect(ghUser.getName(), ghUser.getAuthToken()).getRepository(repo.get());
    validateTagExists(ghRepo, tag.get());
    validateReleaseDoesNotExist(ghRepo, tag.get());
    StringBuilder releaseBody = new StringBuilder(250);
    releaseBody.append(bodyFile.isPresent() ? readContents(bodyFile.getAsFile().get().toPath()) : body.getOrElse(""));
    if (addChecksums.get()) {
        if (releaseBody.length() != 0) {
            releaseBody.append("\n\n---\n");
        }
        appendChecksumsTable(releaseBody);
    }
    GHRelease release = ghRepo.createRelease(tag.get()).name(title.get()).body(releaseBody.toString()).prerelease(prerelease.get()).draft(true).create();
    for (Asset asset : assets) {
        release.uploadAsset(asset.getFile().getAsFile().get(), asset.getContentType().get());
    }
    if (!draft.get()) {
        release.update().draft(false).update();
    }
}
Also used : GitHubUser(org.zaproxy.zap.GitHubUser) GHRepository(org.kohsuke.github.GHRepository) InvalidUserDataException(org.gradle.api.InvalidUserDataException) GHRelease(org.kohsuke.github.GHRelease) TaskAction(org.gradle.api.tasks.TaskAction)

Example 10 with GHRepository

use of org.kohsuke.github.GHRepository in project che by eclipse.

the class GitHubDTOFactory method createRepositoriesList.

/**
     * Create DTO object of GitHub repositories collection from given repositories list
     * @param ghRepositoriesList collection of repositories from kohsuke GitHub library
     * @return DTO object
     * @throws IOException
     */
public GitHubRepositoryList createRepositoriesList(PagedIterable<GHRepository> ghRepositoriesList) throws ApiException, IOException {
    GitHubRepositoryList dtoRepositoriesList = DtoFactory.getInstance().createDto(GitHubRepositoryList.class);
    List<GitHubRepository> dtoRepositories = new ArrayList<>();
    for (GHRepository ghRepository : ghRepositoriesList) {
        dtoRepositories.add(createRepository(ghRepository));
    }
    dtoRepositoriesList.setRepositories(dtoRepositories);
    return dtoRepositoriesList;
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GitHubRepositoryList(org.eclipse.che.plugin.github.shared.GitHubRepositoryList) ArrayList(java.util.ArrayList) GitHubRepository(org.eclipse.che.plugin.github.shared.GitHubRepository)

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