Java Code Examples for org.eclipse.egit.github.core.service.UserService#getUser()
The following examples show how to use
org.eclipse.egit.github.core.service.UserService#getUser() .
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: GithubApi.java From karamel with Apache License 2.0 | 6 votes |
/** * Blindly accepts user credentials, no validation with github. * * @param user * @param password * @return primary github email for the user * @throws se.kth.karamel.common.exception.KaramelException */ public synchronized static GithubUser registerCredentials(String user, String password) throws KaramelException { try { GithubApi.user = user; GithubApi.password = password; client.setCredentials(user, password); client.getUser(); Confs confs = Confs.loadKaramelConfs(); confs.put(Settings.GITHUB_USER_KEY, user); confs.put(Settings.GITHUB_PASSWORD_KEY, password); confs.writeKaramelConfs(); UserService us = new UserService(client); if (us == null) { throw new KaramelException("Could not find user or password incorret: " + user); } User u = us.getUser(); if (u == null) { throw new KaramelException("Could not find user or password incorret: " + user); } GithubApi.email = u.getEmail(); } catch (IOException ex) { logger.warn("Problem connecting to GitHub: " + ex.getMessage()); } return new GithubUser(GithubApi.user, GithubApi.password, GithubApi.email); }
Example 2
Source File: GitHubSourceConnector.java From apicurio-studio with Apache License 2.0 | 5 votes |
/** * @see io.apicurio.hub.api.github.IGitHubSourceConnector#getOrganizations() */ @Override public Collection<GitHubOrganization> getOrganizations() throws GitHubException, SourceConnectorException { logger.debug("Getting organizations for current user."); Collection<GitHubOrganization> rval = new HashSet<>(); try { GitHubClient client = githubClient(); // Add the user's personal org UserService userService = new UserService(client); User user = userService.getUser(); GitHubOrganization gho = new GitHubOrganization(); gho.setUserOrg(true); gho.setId(user.getLogin()); rval.add(gho); // Now all the user's orgs OrganizationService orgService = new OrganizationService(client); List<User> organizations = orgService.getOrganizations(); for (User org : organizations) { gho = new GitHubOrganization(); gho.setUserOrg(false); gho.setId(org.getLogin()); rval.add(gho); } } catch (IOException e) { logger.error("Error getting GitHub organizations.", e); throw new GitHubException("Error getting GitHub organizations.", e); } return rval; }
Example 3
Source File: GitHubSourceConnector.java From apicurio-studio with Apache License 2.0 | 5 votes |
/** * @see io.apicurio.hub.api.github.IGitHubSourceConnector#getRepositories(java.lang.String) */ @Override public Collection<GitHubRepository> getRepositories(String org) throws GitHubException, SourceConnectorException { logger.debug("Getting the repositories from organization {}", org); Collection<GitHubRepository> rval = new HashSet<>(); try { GitHubClient client = githubClient(); // First get the user's login id UserService userService = new UserService(client); User user = userService.getUser(); String userLogin = user.getLogin(); // Get the Org/User repositories RepositoryService repoService = new RepositoryService(client); List<Repository> repositories = null; if (org.equals(userLogin)) { Map<String, String> filters = new HashMap<String, String>(); filters.put("affiliation", "owner"); filters.put("visibility", "all"); repositories = repoService.getRepositories(filters); } else { repositories = repoService.getOrgRepositories(org); } for (Repository repository : repositories) { GitHubRepository ghrepo = new GitHubRepository(); ghrepo.setName(repository.getName()); ghrepo.setPriv(repository.isPrivate()); rval.add(ghrepo); } } catch (IOException e) { logger.error("Error getting GitHub repositories.", e); throw new GitHubException("Error getting GitHub repositories.", e); } return rval; }
Example 4
Source File: GitHubConnector.java From tool.accelerate.core with Apache License 2.0 | 5 votes |
/** * Must be called after #{createGitRepository()} */ public void pushAllChangesToGit() throws IOException { if (localRepository == null) { throw new IOException("Git has not been created, call createGitRepositoryFirst"); } try { UserService userService = new UserService(); userService.getClient().setOAuth2Token(oAuthToken); User user = userService.getUser(); String name = user.getLogin(); String email = user.getEmail(); if (email == null) { // This is the e-mail addressed used by GitHub on web commits where the users mail is private. See: // https://github.com/settings/emails email = name + "@users.noreply.github.com"; } localRepository.add().addFilepattern(".").call(); localRepository.commit() .setMessage("Initial commit") .setCommitter(name, email) .call(); PushCommand pushCommand = localRepository.push(); addAuth(pushCommand); pushCommand.call(); } catch (GitAPIException e) { throw new IOException("Error pushing changes to GitHub", e); } }