public GHMyself getMyself() throws IOException { return github.getMyself(); }
public GHMyself getMyself() throws IOException { return github.getMyself(); }
public GithubCurrentUserService(final GitHub gh) { this.gh = gh; try { this.user = gh.getMyself(); } catch (final IOException e) { throw new RuntimeException(e); } }
private void cleanBefore() throws Exception { String login = github.getMyself().getLogin(); List<String> repoNames = Arrays.asList( Paths.get(login, NAME).toString(), Paths.get(ORG, NAME).toString(), Paths.get(login, STORE_NAME).toString()); for (String repoName : repoNames) { TestCommon.checkAndDeleteBefore(repoName, github); } }
public static void addVersionStoreRepo(GitHub github, List<GHRepository> createdRepos, String storeName) throws IOException { String login = github.getMyself().getLogin(); GHRepository storeRepo = github.getRepository(Paths.get(login, storeName).toString()); createdRepos.add(storeRepo); } }
public String getBotUserLogin() { try { return trigger.getGitHub().getMyself().getLogin(); } catch (IOException ex) { LOGGER.log(Level.SEVERE, null, ex); return null; } } }
private static void checkAndDeleteBefore(List<String> repoNames, String storeName, GitHub github) throws IOException, InterruptedException { String user = github.getMyself().getLogin(); for (String repoName : repoNames) { for (String org : ORGS) { checkAndDeleteBefore(Paths.get(user, repoName).toString(), github); checkAndDeleteBefore(Paths.get(org, repoName).toString(), github); } } checkAndDeleteBefore(Paths.get(user, storeName).toString(), github); }
private static boolean isMyselfUser(GHUser user) { boolean ret = false; if (isNull(user)) { return false; } try { GitHub github = githubFor(URI.create(user.getHtmlUrl().toString())); ret = StringUtils.equals(user.getLogin(), github.getMyself().getLogin()); } catch (IOException e) { LOGGER.error("Can't connect retrieve user data from GitHub", e); } return ret; }
@Test(dependsOnMethods = {"testIdempotency", "testSameNameAcrossDifferentOrgs"}) public void testStoreUpdate() throws Exception { String user = github.getMyself().getLogin(); GHRepository storeRepo = github.getRepository(Paths.get(user, STORE_NAME).toString()); String latestCommit = storeRepo.getBranches().get(storeRepo.getDefaultBranch()).getSHA1(); GHContent store = storeRepo.getFileContent("store.json", latestCommit); try (InputStream stream = store.read(); InputStreamReader streamR = new InputStreamReader(stream)) { JsonElement json = new JsonParser().parse(streamR); assertNotNull(json); JsonElement images = json.getAsJsonObject().get("images"); assertNotNull(images); Object image1 = images.getAsJsonObject().get(IMAGE_1); assertNotNull(image1); Object image2 = images.getAsJsonObject().get(IMAGE_2); assertNotNull(image2); assertEquals(images.getAsJsonObject().get(IMAGE_1).getAsString(), TAG); assertEquals(images.getAsJsonObject().get(IMAGE_2).getAsString(), TAG); } }
public Iterable<GHRepository> getRepositories(final String orgName) { try { if (orgName.equals(this.user.getLogin())) { return this.gh.getMyself().listRepositories(); } else { return this.gh.getOrganization(orgName).listRepositories(); } } catch (final IOException e) { throw new RuntimeException(e); } }
public static void deleteAllRepos(String repoPrefix, String gitHubUsername, String gitHubPassword) throws IOException { GitHub gitHub = GitHub.connectUsingPassword(gitHubUsername, gitHubPassword); gitHub .getMyself() .getAllRepositories() .keySet() .stream() .filter(repoName -> repoName.startsWith(repoPrefix)) .forEach( repoName -> { String repoAddress = gitHubUsername + "/" + repoName; LOG.info("Removing repo " + repoAddress + "..."); try { gitHub.getRepository(repoAddress).delete(); } catch (IOException e) { e.printStackTrace(); } }); }
public GithubAuthenticationToken(String accessToken, String githubServer) throws IOException { super(new GrantedAuthority[] {}); this.accessToken = accessToken; this.gh = GitHub.connectUsingOAuth(githubServer, accessToken); GHUser me = gh.getMyself(); assert me!=null; setAuthenticated(true); this.userName = me.getLogin(); authorities.add(SecurityRealm.AUTHENTICATED_AUTHORITY); for (String name : gh.getMyOrganizations().keySet()) authorities.add(new GrantedAuthorityImpl(name)); }
@Override public List<Organization> getOrganizations(String accessToken) throws IOException, ServiceException { GitHub gitHub = GitHub.connectUsingOAuth(accessToken); List<Organization> organizations = gitHub.getMyself().getAllOrganizations().stream().map(organization -> { Organization result = new Organization(organization.getLogin()); result.setAvatarURL(organization.getAvatarUrl()); return result; }).collect(Collectors.toList()); Organization myself = new Organization(gitHub.getMyself().getLogin()); myself.setAvatarURL(gitHub.getMyself().getAvatarUrl()); organizations.add(myself); return organizations; }
/** * Forks this repository as your repository. * * @return * Newly forked repository that belong to you. */ public GHRepository fork() throws IOException { new Requester(root).method("POST").to(getApiTailUrl("forks"), null); // this API is asynchronous. we need to wait for a bit for (int i=0; i<10; i++) { GHRepository r = root.getMyself().getRepository(name); if (r!=null) return r; try { Thread.sleep(3000); } catch (InterruptedException e) { throw (IOException)new InterruptedIOException().initCause(e); } } throw new IOException(this+" was forked but can't find the new repository"); }
/** * Forks this repository as your repository. * * @return * Newly forked repository that belong to you. */ public GHRepository fork() throws IOException { new Requester(root).method("POST").to(getApiTailUrl("forks"), null); // this API is asynchronous. we need to wait for a bit for (int i=0; i<10; i++) { GHRepository r = root.getMyself().getRepository(name); if (r!=null) return r; try { Thread.sleep(3000); } catch (InterruptedException e) { throw (IOException)new InterruptedIOException().initCause(e); } } throw new IOException(this+" was forked but can't find the new repository"); }
@Override public List<Repository> getRepositories(String accessToken, String organizationName) throws IOException, ServiceException { GitHub gitHub = GitHub.connectUsingOAuth(accessToken); GHPerson person = StringUtils.isBlank(organizationName) ? gitHub.getMyself() : gitHub.getOrganization(organizationName); return person.listRepositories().asList().stream().map(repository -> { Repository repo = new Repository(repository.getName()); repo.setPrivate(repository.isPrivate()); repo.setUrl(repository.getHtmlUrl().toString()); return repo; }).collect(Collectors.toList()); }
@POST public FormValidation doTestGithubAccess( @QueryParameter("serverAPIUrl") final String serverAPIUrl, @QueryParameter("credentialsId") final String credentialsId) { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); try { GitHubBuilder builder = getBuilder(null, serverAPIUrl, credentialsId); if (builder == null) { return FormValidation.error("Unable to look up GitHub credentials using ID: " + credentialsId + "!!"); } GitHub gh = builder.build(); GHMyself me = gh.getMyself(); String name = me.getName(); String email = me.getEmail(); String login = me.getLogin(); String comment = String.format("Connected to %s as %s (%s) login: %s", serverAPIUrl, name, email, login); return FormValidation.ok(comment); } catch (Exception ex) { return FormValidation.error("Unable to connect to GitHub API: " + ex); } }
protected String getCurrentUserLogin(StaplerRequest request) throws IOException { GHUser self = GitHub.connectUsingOAuth(getSetupConfig().getGithubApiUrl(), getAccessToken(request)).getMyself(); return self.getLogin(); } }
protected void updateOfflineAccessTokenForUser(String accessToken) throws IOException { GHUser self = GitHub.connectUsingOAuth(getSetupConfig().getGithubApiUrl(), accessToken).getMyself(); String login = self.getLogin(); getSetupConfig().getGithubAccessTokenRepository().updateAccessToken(login, accessToken); }
public void init(int pullRequestNumber, File projectBaseDir) { initGitBaseDir(projectBaseDir); try { GitHub github; if (config.isProxyConnectionEnabled()) { github = new GitHubBuilder().withProxy(config.getHttpProxy()).withEndpoint(config.endpoint()).withOAuthToken(config.oauth()).build(); } else { github = new GitHubBuilder().withEndpoint(config.endpoint()).withOAuthToken(config.oauth()).build(); } setGhRepo(github.getRepository(config.repository())); setPr(ghRepo.getPullRequest(pullRequestNumber)); LOG.info("Starting analysis of pull request: " + pr.getHtmlUrl()); myself = github.getMyself().getLogin(); loadExistingReviewComments(); patchPositionMappingByFile = mapPatchPositionsToLines(pr); } catch (IOException e) { LOG.debug("Unable to perform GitHub WS operation", e); throw MessageException.of("Unable to perform GitHub WS operation: " + e.getMessage()); } }