Java Code Examples for org.kohsuke.github.GitHub#connectUsingOAuth()

The following examples show how to use org.kohsuke.github.GitHub#connectUsingOAuth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitHistoryRefactoringMinerImpl.java    From RefactoringMiner with MIT License 7 votes vote down vote up
private GitHub connectToGitHub() {
	if(gitHub == null) {
		try {
			Properties prop = new Properties();
			InputStream input = new FileInputStream("github-oauth.properties");
			prop.load(input);
			String oAuthToken = prop.getProperty("OAuthToken");
			if (oAuthToken != null) {
				gitHub = GitHub.connectUsingOAuth(oAuthToken);
				if(gitHub.isCredentialValid()) {
					logger.info("Connected to GitHub with OAuth token");
				}
			}
			else {
				gitHub = GitHub.connect();
			}
		} catch(FileNotFoundException e) {
			logger.warn("File github-oauth.properties was not found in RefactoringMiner's execution directory", e);
		} catch(IOException ioe) {
			ioe.printStackTrace();
		}
	}
	return gitHub;
}
 
Example 2
Source File: GitHubProvider.java    From gocd-build-status-notifier with Apache License 2.0 6 votes vote down vote up
GitHub createGitHubClient(String usernameToUse, String passwordToUse, String oauthAccessTokenToUse, String endPointToUse) throws Exception {
    LOGGER.info("Creating GitHub client"); 

    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;
}
 
Example 3
Source File: GithubHelper.java    From blueocean-plugin with MIT License 5 votes vote down vote up
private GitHub getGitHub() throws IOException {
    if (githubInstance == null) {
        githubInstance = GitHub.connectUsingOAuth(accessToken);
        Preconditions.checkArgument(githubInstance.isCredentialValid(), "invalid GitHub access token");
        logger.info("GitHub initialized w/ valid credentials");
    }

    return githubInstance;
}
 
Example 4
Source File: GitHubUtils.java    From oncokb with GNU Affero General Public License v3.0 5 votes vote down vote up
private static GitHub getGitHubConnection() throws IOException, NoPropertyException {
    String token = PropertiesUtils.getProperties(ONCOKB_DATA_ACCESS_TOKEN_PROPERTY_NAME);
    if (token == null) {
        throw new NoPropertyException("The data access token is not available.");
    }
    return GitHub.connectUsingOAuth(token);
}
 
Example 5
Source File: GitHubProvider.java    From gocd-oauth-login with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: NotesBuilder.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates the connection to the remote repository.
 *
 * @param authToken the authorization token.
 * @param remoteRepoPath path to remote git repository.
 * @return the remote repository object.
 * @throws IOException if an I/O error occurs.
 */
private static GHRepository createRemoteRepo(String authToken, String remoteRepoPath)
        throws IOException {
    final GitHub connection;
    if (authToken == null) {
        connection = GitHub.connectAnonymously();
    }
    else {
        connection = GitHub.connectUsingOAuth(authToken);
    }

    return connection.getRepository(remoteRepoPath);
}
 
Example 7
Source File: GithubRepositoryService.java    From DotCi with MIT License 5 votes vote down vote up
private static GitHub getGithub(final String token) {
    try {
        return GitHub.connectUsingOAuth(SetupConfig.get().getGithubApiUrl(), token);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 8
Source File: GithubRepoAction.java    From DotCi with MIT License 4 votes vote down vote up
protected GitHub getGitHub(StaplerRequest request) throws IOException {
    return GitHub.connectUsingOAuth(getSetupConfig().getGithubApiUrl(), getAccessToken(request));
}
 
Example 9
Source File: GithubReposController.java    From DotCi with MIT License 4 votes vote down vote up
private GitHub getGitHub(final StaplerRequest request) throws IOException {
    return GitHub.connectUsingOAuth(getSetupConfig().getGithubApiUrl(), getAccessToken(request));
}