Skip to content

Commit

Permalink
Allow to fallback on GITHUB_OAUTH env variable when no token has been…
Browse files Browse the repository at this point in the history
… given.
  • Loading branch information
surli committed Apr 5, 2018
1 parent f620a6c commit a76c57b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/fr/inria/jtravis/JTravis.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,22 @@ public GitHub getGithub() throws IOException {
if (this.github == null) {
if (!this.travisConfig.getGithubToken().isEmpty()) {
try {
LOGGER.debug("Get GH OAuth (10 first characters): "+this.travisConfig.getGithubToken().substring(0,10));
this.github = GitHubBuilder.fromEnvironment().withOAuthToken(this.travisConfig.getGithubToken()).build();
} catch (IOException e) {
LOGGER.warn("Error while using credentials: try to use anonymous access to github.", e);
LOGGER.error("Error while using credentials (10 first characters of token: "+this.travisConfig.getGithubToken().substring(0,10)+"): fallback to anonymous connection.", e);
this.github = GitHub.connectAnonymously();
LOGGER.warn("No github information has been given to connect (set GITHUB_OAUTH), you will have a very low ratelimit for github requests.");
}
} else {
this.github = GitHub.connectAnonymously();
LOGGER.warn("No github information has been given to connect (set GITHUB_OAUTH), you will have a very low ratelimit for github requests.");
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;
}
Expand Down

0 comments on commit a76c57b

Please sign in to comment.