public Updater() { ResourceBundle rs = ResourceBundle.getBundle("version"); currentVersion = new Version(rs.getString("version")); try { repository = GitHub.connectAnonymously().getRepository(REPO_NAME); } catch (IOException e) { e.printStackTrace(); } }
public GitHub open() throws IOException { if (getAuthToken() == null) { log.warn("Annonymous login for location={}. You will only have 60 requests per hour! This might not be enough to read the content listing!"); return GitHub.connectAnonymously(); } else { log.info("Connecting using authToken"); return GitHub.connectUsingOAuth(getAuthToken()); } } }
/** * Creates the connection to the remote repository. * @param authToken the authorization token. * @param remoteRepoPath path to remote git repository. * @return the remote repository object. * @throws IOException if an I/O error occurs. */ private static GHRepository createRemoteRepo(String authToken, String remoteRepoPath) throws IOException { final GitHub connection; if (authToken == null) { connection = GitHub.connectAnonymously(); } else { connection = GitHub.connectUsingOAuth(authToken); } return connection.getRepository(remoteRepoPath); }
/** * Iterates through all projects in the given github organisation and generates an archetype for it */ public void generateArchetypesFromGithubOrganisation(String githubOrg, File outputDir, List<String> dirs) throws IOException { GitHub github = GitHub.connectAnonymously(); GHOrganization organization = github.getOrganization(githubOrg); Objects.notNull(organization, "No github organisation found for: " + githubOrg); Map<String, GHRepository> repositories = organization.getRepositories(); Set<Map.Entry<String, GHRepository>> entries = repositories.entrySet(); File cloneParentDir = new File(outputDir, "../git-clones"); if (cloneParentDir.exists()) { Files.recursiveDelete(cloneParentDir); } for (Map.Entry<String, GHRepository> entry : entries) { String repoName = entry.getKey(); GHRepository repo = entry.getValue(); String url = repo.getGitTransportUrl(); generateArchetypeFromGitRepo(outputDir, dirs, cloneParentDir, repoName, url, null); } }
@Inject public GithubConnector(ApolloConfiguration apolloConfiguration) { try { logger.info("Initializing Github Connector"); // If no user or oauth was provided, attempt to go anonymous if (StringUtils.isEmpty(apolloConfiguration.getScm().getGithubLogin()) || StringUtils.isEmpty(apolloConfiguration.getScm().getGithubOauthToken())) { gitHub = GitHub.connectAnonymously(); } else { gitHub = GitHub.connect(apolloConfiguration.getScm().getGithubLogin(), apolloConfiguration.getScm().getGithubOauthToken()); } } catch (IOException e) { throw new RuntimeException("Could not open connection to Github!", e); } }
public GitHub getGithub() throws IOException { if (this.github == null) { if (!this.travisConfig.getGithubToken().isEmpty()) { try { this.github = GitHubBuilder.fromEnvironment().withOAuthToken(this.travisConfig.getGithubToken()).build(); } catch (IOException e) { String token = (this.travisConfig.getGithubToken().length() > 10) ? "[10 first characters of token] "+this.travisConfig.getGithubToken().substring(0,10) : this.travisConfig.getGithubToken(); LOGGER.error("Error while using credentials ("+token+"): fallback to anonymous connection.", e); this.github = GitHub.connectAnonymously(); } } else { LOGGER.info("No Github token has been given, try to connect using environment information"); try { this.github = GitHubBuilder.fromEnvironment().build(); } catch (IOException e) { LOGGER.warn("Error while using environment credentials: fallback to anonymous connection. In the future try by setting a proper token in GITHUB_OAUTH env variable.", e); this.github = GitHub.connectAnonymously(); } } } GHRateLimit rateLimit = this.github.getRateLimit(); LOGGER.info("GitHub ratelimit: Limit: " + rateLimit.limit + " Remaining: " + rateLimit.remaining + " Reset hour: " + hourSimpleDateFormat.format(rateLimit.reset)); return this.github; }
public GitHub get() { try { GitHubScannerBuilder ghb = (GitHubScannerBuilder) getBuilder(); String url = ghb.url; String token = ghb.token ; String username = ghb.username; String password = ghb.password; if (!Strings.isNullOrEmpty(url)) { // enterprise if (!Strings.isNullOrEmpty(token)) { return GitHub.connectToEnterprise(url, token); } if (!Strings.isNullOrEmpty(username)) { return GitHub.connectToEnterprise(url, username, password); } return GitHub.connectToEnterpriseAnonymously(url); } else { if (!Strings.isNullOrEmpty(token)) { return GitHub.connectUsingOAuth(token); } if (!Strings.isNullOrEmpty(username)) { return GitHub.connectUsingPassword(username, password); } return GitHub.connectAnonymously(); } } catch (IOException e) { throw new MercatorException(e); } } }
GitHub gh = GitHub.connectAnonymously();