@Override public String getName() { if (org != null) return org.getLogin(); else return null; }
/** * Returns true if this user belongs to the specified organization. */ public boolean isMemberOf(GHOrganization org) { return org.hasMember(this); }
/** * Creates a new repository. * * @return * Newly created repository. */ public GHRepository createRepository(String name, String description, String homepage, String team, boolean isPublic) throws IOException { GHTeam t = getTeams().get(team); if (t==null) throw new IllegalArgumentException("No such team: "+team); return createRepository(name,description,homepage,t,isPublic); }
public int getPublicRepoCount() { try { return organization.getPublicRepoCount(); } catch (IOException e) { logger.warn("No public repositories count found for organization '{}'.", organization.getLogin()); return 0; } }
/** * Forks this repository into an organization. * * @return * Newly forked repository that belong to you. */ public GHRepository forkTo(GHOrganization org) throws IOException { new Requester(root).to(getApiTailUrl("forks?org="+org.getLogin())); // this API is asynchronous. we need to wait for a bit for (int i=0; i<10; i++) { GHRepository r = org.getRepository(name); if (r!=null) return r; try { Thread.sleep(3000); } catch (InterruptedException e) { throw (IOException)new InterruptedIOException().initCause(e); } } throw new IOException(this+" was forked into "+org.getLogin()+" but can't find the new repository"); }
OrganizationWrapper(GHOrganization organization) { this.organization = organization; List<RepositoryWrapper> repositories; try { repositories = organization.listRepositories().asList().stream() .filter(r -> !r.isPrivate()) // deal with public repos only .filter(r -> !r.isFork()) // skip forks as they change statistics significantly .map(repository -> new RepositoryWrapper(repository, organization)) .collect(Collectors.toList()); } catch (Throwable t) { logger.warn("No repositories found for organization '{}'.", organization.getLogin()); repositories = Collections.<RepositoryWrapper>emptyList(); } this.repositories = Collections.unmodifiableList(repositories); }
public void scanOrganization(GHOrganization org) { try { ObjectNode n = mapper.createObjectNode(); n.put("url", org.getUrl().toString()); if (org.getHtmlUrl() != null) { n.put("htmlUrl", org.getHtmlUrl().toString()); } n.put("name", org.getLogin()); n.put("displayName", org.getName()); String cypher = "merge (o:GitHubOrg {url:{url}}) set o+={props},o.updateTs=timestamp() return o"; getProjector().getNeoRxClient().execCypher(cypher, "url", n.path("url").asText(), "props", n); } catch (IOException e) { throw new MercatorException(e); } try { org.getRepositories().values().forEach(repo -> { scanRepository(repo); String cypher = "match (o:GitHubOrg {url:{orgUrl}}), (r:GitHubRepo {url:{repoUrl}}) merge (o)-[x:CONTAINS]->(r) set x.updateTs=timestamp()"; getProjector().getNeoRxClient().execCypher(cypher, "orgUrl", org.getUrl().toString(), "repoUrl", repo.getUrl().toString()); }); } catch (IOException e) { throw new MercatorException(e); } }
/** * This method returns a shallowly populated organizations. * * To retrieve full organization details, you need to call {@link #getOrganization(String)} * TODO: make this automatic. */ public Map<String, GHOrganization> getMyOrganizations() throws IOException { GHOrganization[] orgs = retrieve().to("/user/orgs", GHOrganization[].class); Map<String, GHOrganization> r = new HashMap<String, GHOrganization>(); for (GHOrganization o : orgs) { // don't put 'o' into orgs because they are shallow r.put(o.getLogin(),o.wrapUp(this)); } return r; }
public List<GHUser> listMembers() { if (this.members == null) { try { this.members = organization.listMembers().asList(); } catch (Throwable t) { logger.warn("No public members found for organization '{}'.", organization.getLogin()); this.members = Collections.<GHUser>emptyList(); } } return this.members; }
/** * List up repositories that has some open pull requests. * * This used to be an efficient method that didn't involve traversing every repository, but now * it doesn't do any optimization. */ public List<GHRepository> getRepositoriesWithOpenPullRequests() throws IOException { List<GHRepository> r = new ArrayList<GHRepository>(); for (GHRepository repository : listRepositories(100)) { repository.wrap(root); List<GHPullRequest> pullRequests = repository.getPullRequests(GHIssueState.OPEN); if (pullRequests.size() > 0) { r.add(repository); } } return r; }
public static void initializeRepos(GHOrganization org, List<String> repos, String image, List<GHRepository> createdRepos, GitHubUtil gitHubUtil) throws Exception { for (String repoName : repos) { GHRepository repo = org.createRepository(repoName) .description("Delete if this exists. If it exists, then an integration test crashed somewhere.") .private_(false) .create(); // Ensure that repository exists for (int attempts = 0; attempts < 5; attempts++) { try { repo = gitHubUtil.getRepo(repo.getFullName()); break; } catch (Exception e) { log.info("Waiting for {} to be created", repo.getFullName()); Thread.sleep(TimeUnit.SECONDS.toMillis(1)); } } repo.createContent("FROM " + image + ":test", "Integration Testing", "Dockerfile"); createdRepos.add(repo); log.info("Initializing {}/{}", org.getLogin(), repoName); gitHubUtil.tryRetrievingContent(repo, "Dockerfile", repo.getDefaultBranch()); } }
/** * All the public members of this organization. */ public PagedIterable<GHUser> listPublicMembers() throws IOException { return listMembers("public_members"); }
@Override public List<Organization> getOrganizations(String accessToken) throws IOException, ServiceException { GitHub gitHub = GitHub.connectUsingOAuth(accessToken); List<Organization> organizations = gitHub.getMyself().getAllOrganizations().stream().map(organization -> { Organization result = new Organization(organization.getLogin()); result.setAvatarURL(organization.getAvatarUrl()); return result; }).collect(Collectors.toList()); Organization myself = new Organization(gitHub.getMyself().getLogin()); myself.setAvatarURL(gitHub.getMyself().getAvatarUrl()); organizations.add(myself); return organizations; }
/** * Finds a team that has the given slug in its {@link GHTeam#getSlug()} */ public GHTeam getTeamBySlug(String slug) throws IOException { for (GHTeam t : listTeams()) { if(t.getSlug().equals(slug)) return t; } return null; }
@Test(dependsOnMethods = "testStoreUpdate") public void testAsUser() throws Exception { GHRepository repo = github.getOrganization(ORG).getRepository(NAME); List<GHPullRequest> prs = repo.getPullRequests(GHIssueState.OPEN); Assert.assertTrue(prs.size() == 1); for (GHPullRequest pr : prs) { pr.merge("Automatic merge through itests."); pr.close(); } try (InputStream stream = repo.getFileContent("Dockerfile").read(); InputStreamReader streamR = new InputStreamReader(stream); BufferedReader reader = new BufferedReader(streamR)) { String line; while ((line = reader.readLine()) != null) { if (line.contains("FROM")) { Assert.assertTrue(line.contains(IMAGE)); Assert.assertTrue(line.endsWith(TAG)); } } } }
/** * @deprecated * Use {@link #createRepository(String)} that uses a builder pattern to let you control every aspect. */ public GHRepository createRepository(String name, String description, String homepage, GHTeam team, boolean isPublic) throws IOException { if (team==null) throw new IllegalArgumentException("Invalid team"); return createRepository(name).description(description).homepage(homepage).private_(!isPublic).team(team).create(); }
public GHTeam loadTeam(String organization, String team) throws IOException { if (gh != null && isAuthenticated()) { GHOrganization org = gh.getOrganization(organization); if (org != null) { Map<String, GHTeam> teamMap = org.getTeams(); return teamMap.get(team); } else return null; } else return null; } }
/** * Forks this repository into an organization. * * @return * Newly forked repository that belong to you. */ public GHRepository forkTo(GHOrganization org) throws IOException { new Requester(root).to(getApiTailUrl("forks?org="+org.getLogin())); // this API is asynchronous. we need to wait for a bit for (int i=0; i<10; i++) { GHRepository r = org.getRepository(name); if (r!=null) return r; try { Thread.sleep(3000); } catch (InterruptedException e) { throw (IOException)new InterruptedIOException().initCause(e); } } throw new IOException(this+" was forked into "+org.getLogin()+" but can't find the new repository"); }
throw new FillErrorResponse(e.getMessage(), false); if (org != null && repoOwner.equalsIgnoreCase(org.getLogin())) { Set<String> result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); LOGGER.log(Level.FINE, "as {0} looking for repositories in {1}", new Object[]{credentialsId, repoOwner}); for (GHRepository repo : org.listRepositories(100)) { LOGGER.log(Level.FINE, "as {0} found {1}/{2}", new Object[]{credentialsId, repoOwner, repo.getName()});