public String getCurrentLogin() { return this.user.getLogin(); }
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); } }
/** * Returns the read-only list of all the public verified keys of the current user. * * Differently from the getPublicKeys() method, the retrieval of the user's * verified public keys does not require any READ/WRITE OAuth Scope to the * user's profile. * * @return * Always non-null. */ public List<GHVerifiedKey> getPublicVerifiedKeys() throws IOException { return Collections.unmodifiableList(Arrays.asList(root.retrieve().to( "/users/" + getLogin() + "/keys", GHVerifiedKey[].class))); }
public String getBotUserLogin() { try { return trigger.getGitHub().getMyself().getLogin(); } catch (IOException ex) { LOGGER.log(Level.SEVERE, null, ex); return null; } } }
/** * Returns the read-only list of all the public verified keys of the current user. * * Differently from the getPublicKeys() method, the retrieval of the user's * verified public keys does not require any READ/WRITE OAuth Scope to the * user's profile. * * @return * Always non-null. */ public List<GHVerifiedKey> getPublicVerifiedKeys() throws IOException { return Collections.unmodifiableList(Arrays.asList(root.retrieve().to( "/users/" + getLogin() + "/keys", GHVerifiedKey[].class))); }
/** * Returns the read-only list of all the public verified keys of the current user. * * Differently from the getPublicKeys() method, the retrieval of the user's * verified public keys does not require any READ/WRITE OAuth Scope to the * user's profile. * * @return * Always non-null. */ public List<GHVerifiedKey> getPublicVerifiedKeys() throws IOException { return Collections.unmodifiableList(Arrays.asList(root.retrieve().to( "/users/" + getLogin() + "/keys", GHVerifiedKey[].class))); }
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 void updateStore(String store, String img, String tag) throws IOException { if (store == null) { log.info("Image tag store cannot be null. Skipping store update..."); return; } log.info("Updating store: {} with image: {} tag: {}...", store, img, tag); GHRepository storeRepo; try { GHMyself myself = gitHubUtil.getMyself(); String ownerOrg = myself.getLogin(); storeRepo = gitHubUtil.getRepo(Paths.get(ownerOrg, store).toString()); } catch (IOException e) { storeRepo = gitHubUtil.createPublicRepo(store); } updateStoreOnGithub(storeRepo, Constants.STORE_JSON_FILE, img, tag); }
public void updateStore(String store, String img, String tag) throws IOException { if (store == null) { log.info("Image tag store cannot be null. Skipping store update..."); return; } log.info("Updating store: {} with image: {} tag: {}...", store, img, tag); GHRepository storeRepo; try { GHMyself myself = gitHubUtil.getMyself(); String ownerOrg = myself.getLogin(); storeRepo = gitHubUtil.getRepo(Paths.get(ownerOrg, store).toString()); } catch (IOException e) { storeRepo = gitHubUtil.createPublicRepo(store); } updateStoreOnGithub(storeRepo, Constants.STORE_JSON_FILE, img, tag); }
/** * Gets the {@link GHUser} that represents yourself. */ @WithBridgeMethods(GHUser.class) public GHMyself getMyself() throws IOException { requireCredential(); GHMyself u = retrieve().to("/user", GHMyself.class); u.root = this; users.put(u.getLogin(), u); return u; }
@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); } }
@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; }
@RequirePOST @Restricted(DoNotUse.class) // WebOnly @SuppressWarnings("unused") public FormValidation doVerifyCredentials( @QueryParameter String apiUrl, @QueryParameter String credentialsId) throws IOException { Jenkins.getActiveInstance().checkPermission(Jenkins.ADMINISTER); GitHubServerConfig config = new GitHubServerConfig(credentialsId); config.setApiUrl(apiUrl); config.setClientCacheSize(0); GitHub gitHub = new GitHubLoginFunction().apply(config); try { if (gitHub != null && gitHub.isCredentialValid()) { return FormValidation.ok("Credentials verified for user %s, rate limit: %s", gitHub.getMyself().getLogin(), gitHub.getRateLimit().remaining); } else { return FormValidation.error("Failed to validate the account"); } } catch (IOException e) { return FormValidation.error(e, "Failed to validate the account"); } }
/** * 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); } }
/** * 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); } }
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()); } }