Java Code Examples for org.kohsuke.github.GitHub#getMyself()
The following examples show how to use
org.kohsuke.github.GitHub#getMyself() .
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: GitPluginCLI.java From updatebot with Apache License 2.0 | 5 votes |
@Override public void configUserNameAndEmail(File dir) { String email = null; String personName = null; try { GitHub github = configuration.getGithub(); if (github != null) { GHMyself myself = github.getMyself(); if (myself != null) { email = myself.getEmail(); personName = myself.getName(); if (Strings.empty(personName)) { configuration.warn(LOG, "No name available for GitHub login!"); personName = myself.getLogin(); } } } } catch (IOException e) { configuration.warn(LOG, "Failed to load github username and email: " + e, e); } if (Strings.notEmpty(email)) { ProcessHelper.runCommandAndLogOutput(configuration, LOG, dir, "git", "config", "user.email", email); } else { configuration.error(LOG, "No email available for GitHub login!"); } if (Strings.notEmpty(personName)) { ProcessHelper.runCommandAndLogOutput(configuration, LOG, dir, "git", "config", "user.name", personName); } else { configuration.error(LOG, "No name available for GitHub login!"); } }
Example 2
Source File: GithubCurrentUserService.java From DotCi with MIT License | 5 votes |
public GithubCurrentUserService(final GitHub gh) { this.gh = gh; try { this.user = gh.getMyself(); } catch (final IOException e) { throw new RuntimeException(e); } }
Example 3
Source File: LoggedInUserInfo.java From github-oauth-authorization-plugin with Apache License 2.0 | 4 votes |
public LoggedInUserInfo(GitHub gitHub) throws IOException { this.gitHub = gitHub; gitHubUser = gitHub.getMyself(); user = new User(gitHubUser.getLogin(), gitHubUser.getName(), gitHubUser.getEmail()); }
Example 4
Source File: GithubScm.java From blueocean-plugin with MIT License | 4 votes |
@Override public Container<ScmOrganization> getOrganizations() { StaplerRequest request = Stapler.getCurrentRequest(); String credentialId = GithubCredentialUtils.computeCredentialId(getCredentialIdFromRequest(request), getId(), getUri()); User authenticatedUser = getAuthenticatedUser(); final StandardUsernamePasswordCredentials credential = CredentialsUtils.findCredential(credentialId, StandardUsernamePasswordCredentials.class, new BlueOceanDomainRequirement()); if(credential == null){ throw new ServiceException.BadRequestException(String.format("Credential id: %s not found for user %s", credentialId, authenticatedUser.getId())); } String accessToken = credential.getPassword().getPlainText(); try { GitHub github = GitHubFactory.connect(accessToken, getUri()); final Link link = getLink().rel("organizations"); Map<String, ScmOrganization> orgMap = new LinkedHashMap<>(); // preserve the same order that github org api returns for(Map.Entry<String, GHOrganization> entry: github.getMyOrganizations().entrySet()){ orgMap.put(entry.getKey(), new GithubOrganization(GithubScm.this, entry.getValue(), credential, link)); } GHMyself user = github.getMyself(); if(orgMap.get(user.getLogin()) == null){ //this is to take care of case if/when github starts reporting user login as org later on orgMap = new HashMap<>(orgMap); orgMap.put(user.getLogin(), new GithubUserOrganization(user, credential, this)); } final Map<String, ScmOrganization> orgs = orgMap; return new Container<ScmOrganization>() { @Override public ScmOrganization get(String name) { ScmOrganization org = orgs.get(name); if(org == null){ throw new ServiceException.NotFoundException(String.format("GitHub organization %s not found", name)); } return org; } @Override public Link getLink() { return link; } @Override public Iterator<ScmOrganization> iterator() { return orgs.values().iterator(); } }; } catch (IOException e) { if(e instanceof HttpException) { HttpException ex = (HttpException) e; if (ex.getResponseCode() == 401) { throw new ServiceException .PreconditionRequired("Invalid GitHub accessToken", ex); }else if(ex.getResponseCode() == 403){ throw new ServiceException .PreconditionRequired("GitHub accessToken does not have required scopes. Expected scopes 'user:email, repo'", ex); } } throw new ServiceException.UnexpectedErrorException(e.getMessage(), e); } }