コード例 #1
0
  /**
   * Get repository README
   *
   * @param repository
   * @param ref
   * @return README
   * @throws IOException
   */
  public RepositoryContents getReadme(IRepositoryIdProvider repository, String ref)
      throws IOException {
    String id = getId(repository);

    StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
    uri.append('/').append(id);
    uri.append(SEGMENT_README);
    GitHubRequest request = createRequest();
    request.setUri(uri);
    if (ref != null && ref.length() > 0) request.setParams(Collections.singletonMap("ref", ref));
    request.setType(RepositoryContents.class);
    return (RepositoryContents) client.get(request).getBody();
  }
コード例 #2
0
  /**
   * Get contents of path at reference in given repository
   *
   * <p>For file paths this will return a list with one entry corresponding to the file contents at
   * the given path
   *
   * @param repository
   * @param path
   * @param ref
   * @return list of contents at path
   * @throws IOException
   */
  @SuppressWarnings("unchecked")
  public List<RepositoryContents> getContents(
      IRepositoryIdProvider repository, String path, String ref) throws IOException {
    String id = getId(repository);

    StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
    uri.append('/').append(id);
    uri.append(SEGMENT_CONTENTS);
    if (path != null && path.length() > 0) {
      if (path.charAt(0) != '/') uri.append('/');
      uri.append(path);
    }
    GitHubRequest request = createRequest();
    request.setUri(uri);
    request.setType(RepositoryContents.class);
    request.setArrayType(new TypeToken<List<RepositoryContents>>() {}.getType());
    if (ref != null && ref.length() > 0) request.setParams(Collections.singletonMap("ref", ref));

    Object body = client.get(request).getBody();
    if (body instanceof RepositoryContents)
      return Collections.singletonList((RepositoryContents) body);
    else return (List<RepositoryContents>) body;
  }