本文整理匯總了Java中org.kohsuke.github.GitHub.connectUsingOAuth方法的典型用法代碼示例。如果您正苦於以下問題:Java GitHub.connectUsingOAuth方法的具體用法?Java GitHub.connectUsingOAuth怎麽用?Java GitHub.connectUsingOAuth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.kohsuke.github.GitHub
的用法示例。
在下文中一共展示了GitHub.connectUsingOAuth方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getGitHub
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
private GitHub getGitHub() throws IOException {
final SettingsRepository settingsRepository = ServiceRegistry.getSettingsRepository();
final String apiUrl = settingsRepository.getGitHubApiUrl();
final String personalAccessToken = settingsRepository.getPersonalAccessToken();
if (apiUrl != null) {
if (personalAccessToken != null) {
return GitHub.connectToEnterprise(apiUrl, personalAccessToken);
} else {
return GitHub.connectToEnterpriseAnonymously(apiUrl);
}
} else {
if (personalAccessToken != null) {
return GitHub.connectUsingOAuth(personalAccessToken);
} else {
return GitHub.connectAnonymously();
}
}
}
示例2: createGitHubClient
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
GitHub createGitHubClient(String usernameToUse, String passwordToUse, String oauthAccessTokenToUse, String endPointToUse) throws Exception {
GitHub github = null;
if (usernameAndPasswordIsAvailable(usernameToUse, passwordToUse)) {
if (endPointIsAvailable(endPointToUse)) {
github = GitHub.connectToEnterprise(endPointToUse, usernameToUse, passwordToUse);
} else {
github = GitHub.connectUsingPassword(usernameToUse, passwordToUse);
}
}
if (oAuthTokenIsAvailable(oauthAccessTokenToUse)) {
if (endPointIsAvailable(endPointToUse)) {
github = GitHub.connectUsingOAuth(endPointToUse, oauthAccessTokenToUse);
} else {
github = GitHub.connectUsingOAuth(oauthAccessTokenToUse);
}
}
if (github == null) {
github = GitHub.connect();
}
return github;
}
示例3: run
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
@Override
public void run(UpsourceConfiguration configuration, Environment environment) throws Exception {
DBIFactory factory = new DBIFactory();
DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "data-source");
GitHub gitHub = GitHub.connectUsingOAuth(configuration.getGitHubOAuthToken());
ImmutableMap.Builder<String, Repository> repositoryBuilder = ImmutableMap.builder();
ImmutableMap.Builder<String, ExecutorService> executorBuilder = ImmutableMap.builder();
configuration.getRepositories().forEach(
repository -> {
repositoryBuilder.put(repository.getFullName(), repository);
executorBuilder.put(repository.getFullName(), Executors.newSingleThreadExecutor());
});
List<String> repoNames = configuration.getRepositories().stream().map(Repository::getFullName).
collect(Collectors.toList());
GitHubConnector gitHubConnector =
new GitHubConnector(gitHub, repositoryBuilder.build(), executorBuilder.build());
gitHubConnector.handleStartup();
GitHubWebhookResource gitHubWebhookResource =
new GitHubWebhookResource(gitHubConnector, ImmutableList.copyOf(repoNames));
environment.jersey().register(
gitHubWebhookResource);
environment.jersey().register(new GitHubHMACFilter(configuration.getGitHubWebhookSecret()));
//environment.jersey().register(new UserResource(jdbi.onDemand(UserDao.class)));
environment.jersey().register(DeclarativeLinkingFeature.class);
}
示例4: fetch
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
private PullRequest fetch(PullRequestKey key) {
try {
GitHub github;
if(currentUser== null) {
github = GitHub.connectAnonymously();
} else {
github = GitHub.connectUsingOAuth(currentUser.getAccessToken());
}
return GithubUtil.toPullRequest(
github.getUser(key.getUser())
.getRepository(key.getRepository())
.getPullRequest(key.getNumber()));
} catch (Exception e) {
notification.sendMessage(key, "Could not fetch pull request data from GitHub: " + e.getMessage());
throw new RuntimeException("Could not fetch PullRequest from GitHub for " + key, e);
}
}
示例5: createGitHub
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
private GitHub createGitHub(String accessToken, GitHubConfiguration gitHubConfiguration) throws IOException {
if (gitHubConfiguration.authenticateWith() == AuthenticateWith.GITHUB_ENTERPRISE) {
LOG.debug("Create GitHub connection to enterprise GitHub with token");
return GitHub.connectToEnterprise(gitHubConfiguration.gitHubEnterpriseUrl(), accessToken);
} else {
LOG.debug("Create GitHub connection to public GitHub with token");
return GitHub.connectUsingOAuth(accessToken);
}
}
示例6: setOauthToken
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
public static void setOauthToken(String oauthToken) {
validateOauthToken(oauthToken);
try {
gitHub = GitHub.connectUsingOAuth(oauthToken);
} catch (IOException e) {
Log.e("Error connecting to the GitHub API using the oauth token " + oauthToken);
}
}
示例7: connectToPublicGitHub
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
private GitHub connectToPublicGitHub(GithubPluginSettings pluginSettings) throws IOException {
if (pluginSettings.containsUsernameAndPassword()) {
LOGGER.debug("Create GitHub connection to public GitHub using username and password");
return GitHub.connectUsingPassword(pluginSettings.getUsername(), pluginSettings.getPassword());
} else if (pluginSettings.containsOAuthToken()) {
LOGGER.debug("Create GitHub connection to public GitHub with token");
return GitHub.connectUsingOAuth(pluginSettings.getOauthToken());
}
return null;
}
示例8: oauthConnect
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
/**
* Connect to GitHub API using OAuth
*
* @param oauthToken token for OAuth connection
* @return connected GitHub API class
*/
public GitHub oauthConnect(String oauthToken) throws ServerException, UnauthorizedException {
try {
return GitHub.connectUsingOAuth(oauthToken);
} catch (IOException e) {
throw new ServerException(e.getMessage());
}
}
示例9: runNotesBuilder
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
/**
* Executes NotesBuilder based on passed command line options.
* @param cliOptions command line options.
* @return result of NotesBuilder work.
* @throws IOException if an I/O error occurs.
* @throws GitAPIException if an error occurs while accessing GitHub API.
*/
private static Result runNotesBuilder(CliOptions cliOptions)
throws IOException, GitAPIException {
final String localRepoPath = cliOptions.getLocalRepoPath();
final String startRef = cliOptions.getStartRef();
final String endRef = cliOptions.getEndRef();
final String authToken = cliOptions.getAuthToken();
final GitHub connection;
if (authToken == null) {
connection = GitHub.connectAnonymously();
}
else {
connection = GitHub.connectUsingOAuth(authToken);
}
final GHRepository remoteRepo = connection.getRepository(REMOTE_REPO_PATH);
final Result result = NotesBuilder.buildResult(remoteRepo, localRepoPath, startRef, endRef);
if (result.hasWarnings()) {
printListOf(result.getWarningMessages());
}
if (result.hasErrors()) {
printListOf(result.getErrorMessages());
}
return result;
}
示例10: getUserInfo
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
String oauthToken = token.getToken();
GitHub hub = GitHub.connectUsingOAuth(oauthToken);
GHMyself myself = hub.getMyself();
String login = myself.getLogin();
return new OAuthUserInfo(
ExternalId.SCHEME_GERRIT + login, login, myself.getEmail(), myself.getName(), null);
}
示例11: connect
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
private void connect() throws IOException{
String accessToken = GhprbTrigger.getDscp().getAccessToken();
String serverAPIUrl = GhprbTrigger.getDscp().getServerAPIUrl();
if(accessToken != null && !accessToken.isEmpty()) {
try {
gh = GitHub.connectUsingOAuth(serverAPIUrl, accessToken);
} catch(IOException e) {
logger.log(Level.SEVERE, "Can''t connect to {0} using oauth", serverAPIUrl);
throw e;
}
} else {
gh = GitHub.connect(GhprbTrigger.getDscp().getUsername(), null, GhprbTrigger.getDscp().getPassword());
}
}
示例12: getGithub
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
private static GitHub getGithub(final String token) {
try {
return GitHub.connectUsingOAuth(SetupConfig.get().getGithubApiUrl(), token);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
示例13: onEnable
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
@Override
public void onEnable() {
saveDefaultConfig();
ConfigurationSerialization.registerClass(KitImpl.class);
getServer().getScheduler().scheduleSyncRepeatingTask(this, new TimeSlowRunnable(this), 100L, 100L);
registerListeners(new PlayerJoinListener(this), new PlayerQuitListener(this), new PlayerTeleportListener(this),
new PlayerItemConsumeListener(this),
new WarpSignChangeListener(this), new WarpPlayerInteractListener(this));
registerCommands();
warpManager = new WarpManager(this);
kitManager = new KitManager(this);
drinkManager = new DrinkManager(this);
try {
File gitHubFile = new File(getDataFolder(), "github.yml");
if (gitHubFile.exists()) {
YamlConfiguration gitHubConfig = new YamlConfiguration();
gitHubConfig.load(gitHubFile);
if (gitHubConfig.getString("oauth") != null) {
getLogger().info("Found OAuth token in GitHub config, attempting to connect using OAuth...");
gitHub = GitHub.connectUsingOAuth(gitHubConfig.getString("oauth"));
} else if (gitHubConfig.getString("user") != null && gitHubConfig.getString("password") != null) {
getLogger().info("Found user and password in GitHub config, attempting to connect using user and password...");
gitHub = GitHub.connectUsingPassword(gitHubConfig.getString("user"), gitHubConfig.getString("password"));
} else {
getLogger().info("No user & password or OAuth token found in GitHub config, attempting to connect anonymously...");
gitHub = GitHub.connectAnonymously();
}
} else {
getLogger().info("No GitHub config found, attempting to connect anonymously...");
gitHub = GitHub.connectAnonymously();
}
} catch (IOException | InvalidConfigurationException exception) {
exception.printStackTrace();
}
drinkManager.setupRecipes();
logMessagesEnabledFile = new File(getDataFolder(), "log-messages-enabled.yml");
}
示例14: connect
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
@Override
protected void connect() {
try {
gh = GitHub.connectUsingOAuth(getUserToken().getToken());
} catch (IOException e) {
e.printStackTrace();
}
}
示例15: getGitHub
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
protected GitHub getGitHub(StaplerRequest request) throws IOException {
return GitHub.connectUsingOAuth(getSetupConfig().getGithubApiUrl(), getAccessToken(request));
}