@Override public Repository getRepository(final String id, final Map<String, String> env) { return getRepository(credentials, id, env); }
public GitHub(final GitCredentials credentials, final ConfigProperties configProperties) { this.id = toHex("GitHub"); this.name = "GitHub"; this.credentials = credentials; this.configProperties = configProperties; }
@Override public Repository getRepository(final String id, final Map<String, String> env) { return getRepository(credentials, id, env); }
@Override public Optional<Source> apply(final GitConfig gitConfig) { checkNotEmpty("repo-name parameter is mandatory", gitConfig.getRepoName()); if (Boolean.parseBoolean(gitConfig.getCreateRepo())) { final URI uri = URI.create("git://" + gitConfig.getRepoName()); FileSystems.newFileSystem(uri, new HashMap<String, Object>() { if (gitConfig.getOrigin() != null && !gitConfig.getOrigin().isEmpty()) { put("origin", gitConfig.getOrigin()); } else { put("init", Boolean.TRUE); if (gitConfig.getOutPath() != null && !gitConfig.getOutPath().isEmpty()) { put("out-dir", gitConfig.getOutPath()); final URI uri = URI.create("git://" + gitConfig.getRepoName() + "?sync"); try { FileSystems.getFileSystem(uri); final GitRepository gitRepository = (GitRepository) new UFLocal().getRepository(gitConfig.getRepoName(), Collections.emptyMap()); final Optional<Source> source_ = Optional.ofNullable(gitRepository.getSource((gitConfig.getBranch() != null && !gitConfig.getBranch().isEmpty()) ? gitConfig.getBranch() : "master")); if (source_.isPresent()) { Source source = source_.get();
@Test public void sourceCloneTest() throws Exception { final URI uri = URI.create("git://tempx"); final FileSystem fs = FileSystems.newFileSystem(uri, new HashMap<String, Object>() {{ put("init", Boolean.TRUE); put("internal", Boolean.TRUE); put("out-dir", tempPath.getAbsolutePath()); }}); final UFLocal local = new UFLocal(); final GitRepository repository = (GitRepository) local.getRepository("tempx", Collections.emptyMap()); final Source source = repository.getSource("master"); assertNotNull(source); assertEquals(source.getPath().getFileSystem(), fs); } }
@Test public void repositoryVisitorDiffDeletedTest() throws IOException { final GitHub gitHub = new GitHub(); final GitRepository repository = (GitRepository) gitHub.getRepository("mbarkley/appformer-playground", new HashMap<String, String>() { final Source source = repository.getSource("master"); final URI originRepo = URI.create("git://" + repository.getName()); final JGitFileSystemProvider provider = (JGitFileSystemProvider) FileSystemProviders.resolveProvider(originRepo);
@Test public void hello() throws Exception { final GitHub gitHub = new GitHub(); final GitRepository repository = (GitRepository) gitHub.getRepository("salaboy/drools-workshop", new HashMap<String, String>() {{ put("out-dir", tempPath.getAbsolutePath()); }}); final Source source = repository.getSource("master"); assertNotNull(source); } }
@Override public Source getSource() { return getSource("master"); }
if (env != null && !env.isEmpty()) { final String _protocol = env.getOrDefault("protocol", Protocol.HTTPS.toString()); Protocol tempProtocol; try { tempProtocol = Protocol.valueOf(_protocol); } catch (Exception ex) { tempProtocol = Protocol.HTTPS; return new GitHubRepository(this, repositoryId, ids[0], ids[1], protocol.toURI("github.com", repositoryId), credential,
new HashMap<String, Object>(env) { putIfAbsent("origin", uri.toString()); putIfAbsent("out-dir", bareRepoDir); if (credentials.getUser() != null) { putIfAbsent("username", credentials.getUser()); putIfAbsent("password", credentials.getPassw()); path); return new GitSource(this, result);
public GitHub() { this(new GitCredentials()); }
public UFLocal(final GitCredentials credentials, final ConfigProperties configProperties) { this.id = toHex("UFLocal"); this.name = "UFLocal"; this.credentials = credentials; this.configProperties = configProperties; }
public URI toURI(final String host, final String id) { return URI.create(toString().toLowerCase() + "://" + host + "/" + id + ".git"); } }
@Override public Repository getRepository(final GitCredentials credential, final String repositoryId, final Map<String, String> env) { checkNotNull("credential", credential); checkNotEmpty("id", repositoryId); return new GitRepository(this, repositoryId, repositoryId, URI.create("git://local"), credential, env, configProperties); }
@Test public void sourceCloneTest() throws Exception { final URI uri = URI.create("git://tempx"); final FileSystem fs = FileSystems.newFileSystem(uri, new HashMap<String, Object>() {{ put("init", Boolean.TRUE); put("internal", Boolean.TRUE); put("out-dir", tempPath.getAbsolutePath()); }}); final UFLocal local = new UFLocal(); final GitRepository repository = (GitRepository) local.getRepository("tempx", Collections.emptyMap()); final Source source = repository.getSource("master"); assertNotNull(source); assertEquals(source.getPath().getFileSystem(), fs); } }
GitHub github = GitHub.connectUsingPassword("Username","Password"); github.getRepository("Repository name");
@Override public Repository getRepository(final String id) { return getRepository(id, Collections.emptyMap()); }
public UFLocal() { this(new GitCredentials()); }
@Override public Repository getRepository(final String id) { return getRepository(id, Collections.emptyMap()); }
Properties props = new Properties(); props.setProperty("login", "somebody@somewhere.com"); props.setProperty("password", "YourGithubPassword"); GitHub gitHub = GitHubBuilder.fromProperties(props).build(); GHRepository repository = gitHub.getRepository("your/repo"); Calendar cal = Calendar.getInstance(); cal.set(2014, 0, 4); Date since = cal.getTime(); cal.set(2014, 0, 14); Date until = cal.getTime(); GHCommitQueryBuilder queryBuilder = repository.queryCommits().since(since).until(until); PagedIterable<GHCommit> commits = queryBuilder.list(); Iterator<GHCommit> iterator = commits.iterator(); while (iterator.hasNext()) { GHCommit commit = iterator.next(); System.out.println("Commit: " + commit.getSHA1() + ", info: " + commit.getCommitShortInfo().getMessage() + ", author: " + commit.getAuthor()); }