org.eclipse.egit.github.core.service.RepositoryService Java Examples
The following examples show how to use
org.eclipse.egit.github.core.service.RepositoryService.
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: RepoTask.java From Bitocle with Apache License 2.0 | 6 votes |
@Override protected void onPreExecute() { context = fragment.getContentView().getContext(); flag = fragment.getFlag(); adapter = fragment.getRepoItemAdapter(); list = fragment.getRepoItemList(); GitHubClient client = fragment.getClient(); service = new RepositoryService(client); if (flag == Flag.REPO_FIRST) { fragment.setContentEmpty(false); fragment.setContentShown(false); } }
Example #2
Source File: GitHubSourceConnector.java From apicurio-studio with Apache License 2.0 | 6 votes |
/** * @see io.apicurio.hub.api.github.IGitHubSourceConnector#getBranches(java.lang.String, java.lang.String) */ @Override public Collection<SourceCodeBranch> getBranches(String org, String repo) throws GitHubException, SourceConnectorException { logger.debug("Getting the branches from {} / {}", org, repo); Collection<SourceCodeBranch> rval = new HashSet<>(); try { GitHubClient client = githubClient(); RepositoryService repoService = new RepositoryService(client); Repository repository = repoService.getRepository(org, repo); List<RepositoryBranch> branches = repoService.getBranches(repository); for (RepositoryBranch branch : branches) { SourceCodeBranch ghBranch = new SourceCodeBranch(); ghBranch.setName(branch.getName()); ghBranch.setCommitId(branch.getCommit().getSha()); rval.add(ghBranch); } } catch (IOException e) { logger.error("Error getting GitHub branches.", e); throw new GitHubException("Error getting GitHub branches.", e); } return rval; }
Example #3
Source File: JiraExporterTest.java From rtc2jira with GNU General Public License v2.0 | 6 votes |
public void testCreateOrUpdateItem(@Mocked ClientResponse clientResponse, @Mocked StorageEngine store, @Mocked Repository repoMock, @Mocked RepositoryService service, @Mocked IssueService issueServiceMock, @Mocked ODocument workItem) throws Exception { new Expectations() { { settings.hasJiraProperties(); result = true; clientResponse.getStatus(); result = Status.OK.getStatusCode(); service.getRepository(anyString, anyString); result = repoMock; } }; JiraExporter jiraExporter = JiraExporter.INSTANCE; jiraExporter.initialize(settings, store); jiraExporter.createOrUpdateItem(workItem); new Verifications() { { } }; }
Example #4
Source File: GithubApi.java From karamel with Apache License 2.0 | 6 votes |
/** * Gets all repositories for a given organization/user. * * @param orgName * @return List of repositories * @throws KaramelException */ public synchronized static List<RepoItem> getRepos(String orgName) throws KaramelException { if (cachedRepos.get(orgName) != null) { return cachedRepos.get(orgName); } try { RepositoryService rs = new RepositoryService(client); List<Repository> repos; // If we are looking for the repositories for the current user if (GithubApi.getUser().equalsIgnoreCase(orgName)) { repos = rs.getRepositories(orgName); } else { // If we are looking for the repositories for a given organization repos = rs.getOrgRepositories(orgName); } List<RepoItem> repoItems = new ArrayList<>(); for (Repository r : repos) { repoItems.add(new RepoItem(r.getName(), r.getDescription(), r.getSshUrl())); } cachedRepos.put(orgName, repoItems); return repoItems; } catch (IOException ex) { throw new KaramelException("Problem listing GitHub repositories: " + ex.getMessage()); } }
Example #5
Source File: GithubApi.java From karamel with Apache License 2.0 | 6 votes |
/** * Create a repository for a given organization with a description * * @param org * @param repoName * @param description * @return RepoItem bean/json object * @throws KaramelException */ public synchronized static RepoItem createRepoForOrg(String org, String repoName, String description) throws KaramelException { try { OrganizationService os = new OrganizationService(client); RepositoryService rs = new RepositoryService(client); Repository r = new Repository(); r.setName(repoName); r.setOwner(os.getOrganization(org)); r.setDescription(description); rs.createRepository(org, r); cloneRepo(org, repoName); cachedRepos.remove(org); return new RepoItem(repoName, description, r.getSshUrl()); } catch (IOException ex) { throw new KaramelException("Problem creating the repository " + repoName + " for organization " + org + " : " + ex.getMessage()); } }
Example #6
Source File: GithubApi.java From karamel with Apache License 2.0 | 6 votes |
/** * Create a repository in a given github user's local account. * * @param repoName * @param description * @throws KaramelException */ public synchronized static void createRepoForUser(String repoName, String description) throws KaramelException { try { UserService us = new UserService(client); RepositoryService rs = new RepositoryService(client); Repository r = new Repository(); r.setName(repoName); r.setOwner(us.getUser()); r.setDescription(description); rs.createRepository(r); cloneRepo(getUser(), repoName); cachedRepos.remove(GithubApi.getUser()); } catch (IOException ex) { throw new KaramelException("Problem creating " + repoName + " for user " + ex.getMessage()); } }
Example #7
Source File: RepoTask.java From Bitocle with Apache License 2.0 | 6 votes |
@Override protected void onPreExecute() { mainFragment.setRefreshStatus(true); context = mainFragment.getContentView().getContext(); refreshType = mainFragment.getRefreshType(); GitHubClient gitHubClient = mainFragment.getGitHubClient(); repositoryService = new RepositoryService(gitHubClient); repoItemAdapter = mainFragment.getRepoItemAdapter(); repoItemList = mainFragment.getRepoItemList(); if (refreshType == RefreshType.REPO_FIRST) { mainFragment.setContentShown(false); } }
Example #8
Source File: GitHubConnector.java From tool.accelerate.core with Apache License 2.0 | 6 votes |
/** * Creates a repository on GitHub and in a local temporary directory. This is a one time operation as * once it is created on GitHub and locally it cannot be recreated. */ public File createGitRepository(String repositoryName) throws IOException { RepositoryService service = new RepositoryService(); service.getClient().setOAuth2Token(oAuthToken); Repository repository = new Repository(); repository.setName(repositoryName); repository = service.createRepository(repository); repositoryLocation = repository.getHtmlUrl(); CloneCommand cloneCommand = Git.cloneRepository() .setURI(repository.getCloneUrl()) .setDirectory(localGitDirectory); addAuth(cloneCommand); try { localRepository = cloneCommand.call(); } catch (GitAPIException e) { throw new IOException("Error cloning to local file system", e); } return localGitDirectory; }
Example #9
Source File: RepoTask.java From Bitocle with Apache License 2.0 | 6 votes |
@Override protected void onPreExecute() { context = fragment.getContentView().getContext(); flag = fragment.getFlag(); adapter = fragment.getRepoItemAdapter(); list = fragment.getRepoItemList(); GitHubClient client = fragment.getClient(); service = new RepositoryService(client); if (flag == Flag.REPO_FIRST) { fragment.setContentEmpty(false); fragment.setContentShown(false); } }
Example #10
Source File: GithubApi.java From karamel with Apache License 2.0 | 5 votes |
/** * Clone an existing github repo. * * @param owner * @param repoName * @throws se.kth.karamel.common.exception.KaramelException */ public synchronized static void cloneRepo(String owner, String repoName) throws KaramelException { Git result = null; try { RepositoryService rs = new RepositoryService(client); Repository r = rs.getRepository(owner, repoName); String cloneURL = r.getSshUrl(); // prepare a new folder for the cloned repository File localPath = new File(Settings.COOKBOOKS_PATH + File.separator + repoName); if (localPath.isDirectory() == false) { localPath.mkdirs(); } else { throw new KaramelException("Local directory already exists. Delete it first: " + localPath); } logger.debug("Cloning from " + cloneURL + " to " + localPath); result = Git.cloneRepository() .setURI(cloneURL) .setDirectory(localPath) .call(); // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks! logger.debug("Cloned repository: " + result.getRepository().getDirectory()); } catch (IOException | GitAPIException ex) { throw new KaramelException("Problem cloning repo: " + ex.getMessage()); } finally { if (result != null) { result.close(); } } }
Example #11
Source File: AddTask.java From Bitocle with Apache License 2.0 | 5 votes |
@Override protected void onPreExecute() { context = fragment.getContentView().getContext(); GitHubClient client = fragment.getClient(); service = new RepositoryService(client); pull = fragment.getPull(); listView = fragment.getListView(); adapter = fragment.getRepoItemAdapter(); list = fragment.getRepoItemList(); pull.setRefreshing(true); }
Example #12
Source File: CommitTask.java From Bitocle with Apache License 2.0 | 5 votes |
@Override protected void onPreExecute() { mainFragment.setContentShown(false); mainFragment.setRefreshStatus(true); context = mainFragment.getContentView().getContext(); GitHubClient gitHubClient = mainFragment.getGitHubClient(); repositoryService = new RepositoryService(gitHubClient); commitService = new CommitService(gitHubClient); commitItemAdapter = mainFragment.getCommitItemAdapter(); commitItemList = mainFragment.getCommitItemList(); }
Example #13
Source File: AddTask.java From Bitocle with Apache License 2.0 | 5 votes |
@Override protected void onPreExecute() { mainFragment.getPullToRefreshLayout().setRefreshing(true); context = mainFragment.getContentView().getContext(); GitHubClient gitHubClient = mainFragment.getGitHubClient(); repositoryService = new RepositoryService(gitHubClient); repoItemAdapter = mainFragment.getRepoItemAdapter(); repoItemList = mainFragment.getRepoItemList(); }
Example #14
Source File: AddTask.java From Bitocle with Apache License 2.0 | 5 votes |
@Override protected void onPreExecute() { context = fragment.getContentView().getContext(); GitHubClient client = fragment.getClient(); service = new RepositoryService(client); pull = fragment.getPull(); listView = fragment.getListView(); adapter = fragment.getRepoItemAdapter(); list = fragment.getRepoItemList(); pull.setRefreshing(true); }
Example #15
Source File: GitHubRepositoryCreationTest.java From tool.accelerate.core with Apache License 2.0 | 5 votes |
@Test public void testGitHubRepositoryCreation() throws Exception { String oAuthToken = System.getProperty("gitHubOauth"); assumeTrue(oAuthToken != null && !oAuthToken.isEmpty()); String name = "TestAppAcceleratorProject"; String port = System.getProperty("liberty.test.port"); URI baseUri = new URI("http://localhost:" + port + "/start"); ServiceConnector serviceConnector = new MockServiceConnector(baseUri); Services services = new Services(); Service service = new Service(); service.setId("wibble"); List<Service> serviceList = Collections.singletonList(service); services.setServices(serviceList); ProjectConstructionInputData inputData = new ProjectConstructionInputData(services, serviceConnector, name, ProjectConstructor.DeployType.LOCAL, ProjectConstructor.BuildType.MAVEN, null, null, null, null, null, false); ProjectConstructor constructor = new ProjectConstructor(inputData); GitHubConnector connector = new GitHubConnector(oAuthToken); GitHubWriter writer = new GitHubWriter(constructor.buildFileMap(), inputData.appName, connector); writer.createProjectOnGitHub(); RepositoryService repositoryService = new RepositoryService(); repositoryService.getClient().setOAuth2Token(oAuthToken); UserService userService = new UserService(); userService.getClient().setOAuth2Token(oAuthToken); ContentsService contentsService = new ContentsService(); contentsService.getClient().setOAuth2Token(oAuthToken); Repository repository = repositoryService.getRepository(userService.getUser().getLogin(), name); checkFileExists(contentsService, repository, "pom.xml"); checkFileExists(contentsService, repository, "README.md"); }
Example #16
Source File: ForkRepositoryWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<String, Object>(); String repoOwner = (String) workItem.getParameter("RepoOwner"); String repoName = (String) workItem.getParameter("RepoName"); String organization = (String) workItem.getParameter("Organization"); Repository forkedRepository; RepositoryService repoService = auth.getRespositoryService(this.userName, this.password); RepositoryId toBeForkedRepo = new RepositoryId(repoOwner, repoName); if (StringUtils.isNotEmpty(organization)) { forkedRepository = repoService.forkRepository(toBeForkedRepo, organization); } else { forkedRepository = repoService.forkRepository(toBeForkedRepo); } results.put(RESULTS_VALUE, new RepositoryInfo(forkedRepository)); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }
Example #17
Source File: GitHubExporter.java From rtc2jira with GNU General Public License v2.0 | 5 votes |
@Override public void initialize(Settings settings, StorageEngine engine) throws IOException { this.store = new GitHubStorage(engine); this.client = new GitHubClient(); this.service = new RepositoryService(client); this.issueService = new IssueService(client); client.setCredentials(settings.getGithubUser(), settings.getGithubPassword()); client.setOAuth2Token(settings.getGithubToken()); repository = service.getRepository(settings.getGithubRepoOwner(), settings.getGithubRepoName()); }
Example #18
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 #19
Source File: ListRepositoriesWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<String, Object>(); String user = (String) workItem.getParameter("User"); RepositoryService repoService = auth.getRespositoryService(this.userName, this.password); List<Repository> userRepos = repoService.getRepositories(user); List<RepositoryInfo> resultRepositoryInformation = new ArrayList<>(); if (userRepos != null) { for (Repository repo : userRepos) { resultRepositoryInformation.add(new RepositoryInfo(repo)); } } else { logger.info("No repositories found for " + user); } results.put(RESULTS_VALUE, resultRepositoryInformation); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }
Example #20
Source File: GithubAuth.java From jbpm-work-items with Apache License 2.0 | 4 votes |
public RepositoryService getRespositoryService(String username, String password) throws IOException { return new RepositoryService(getGitHubClient(username, password)); }
Example #21
Source File: GithubApi.java From karamel with Apache License 2.0 | 2 votes |
/** * Search github for organizations/repositories/users using the GitHub API. * * @param query * @throws IOException */ public synchronized static void searchRepos(String query) throws IOException { RepositoryService rs = new RepositoryService(client); List<SearchRepository> listRepos = rs.searchRepositories(query); }