Refine search
public void scanRepository(GHRepository repo) { logger.info("scanning repo: {}", repo.getName()); ObjectNode n = mapper.createObjectNode(); n.put("name", repo.getName()); n.put("description", repo.getDescription()); n.put("fullName", repo.getFullName()); n.put("homepage", repo.getHomepage()); n.put("sshUrl", repo.getSshUrl()); if (repo.getHtmlUrl() != null) { n.put("htmlUrl", repo.getHtmlUrl().toString()); } n.put("url", repo.getUrl().toString()); n.put("gitTransportUrl", repo.getGitTransportUrl()); String cypher = "merge (r:SCMRepo:GitHubRepo {url:{url}}) set r+={props},r.updateTs=timestamp() return r"; getProjector().getNeoRxClient().execCypher(cypher, "url", repo.getUrl().toString(), "props", n); }
@Override public GHPullRequest apply(Integer input) { try { return ghRepository.getPullRequest(input); } catch (IOException e) { LOGGER.error("Can't fetch pr by num {}", input, e); return null; } } }
/** * If this thread is about a commit, return that commit. * * @return null if this thread is not about a commit. */ public GHCommit getBoundCommit() throws IOException { if (!"Commit".equals(subject.type)) return null; return repository.getCommit(subject.url.substring(subject.url.lastIndexOf('/') + 1)); }
@Override String getApiRoute() { return String.format("/repos/%s/%s/hooks/%d", repository.getOwnerName(), repository.getName(), id); } }
public GHRepository createFork(GHRepository repo) throws IOException { try { return repo.fork(); } catch (IOException e) { log.error("Could not fork {}", repo.getFullName(), e); } return null; }
private static Exception checkAndDelete(GHRepository repo) { log.info("deleting {}", repo.getFullName()); try { repo.delete(); } catch (Exception e) { return e; } return null; }
@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()); }
@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 void setDefaultBranch(String branchName) throws IOException { ghRepo.setDefaultBranch(branchName); ghRepo = gitHub.getRepository(ghRepo.getFullName()); }
public String forkRepository(String repository, AbstractStep step) throws IOException { GitHub gh = RepairnatorConfig.getInstance().getGithub(); showGitHubRateInformation(gh, step); if (gh.getRateLimit().remaining > 10) { GHRepository originalRepo = gh.getRepository(repository); if (originalRepo != null) { return originalRepo.fork().getUrl().toString(); } } return null; }
/** * Forked repositories have a 'source' attribute that specifies the ultimate source of the forking chain. * * @return * {@link GHRepository} that points to the root repository where this repository is forked * (indirectly or directly) from. Otherwise null. * @see #getParent() */ public GHRepository getSource() throws IOException { if (source == null) return null; if (source.root == null) source = root.getRepository(source.getFullName()); return source; }
void updateCommitStatus(String revision, String pipelineStage, String trackbackURL, String repository, GHCommitState state, String usernameToUse, String passwordToUse, String oauthAccessTokenToUse, String endPointToUse) throws Exception { GitHub github = createGitHubClient(usernameToUse, passwordToUse, oauthAccessTokenToUse, endPointToUse); GHRepository ghRepository = github.getRepository(repository); ghRepository.createCommitStatus(revision, state, trackbackURL, "", pipelineStage); }
public PagedIterator<GHCommitComment> _iterator(int pageSize) { return new PagedIterator<GHCommitComment>(owner.root.retrieve().asIterator(String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), GHCommitComment[].class, pageSize)) { @Override protected void wrapUp(GHCommitComment[] page) { for (GHCommitComment c : page) c.wrap(owner); } }; } };
private GitHubRepository mapGhRepository(GHRepository gitHubRepository) throws IOException { String repositoryName = gitHubRepository.getName(); int stars = gitHubRepository.listStargazers().asList().size(); int openPullRequests = gitHubRepository.getPullRequests(GHIssueState.OPEN).size(); int pullRequests = openPullRequests + gitHubRepository.getPullRequests(GHIssueState.CLOSED).size(); int openIssues = gitHubRepository.getOpenIssueCount(); int branches = gitHubRepository.getBranches().size(); int collaborators = gitHubRepository.getCollaborators().size(); int forks = gitHubRepository.getForks(); int watchers = gitHubRepository.getWatchers(); return new GitHubRepository(repositoryName, stars, openPullRequests, pullRequests, openIssues, branches, collaborators, forks, watchers); }
private GHPullRequest pullRequestFrom(GitConfig gitConfig, int currentPullRequestID) throws IOException { return loginWith(gitConfig) .getRepository(GHUtils.parseGithubUrl(gitConfig.getEffectiveUrl())) .getPullRequest(currentPullRequestID); }
protected void updateStoreOnGithub(GHRepository repo, String path, String img, String tag) throws IOException { try { repo.getFileContent(path); } catch (IOException e) { repo.createContent("", "initializing store", path); } String latestCommit = repo.getBranches().get(repo.getDefaultBranch()).getSHA1(); log.info("Loading image store at commit {}", latestCommit); GHContent content = repo.getFileContent(path, latestCommit); if (content.isFile()) { JsonElement json; try (InputStream stream = content.read(); InputStreamReader streamR = new InputStreamReader(stream)) { try { json = new JsonParser().parse(streamR); } catch (JsonParseException e) { log.warn("Not a JSON format store. Clearing and rewriting as JSON..."); json = JsonNull.INSTANCE; } } String jsonOutput = getAndModifyJsonString(json, img, tag); content.update(jsonOutput, String.format("Updated image %s with tag %s.\n@rev none@", img, tag), repo.getDefaultBranch()); } }
public GithubRepository(GHRepository repository) { this.repository = repository; URL htmlUrl = repository.getHtmlUrl(); if (htmlUrl != null) { setHtmlUrl(htmlUrl.toString()); } setName(repository.getName()); setCloneUrl(repository.getGitTransportUrl()); }
public DynamicProject createNewProject(final GHRepository githubRepository, final String accessToken, final String user) { try { new GithubRepositoryService(githubRepository).linkProjectToCi(accessToken, user); final OrganizationContainer folder = this.organizationRepository.getOrCreateContainer(githubRepository.getOwner().getLogin()); final String projectName = githubRepository.getName(); final DynamicProject project = folder.createProject(DynamicProject.class, projectName); project.setDescription(format("<a href=\"%s\">%s</a>", githubRepository.getUrl(), githubRepository.getUrl())); project.setConcurrentBuild(true); if (StringUtils.isNotEmpty(SetupConfig.get().getLabel())) { project.setAssignedLabel(Jenkins.getInstance().getLabel(SetupConfig.get().getLabel())); } project.addProperty(new ParametersDefinitionProperty(new GithubBranchParameterDefinition("BRANCH", "master", githubRepository.getHtmlUrl().toString()))); project.addProperty(new GithubRepoProperty(githubRepository.getHtmlUrl().toExternalForm())); project.addProperty(new BuildTypeProperty(SetupConfig.get().getDefaultBuildType())); project.addProperty(new DynamicProjectBranchTabsProperty("master")); project.addProperty(new RebuildSettings(true, false)); project.addProperty(new JobUiProperty(SetupConfig.get().isDefaultToNewUi())); project.save(); folder.addItem(project); folder.save(); return project; } catch (final IOException e) { throw new RuntimeException(e); } }
/** * Does this repository match the repository referenced in the given {@link GHCommitPointer}? */ public boolean matches(GHRepository repo) throws IOException { return userName.equals(repo.getOwner().getLogin()) // TODO: use getOwnerName && repositoryName.equals(repo.getName()) && host.equals(repo.getHtmlUrl().getHost()); }
@Override public boolean hasCloneUrl(String url) { if (super.hasCloneUrl(url)) { return true; } return Strings.equalAnyValue(url, repository.getGitTransportUrl(), repository.gitHttpTransportUrl(), repository.getSshUrl(), repository.getUrl(), repository.getSvnUrl()); }