throw new GitHubException("Error creating blob from '" + path + "': " + e.getMessage(), e);
}
}
private GitHubClient createClient(String host, String userName, String password, String oauth2Token) throws GitHubException {
GitHubClient client;
if (!StringUtils.isEmpty(host)) {
if (log.isDebugEnabled()){
log.debug("Using custom host: " + host);
}
client = createClient(host);
} else{
client = new GitHubClient();
}
if(!StringUtils.isEmpty(userName) && !StringUtils.isEmpty(password)){
if (log.isDebugEnabled()){
log.debug("Using basic authentication with username: " + userName);
}
client.setCredentials(userName, password);
return client;
}else if(!StringUtils.isEmpty(oauth2Token)){
if (log.isDebugEnabled()){
log.debug("Using OAuth2 access token authentication");
}
client.setOAuth2Token(oauth2Token);
return client;
}else if(StringUtils.isEmpty(userName) && !StringUtils.isEmpty(password)){
if (log.isDebugEnabled()){
log.debug("Using OAuth2 access token authentication");
}
client.setOAuth2Token(password);
return client;
}else if(!StringUtils.isEmpty(userName) && System.console() != null){
Console console = System.console();
while(StringUtils.isEmpty(password)){
password = new String(console.readPassword("Input the password for '" + userName + "': "));
}
client.setCredentials(userName, password);
return client;
}
throw new GitHubException("No authentication credentials configured");
}