public static GitHubBuilder fromProperties(Properties props) { GitHubBuilder self = new GitHubBuilder(); self.withOAuthToken(props.getProperty("oauth"), props.getProperty("login")); self.withPassword(props.getProperty("login"), props.getProperty("password")); self.withEndpoint(props.getProperty("endpoint", GitHub.GITHUB_URL)); return self; }
public static GitHubBuilder fromProperties(Properties props) { GitHubBuilder self = new GitHubBuilder(); self.withOAuthToken(props.getProperty("oauth"), props.getProperty("login")); self.withPassword(props.getProperty("login"), props.getProperty("password")); self.withEndpoint(props.getProperty("endpoint", GitHub.GITHUB_URL)); return self; }
public static GitHubBuilder fromProperties(Properties props) { GitHubBuilder self = new GitHubBuilder(); self.withOAuthToken(props.getProperty("oauth"), props.getProperty("login")); self.withPassword(props.getProperty("login"), props.getProperty("password")); self.withEndpoint(props.getProperty("endpoint", GitHub.GITHUB_URL)); return self; }
public static GitHub connectUsingPassword(String login, String password) throws IOException { return new GitHubBuilder().withPassword(login, password).build(); }
public static GitHub connectUsingPassword(String login, String password) throws IOException { return new GitHubBuilder().withPassword(login, password).build(); }
public static GitHub connectUsingPassword(String login, String password) throws IOException { return new GitHubBuilder().withPassword(login, password).build(); }
public Future<Snapshot> takeSnapshot(String organizationName, Date snapshotDate) throws IOException { GitHubBuilder builder = new GitHubBuilder(); if (StringUtils.isNotEmpty(token)) { builder.withOAuthToken(token); } else if (StringUtils.isNotEmpty(login) && StringUtils.isNotEmpty(password)) { builder.withPassword(login, password); } else { logger.error("GitHub credentials not found, proceeding unauthenticated. That will enforce 60 requests per hour limit."); } GitHub gitHub = builder.withConnector(new OkHttpConnector(new OkUrlFactory(httpClient))).build(); return pool.submit(new TakeSnapshotTask(gitHub, organizationName, scorer, snapshotDate)); }
/** * @deprecated * Either OAuth token or password is sufficient, so there's no point in passing both. * Use {@link #connectUsingPassword(String, String)} or {@link #connectUsingOAuth(String)}. */ public static GitHub connect(String login, String oauthAccessToken, String password) throws IOException { return new GitHubBuilder().withOAuthToken(oauthAccessToken, login).withPassword(login, password).build(); }
private void retrieveRepositoryNames() throws IOException { System.err.println("Retrieving GitHub repository names..."); Cache cache = new Cache(GITHUB_API_CACHE, 20L*1024*1024); // 20 MB cache github = new GitHubBuilder().withConnector(new OkHttp3Connector(new OkUrlFactory(new OkHttpClient.Builder().cache(cache).build()))).withPassword(GITHUB_API_USERNAME, GITHUB_API_PASSWORD).build(); List<String> ret = new ArrayList<>(); for (GHRepository repo : github.getOrganization("jenkinsci").listRepositories().withPageSize(100)) { ret.add(repo.getHtmlUrl().toString()); } Files.write(GITHUB_REPO_LIST.toPath(), ret); }
/** * Version that connects to GitHub Enterprise. * * @deprecated * Use with caution. Login with password is not a preferred method. */ public static GitHub connectToEnterprise(String apiUrl, String login, String password) throws IOException { return new GitHubBuilder().withEndpoint(apiUrl).withPassword(login, password).build(); }
/** * @deprecated * Either OAuth token or password is sufficient, so there's no point in passing both. * Use {@link #connectUsingPassword(String, String)} or {@link #connectUsingOAuth(String)}. */ public static GitHub connect(String login, String oauthAccessToken, String password) throws IOException { return new GitHubBuilder().withOAuthToken(oauthAccessToken, login).withPassword(login, password).build(); }
/** * Version that connects to GitHub Enterprise. * * @deprecated * Use with caution. Login with password is not a preferred method. */ public static GitHub connectToEnterprise(String apiUrl, String login, String password) throws IOException { return new GitHubBuilder().withEndpoint(apiUrl).withPassword(login, password).build(); }
/** * @deprecated * Either OAuth token or password is sufficient, so there's no point in passing both. * Use {@link #connectUsingPassword(String, String)} or {@link #connectUsingOAuth(String)}. */ public static GitHub connect(String login, String oauthAccessToken, String password) throws IOException { return new GitHubBuilder().withOAuthToken(oauthAccessToken, login).withPassword(login, password).build(); }
public static GitHub connectToEnterprise(String apiUrl, String login, String password) throws IOException { return new GitHubBuilder().withEndpoint(apiUrl).withPassword(login, password).build(); }
/** * Can be used to convert given login and password to GH personal token as more secured way to interact with api * * @param username gh login * @param password gh password * @param apiUrl gh api url. Can be null or empty to default * * @return personal token with requested scope * @throws IOException when can't create token with given creds */ public GHAuthorization createToken(@Nonnull String username, @Nonnull String password, @Nullable String apiUrl) throws IOException { GitHub gitHub = new GitHubBuilder() .withEndpoint(defaultIfBlank(apiUrl, GITHUB_URL)) .withPassword(username, password) .build(); return gitHub.createToken( GH_PLUGIN_REQUIRED_SCOPE, format("Jenkins GitHub Plugin token (%s)", Jenkins.getInstance().getRootUrl()), Jenkins.getInstance().getRootUrl() ); }
builder.withPassword(username, password); } else { StandardCredentials credentials = Ghprb.lookupCredentials(null, credentialsId, serverAPIUrl); if (credentials instanceof StandardUsernamePasswordCredentials) { StandardUsernamePasswordCredentials upCredentials = (StandardUsernamePasswordCredentials) credentials; builder.withPassword(upCredentials.getUsername(), upCredentials.getPassword().getPlainText()); } else { return FormValidation.error("No username/password credentials provided");
private static GitHubBuilder getBuilder(Item context, String serverAPIUrl, String credentialsId) { GitHubBuilder builder = new GitHubBuilder() .withEndpoint(serverAPIUrl) .withConnector(new HttpConnectorWithJenkinsProxy()); String contextName = context == null ? "(Jenkins.instance)" : context.getFullDisplayName(); if (StringUtils.isEmpty(credentialsId)) { LOGGER.log(Level.WARNING, "credentialsId not set for context {0}, using anonymous connection", contextName); return builder; } StandardCredentials credentials = Ghprb.lookupCredentials(context, credentialsId, serverAPIUrl); if (credentials == null) { LOGGER.log(Level.SEVERE, "Failed to look up credentials for context {0} using id: {1}", new Object[] {contextName, credentialsId}); } else if (credentials instanceof StandardUsernamePasswordCredentials) { LOGGER.log(Level.FINEST, "Using username/password for context {0}", contextName); StandardUsernamePasswordCredentials upCredentials = (StandardUsernamePasswordCredentials) credentials; builder.withPassword(upCredentials.getUsername(), upCredentials.getPassword().getPlainText()); } else if (credentials instanceof StringCredentials) { LOGGER.log(Level.FINEST, "Using OAuth token for context {0}", contextName); StringCredentials tokenCredentials = (StringCredentials) credentials; builder.withOAuthToken(tokenCredentials.getSecret().getPlainText()); } else { LOGGER.log(Level.SEVERE, "Unknown credential type for context {0} using id: {1}: {2}", new Object[] {contextName, credentialsId, credentials.getClass().getName()}); return null; } return builder; }
gb.withPassword(username, password);
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; }