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; }
private GitHub loginWith(GitConfig gitConfig) throws IOException { if (hasCredentials(gitConfig)) return GitHub.connectUsingPassword(gitConfig.getUsername(), gitConfig.getPassword()); else return GitHub.connect(); }
@Inject public GithubConnector(ApolloConfiguration apolloConfiguration) { try { logger.info("Initializing Github Connector"); // If no user or oauth was provided, attempt to go anonymous if (StringUtils.isEmpty(apolloConfiguration.getScm().getGithubLogin()) || StringUtils.isEmpty(apolloConfiguration.getScm().getGithubOauthToken())) { gitHub = GitHub.connectAnonymously(); } else { gitHub = GitHub.connect(apolloConfiguration.getScm().getGithubLogin(), apolloConfiguration.getScm().getGithubOauthToken()); } } catch (IOException e) { throw new RuntimeException("Could not open connection to Github!", e); } }
/** * Create the repository on Github * * @throws IOException if something goes horribly wrong */ @TaskAction public void configureRepository() throws IOException { GitHub github = GitHub.connect(null, getGithubToken()); String user = github.getMyself().getLogin(); GHRepository repository = null; try { repository = github.getRepository(user + "/" + getRepositoryName()); } catch (FileNotFoundException e) { GHCreateRepositoryBuilder repositoryCreator = github.createRepository(getRepositoryName()); repository = repositoryCreator.create(); } String description = getRepositoryDescription(); if (description != null && !description.equals(repository.getDescription())) { repository.setDescription(description); } }
gitHub = GitHub.connect();
/** * Create the repository on Github * * @throws IOException if something goes horribly wrong */ @TaskAction public void configureRepository() throws IOException { GitHub github = GitHub.connect(null, getGithubToken()); String user = github.getMyself().getLogin(); GHRepository repository = null; try { repository = github.getRepository(user + "/" + getRepositoryName()); } catch (FileNotFoundException e) { GHCreateRepositoryBuilder repositoryCreator = github.createRepository(getRepositoryName()); repository = repositoryCreator.create(); } String description = getRepositoryDescription(); if (description != null && !description.equals(repository.getDescription())) { repository.setDescription(description); } }