Java Code Examples for org.eclipse.egit.github.core.service.RepositoryService#getRepository()

The following examples show how to use org.eclipse.egit.github.core.service.RepositoryService#getRepository() . 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: GitHubSourceConnector.java    From apicurio-studio with Apache License 2.0 6 votes vote down vote up
/**
 * @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 2
Source File: JiraExporterTest.java    From rtc2jira with GNU General Public License v2.0 6 votes vote down vote up
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 3
Source File: GithubApi.java    From karamel with Apache License 2.0 5 votes vote down vote up
/**
 * 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 4
Source File: GitHubRepositoryCreationTest.java    From tool.accelerate.core with Apache License 2.0 5 votes vote down vote up
@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");
}