/** * @deprecated * Use {@link #fromEnvironment()} to pick up standard set of environment variables, so that * different clients of this library will all recognize one consistent set of coordinates. */ public static GitHubBuilder fromEnvironment(String loginVariableName, String passwordVariableName, String oauthVariableName) throws IOException { return fromEnvironment(loginVariableName, passwordVariableName, oauthVariableName, ""); }
/** * @deprecated * Use {@link #fromEnvironment()} to pick up standard set of environment variables, so that * different clients of this library will all recognize one consistent set of coordinates. */ public static GitHubBuilder fromEnvironment(String loginVariableName, String passwordVariableName, String oauthVariableName) throws IOException { return fromEnvironment(loginVariableName, passwordVariableName, oauthVariableName, ""); }
/** * @deprecated * Use {@link #fromEnvironment()} to pick up standard set of environment variables, so that * different clients of this library will all recognize one consistent set of coordinates. */ public static GitHubBuilder fromEnvironment(String loginVariableName, String passwordVariableName, String oauthVariableName) throws IOException { return fromEnvironment(loginVariableName, passwordVariableName, oauthVariableName, ""); }
/** * First check if the credentials are configured using the ~/.github properties file. * * If no user is specified it means there is no configuration present so check the environment instead. * * If there is still no user it means there are no credentials defined and throw an IOException. * * @return the configured Builder from credentials defined on the system or in the environment. * * @throws IOException If there are no credentials defined in the ~/.github properties file or the process environment. */ public static GitHubBuilder fromCredentials() throws IOException { Exception cause = null; GitHubBuilder builder; try { builder = fromPropertyFile(); if (builder.oauthToken != null || builder.user != null) return builder; } catch (FileNotFoundException e) { // fall through cause = e; } builder = fromEnvironment(); if (builder.oauthToken != null || builder.user != null) return builder; else throw (IOException)new IOException("Failed to resolve credentials from ~/.github or the environment.").initCause(cause); }
/** * First check if the credentials are configured using the ~/.github properties file. * * If no user is specified it means there is no configuration present so check the environment instead. * * If there is still no user it means there are no credentials defined and throw an IOException. * * @return the configured Builder from credentials defined on the system or in the environment. * * @throws IOException If there are no credentials defined in the ~/.github properties file or the process environment. */ public static GitHubBuilder fromCredentials() throws IOException { Exception cause = null; GitHubBuilder builder; try { builder = fromPropertyFile(); if (builder.user != null) return builder; } catch (FileNotFoundException e) { // fall through cause = e; } builder = fromEnvironment(); if (builder.user != null) return builder; else throw (IOException)new IOException("Failed to resolve credentials from ~/.github or the environment.").initCause(cause); }
/** * First check if the credentials are configured using the ~/.github properties file. * * If no user is specified it means there is no configuration present so check the environment instead. * * If there is still no user it means there are no credentials defined and throw an IOException. * * @return the configured Builder from credentials defined on the system or in the environment. * * @throws IOException If there are no credentials defined in the ~/.github properties file or the process environment. */ public static GitHubBuilder fromCredentials() throws IOException { Exception cause = null; GitHubBuilder builder; try { builder = fromPropertyFile(); if (builder.oauthToken != null || builder.user != null) return builder; } catch (FileNotFoundException e) { // fall through cause = e; } builder = fromEnvironment(); if (builder.oauthToken != null || builder.user != null) return builder; else throw (IOException)new IOException("Failed to resolve credentials from ~/.github or the environment.").initCause(cause); }
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; }
private GHCompare getCompare(Build build, Build previousBuild) { try { GitHub gh = GitHubBuilder.fromEnvironment().build(); GHRateLimit rateLimit = gh.getRateLimit(); SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); this.logger.debug("GitHub rate limit: Limit: " + rateLimit.limit + " - Remaining: " + rateLimit.remaining + " - Reset hour: " + dateFormat.format(rateLimit.reset)); if (rateLimit.remaining > 2) { GHRepository ghRepo = gh.getRepository(build.getRepository().getSlug()); GHCommit buildCommit = ghRepo.getCommit(build.getCommit().getSha()); GHCommit previousBuildCommit = ghRepo.getCommit(previousBuild.getCommit().getSha()); GHCompare compare = ghRepo.getCompare(previousBuildCommit, buildCommit); return compare; } else { this.logger.warn("You reached your rate limit for GitHub. You have to wait until " + dateFormat.format(rateLimit.reset) + " to get data. PRInformation will be null for build "+build.getId()+"."); } } catch (IOException e) { this.logger.warn("Error while getting commit from GitHub: " + e); } return null; }