/** * Called by {@link #apply(Object)} * Logins to GH and returns client instance * * @param github config where token saved * * @return authorized client or null on login error */ @Override @CheckForNull protected GitHub applyNullSafe(@Nonnull GitHubServerConfig github) { String accessToken = tokenFor(github.getCredentialsId()); GitHubBuilder builder = new GitHubBuilder() .withOAuthToken(accessToken) .withConnector(connector(github)) .withRateLimitHandler(RateLimitHandler.FAIL); try { if (isNotBlank(github.getApiUrl())) { builder.withEndpoint(github.getApiUrl()); } LOGGER.debug("Create new GH client with creds id {}", github.getCredentialsId()); return builder.build(); } catch (IOException e) { LOGGER.warn("Failed to login with creds {}", github.getCredentialsId(), e); return null; } }
public GitHub getGithub() throws IOException { if (github == null) { GitHubBuilder ghb = new GitHubBuilder(); String username = getGithubUsername(); String password = getGithubPassword(); String token = getGithubToken(); if (Strings.notEmpty(username) && Strings.notEmpty(password)) { ghb.withPassword(username, password); } else if (Strings.notEmpty(token)) { if (Strings.notEmpty(username)) { ghb.withOAuthToken(token, username); } else { ghb.withOAuthToken(token); } } ghb.withRateLimitHandler(RateLimitHandler.WAIT). withAbuseLimitHandler(AbuseLimitHandler.WAIT); this.github = ghb.build(); } return this.github; }
public GitHub getGithub() throws IOException { if (github == null) { GitHubBuilder ghb = new GitHubBuilder(); String username = getGithubUsername(); String password = getGithubPassword(); String token = getGithubToken(); if (Strings.notEmpty(username) && Strings.notEmpty(password)) { ghb.withPassword(username, password); } else if (Strings.notEmpty(token)) { if (Strings.notEmpty(username)) { ghb.withOAuthToken(token, username); } else { ghb.withOAuthToken(token); } } ghb.withRateLimitHandler(RateLimitHandler.WAIT). withAbuseLimitHandler(AbuseLimitHandler.WAIT); this.github = ghb.build(); } return this.github; }