File repoDir = new File("test-git/.git"); // open the repository Repository repo = new Repository(repoDir); // find the HEAD Commit head = repo.mapCommit(Constants.HEAD); // retrieve the tree in HEAD Tree tree = head.getTree(); // 1.2.0 api version here // find a file (as a TreeEntry, which contains the blob object id) TreeWalk treewalk = TreeWalk.forPath(repo, "b/test.txt", tree); // use the blob id to read the file's data byte[] data = repo.open(treewalk.getObjectId(0)).getBytes();
/** * Create repository id from given owner and name. * * @param owner * @param name * @return repository id */ public static RepositoryId create(String owner, String name) { return new RepositoryId(owner, name); }
public RepositoryInfo(Repository repository) { if (repository != null) { this.id = repository.getId(); this.name = repository.getName(); this.gitURL = repository.getGitUrl(); this.htmlURL = repository.getHtmlUrl(); this.description = repository.getDescription(); this.masterBranch = repository.getMasterBranch(); this.openIssues = repository.getOpenIssues(); this.sshURL = repository.getSshUrl(); this.watchers = repository.getWatchers(); } }
public static TreeEntry createTreeFromString(String prefix, String name, String content, DataService serv, RepositoryId id) throws Exception { TreeEntry entry = new TreeEntry(); entry.setPath(prefix + name); entry.setType(TreeEntry.TYPE_BLOB); entry.setMode(TreeEntry.MODE_BLOB); Blob blob = new Blob().setEncoding(Blob.ENCODING_UTF8); blob.setContent(content); entry.setSha(serv.createBlob(id, blob)); return entry; } }
private boolean matchPullRequest(String base, String head, PullRequest openPR) { boolean matchingHead = head.equals(openPR.getHead().getLabel()); String openmrsBase = base.startsWith(OPENMRS_USER) ? base : OPENMRS_USER+":"+base; boolean matchingBase = openmrsBase.equals(openPR.getBase().getLabel()); return matchingBase && matchingHead; }
private CommitUser createUser() { CommitUser author = new CommitUser(); author.setDate(new Date()); author.setEmail(email); author.setName(name); return author; }
private Commit createCommit() { Commit commit = new Commit(); commit.setMessage(this.commitMessage); CommitUser author = createUser(); commit.setAuthor(author); commit.setCommitter(author); return commit; }
public Collection<IssueEvent> getIssueEvents(final IRepositoryIdProvider repo, final Issue issue) { Collection<IssueEvent> events = null; try { events = service.getIssueEvents(repo, issue); } catch (IOException e) { log.error("Exception fetching events for issue {}:{}", new Object[]{repo.generateId(), issue.getNumber(), e}); } return events; } }
private GitHubUser toUser(User user) { if (user == null) { return null; } else { return new GitHubUser( user.getLogin(), user.getHtmlUrl() ); } }
private Vertex getOrCreateIssue(final Repository repo, final Issue issue) { final String issueId = repo.generateId() + ":" + issue.getNumber(); return getOrCreateVertexHelper(IdCols.ISSUE, issueId, VertexType.ISSUE, issueidx); }
public Repository createCommit(File srcFolder, String applicationName) throws IOException, GitAPIException { Repository repository = repositoryService.createRepository(new Repository().setName(applicationName)); String cloneUrl = repository.getCloneUrl(); InitCommand init = new InitCommand(); init.setDirectory(srcFolder); init.setBare(false); Git git = init.call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", cloneUrl); config.save(); UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(accessToken, ""); git.add().addFilepattern(".").call(); git.commit().setMessage(COMMIT_MESSAGE).call(); git.push().setCredentialsProvider(user).call(); return repository; } }
/** * Create SSH URL used for repository remote configs * * @param repository * @param host * @return URL */ public static String createRemoteSshUrl(IRepositoryIdProvider repository, String host) { return "git@" + host + ":" + repository.generateId() + SUFFIX_GIT; //$NON-NLS-1$ //$NON-NLS-2$ }
@Override public String toString() { return generateId(); } }
/** * @see java.lang.Object#toString() */ public String toString() { return getId(); }
/** * Create read-only URL used for repository remote configs * * @param repository * @param host * @return URL */ public static String createRemoteReadOnlyUrl( IRepositoryIdProvider repository, String host) { return "git://" + host + "/" + repository.generateId() + SUFFIX_GIT; //$NON-NLS-1$ //$NON-NLS-2$ }
/** * Create HTTPS URL used for repository remote configs * * @param repository * @param host * @param user * @return URL */ public static String createRemoteHttpsUrl(IRepositoryIdProvider repository, String host, String user) { return "https://" + user + "@" + host + "/" + repository.generateId() //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + SUFFIX_GIT; }
/** * @see java.lang.Object#hashCode() */ public int hashCode() { return getId().hashCode(); }