本文整理汇总了Java中org.kohsuke.github.GitHubBuilder.withPassword方法的典型用法代码示例。如果您正苦于以下问题:Java GitHubBuilder.withPassword方法的具体用法?Java GitHubBuilder.withPassword怎么用?Java GitHubBuilder.withPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kohsuke.github.GitHubBuilder
的用法示例。
在下文中一共展示了GitHubBuilder.withPassword方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGithub
import org.kohsuke.github.GitHubBuilder; //导入方法依赖的package包/类
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;
}
示例2: GitHubFacade
import org.kohsuke.github.GitHubBuilder; //导入方法依赖的package包/类
public GitHubFacade(GitAccount details) {
this.details = details;
String username = details.getUsername();
String token = details.getToken();
String password = details.getPassword();
try {
final GitHubBuilder ghb = new GitHubBuilder();
if (Strings.isNotBlank(username) && Strings.isNotBlank(password)) {
ghb.withPassword(username, password);
} else if (Strings.isNotBlank(token)) {
if (Strings.isNotBlank(username)) {
ghb.withOAuthToken(token, username);
} else {
ghb.withOAuthToken(token);
}
}
this.github = ghb.build();
this.myself = this.github.getMyself();
String login = myself.getLogin();
if (Strings.isNotBlank(login) && !Objects.equals(login, username)) {
LOG.debug("Switching the github user name from " + username + " to " + login);
details.setUsername(login);
}
// lets always use the github email address
String email = myself.getEmail();
if (Strings.isNotBlank(email)) {
details.setEmail(email);
}
} catch (IOException e) {
LOG.warn("Failed to create github client for user " + details.getUsername());
}
}
示例3: getBuilder
import org.kohsuke.github.GitHubBuilder; //导入方法依赖的package包/类
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 = Ghprc.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.INFO, "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.INFO, "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;
}
示例4: doCreateApiToken
import org.kohsuke.github.GitHubBuilder; //导入方法依赖的package包/类
public FormValidation doCreateApiToken(
@QueryParameter("serverAPIUrl") final String serverAPIUrl,
@QueryParameter("credentialsId") final String credentialsId,
@QueryParameter("username") final String username,
@QueryParameter("password") final String password) {
try {
GitHubBuilder builder = new GitHubBuilder()
.withEndpoint(serverAPIUrl)
.withConnector(new HttpConnectorWithJenkinsProxy());
if (StringUtils.isEmpty(credentialsId)) {
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
return FormValidation.error("Username and Password required");
}
builder.withPassword(username, password);
} else {
StandardCredentials credentials = Ghprc.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");
}
}
GitHub gh = builder.build();
GHAuthorization token = gh.createToken(Arrays.asList(GHAuthorization.REPO_STATUS,
GHAuthorization.REPO), "Jenkins GitHub Pull Request Comments", null);
String tokenId;
try {
tokenId = Ghprc.createCredentials(serverAPIUrl, token.getToken());
} catch (Exception e) {
tokenId = "Unable to create credentials: " + e.getMessage();
}
return FormValidation.ok("Access token created: " + token.getToken() + " token CredentialsID: " + tokenId);
} catch (IOException ex) {
return FormValidation.error("GitHub API token couldn't be created: " + ex.getMessage());
}
}