/** * Get reference with given name * * @param repository * @param name * @return reference * @throws IOException */ public Reference getReference(IRepositoryIdProvider repository, String name) throws IOException { final String id = getId(repository); if (name == null) throw new IllegalArgumentException("Name cannot be null"); //$NON-NLS-1$ if (name.length() == 0) throw new IllegalArgumentException("Name cannot be empty"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(); uri.append(SEGMENT_REPOS); uri.append('/').append(id); uri.append(SEGMENT_GIT); if (!name.startsWith("refs/")) //$NON-NLS-1$ uri.append(SEGMENT_REFS); uri.append('/').append(name); GitHubRequest request = createRequest(); request.setType(Reference.class); request.setUri(uri); return (Reference) client.get(request).getBody(); }
/** * Get commit for given SHA-1 * * @param repository * @param sha * @return commit * @throws IOException */ public Commit getCommit(IRepositoryIdProvider repository, String sha) throws IOException { final String id = getId(repository); if (sha == null) throw new IllegalArgumentException("SHA-1 cannot be null"); //$NON-NLS-1$ if (sha.length() == 0) throw new IllegalArgumentException("SHA-1 cannot be empty"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(); uri.append(SEGMENT_REPOS); uri.append('/').append(id); uri.append(SEGMENT_GIT); uri.append(SEGMENT_COMMITS); uri.append('/').append(sha); GitHubRequest request = createRequest(); request.setType(Commit.class); request.setUri(uri); return (Commit) client.get(request).getBody(); }
/** * Create tree * * @param repository * @param entries * @param baseTree * @return created tree * @throws IOException */ public Tree createTree(IRepositoryIdProvider repository, Collection<TreeEntry> entries, String baseTree) throws IOException { final String id = getId(repository); StringBuilder uri = new StringBuilder(); uri.append(SEGMENT_REPOS); uri.append('/').append(id); uri.append(SEGMENT_GIT); uri.append(SEGMENT_TREES); GitHubRequest request = createRequest(); request.setType(Tree.class); request.setUri(uri); Map<String, Object> params = new HashMap<String, Object>(); if (entries != null) params.put("tree", entries.toArray()); //$NON-NLS-1$ if (baseTree != null) params.put("base_tree", baseTree); //$NON-NLS-1$ return client.post(uri.toString(), params, Tree.class); }
/** * Get blob for given SHA-1 * * @param repository * @param sha * @return blob * @throws IOException */ public Blob getBlob(IRepositoryIdProvider repository, String sha) throws IOException { final String id = getId(repository); if (sha == null) throw new IllegalArgumentException("SHA-1 cannot be null"); //$NON-NLS-1$ if (sha.length() == 0) throw new IllegalArgumentException("SHA-1 cannot be empty"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(); uri.append(SEGMENT_REPOS); uri.append('/').append(id); uri.append(SEGMENT_GIT); uri.append(SEGMENT_BLOBS); uri.append('/').append(sha); GitHubRequest request = createRequest(); request.setType(Blob.class); request.setUri(uri); return (Blob) client.get(request).getBody(); }
/** * Get tag for given SHA-1 * * @param repository * @param sha * @return tag * @throws IOException */ public Tag getTag(IRepositoryIdProvider repository, String sha) throws IOException { final String id = getId(repository); if (sha == null) throw new IllegalArgumentException("SHA-1 cannot be null"); //$NON-NLS-1$ if (sha.length() == 0) throw new IllegalArgumentException("SHA-1 cannot be empty"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(); uri.append(SEGMENT_REPOS); uri.append('/').append(id); uri.append(SEGMENT_GIT); uri.append(SEGMENT_TAGS); uri.append('/').append(sha); GitHubRequest request = createRequest(); request.setType(Tag.class); request.setUri(uri); return (Tag) client.get(request).getBody(); }
/** * Get tree with given SHA-1 * * @param repository * @param sha * @param recursive * @return tree * @throws IOException */ public Tree getTree(IRepositoryIdProvider repository, String sha, boolean recursive) throws IOException { final String id = getId(repository); if (sha == null) throw new IllegalArgumentException("SHA-1 cannot be null"); //$NON-NLS-1$ if (sha.length() == 0) throw new IllegalArgumentException("SHA-1 cannot be empty"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(); uri.append(SEGMENT_REPOS); uri.append('/').append(id); uri.append(SEGMENT_GIT); uri.append(SEGMENT_TREES); uri.append('/').append(sha); GitHubRequest request = createRequest(); request.setType(Tree.class); request.setUri(uri); if (recursive) request.setParams(Collections.singletonMap("recursive", "1")); //$NON-NLS-1$ //$NON-NLS-2$ return (Tree) client.get(request).getBody(); }