예제 #1
0
  /**
   * Gets a pull request's review comments
   *
   * @param repoId
   * @param pullRequestNumber
   * @return list of review comments
   * @throws IOException
   */
  private List<ReviewComment> getReviewComments(String repoId, String pullRequestNumber)
      throws IOException {
    if (pullRequestNumber == null) {
      throw new IllegalArgumentException("Pull request number cannot be null");
    }
    if (pullRequestNumber.length() == 0) {
      throw new IllegalArgumentException("Pull request number cannot be empty");
    }

    logger.info("Getting review comments for PR" + pullRequestNumber + " " + repoId);

    StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
    uri.append('/')
        .append(repoId)
        .append(SEGMENT_PULLS)
        .append('/')
        .append(pullRequestNumber)
        .append(SEGMENT_COMMENTS);

    PagedRequest<ReviewComment> request = createPagedRequest();
    request.setUri(uri);
    request.setType(new TypeToken<List<ReviewComment>>() {}.getType());

    return getAll(request);
  }
예제 #2
0
 /**
  * Get bulk issues request
  *
  * @param user
  * @param repository
  * @param filterData
  * @param start
  * @param size
  * @return paged request
  */
 protected PagedRequest<Issue> createIssuesRequest(
     String user, String repository, Map<String, String> filterData, int start, int size) {
   Assert.notNull("User cannot be null", user); // $NON-NLS-1$
   Assert.notNull("Repository cannot be null", repository); // $NON-NLS-1$
   StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
   uri.append('/').append(user).append('/').append(repository);
   uri.append(IGitHubConstants.SEGMENT_ISSUES);
   PagedRequest<Issue> request = createPagedRequest(start, size);
   request.setParams(filterData).setUri(uri);
   request.setType(new TypeToken<List<Issue>>() {}.getType());
   return request;
 }
예제 #3
0
 /**
  * Get an issue's comments
  *
  * @param user
  * @param repository
  * @param id
  * @return list of matching issues
  * @throws IOException
  */
 public List<Comment> getComments(String user, String repository, String id) throws IOException {
   Assert.notNull("User cannot be null", user); // $NON-NLS-1$
   Assert.notNull("Repository cannot be null", repository); // $NON-NLS-1$
   Assert.notNull("Id cannot be null", id); // $NON-NLS-1$
   StringBuilder builder = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
   builder.append('/').append(user).append('/').append(repository);
   builder.append(IGitHubConstants.SEGMENT_ISSUES);
   builder.append('/').append(id);
   builder.append(IGitHubConstants.SEGMENT_COMMENTS);
   PagedRequest<Comment> request = createPagedRequest();
   request.setUri(builder.toString()).setType(new TypeToken<List<Comment>>() {}.getType());
   return getAll(request);
 }
예제 #4
0
  /**
   * Tests that a PageHeaderIterator correctly retrieves ETag headers for 3 pages from a mocked
   * server that conform to GitHub API's pagination specifications and terminates afterwards.
   *
   * @throws NoSuchElementException
   */
  @Test
  public void testHeaderIterator() throws NoSuchElementException, IOException {
    MockServerClient mockServer = ClientAndServer.startClientAndServer(8888);

    HttpRequest page1Request = createMockServerPagedHeaderRequest(1);
    List<Header> page1Headers =
        TestUtils.parseHeaderRecord(
            TestUtils.readFileFromResource(this, "tests/PagedHeadersSample/page1-header.txt"));
    String page1Etag = "aaf65fc6b10d5afbdc9cd0aa6e6ada4c";

    HttpRequest page2Request = createMockServerPagedHeaderRequest(2);
    List<Header> page2Headers =
        TestUtils.parseHeaderRecord(
            TestUtils.readFileFromResource(this, "tests/PagedHeadersSample/page2-header.txt"));
    String page2Etag = "731501e0f7d9816305782bc4c3f70d9f";

    HttpRequest page3Request = createMockServerPagedHeaderRequest(3);
    List<Header> page3Headers =
        TestUtils.parseHeaderRecord(
            TestUtils.readFileFromResource(this, "tests/PagedHeadersSample/page3-header.txt"));
    String page3Etag = "a6f367d674155d6fbbacbc2fca04917b";

    setUpHeadRequestOnMockServer(mockServer, page1Request, page1Headers);
    setUpHeadRequestOnMockServer(mockServer, page2Request, page2Headers);
    setUpHeadRequestOnMockServer(mockServer, page3Request, page3Headers);

    PagedRequest<Milestone> request = new PagedRequest<>();
    Map<String, String> params = new HashMap<>();
    params.put("state", "all");

    GitHubClientEx client = new GitHubClientEx("localhost", 8888, "http");

    String path = SEGMENT_REPOS + "/hubturbo/hubturbo" + SEGMENT_PULLS;
    request.setUri(path);
    request.setResponseContentType(CONTENT_TYPE_JSON);
    request.setParams(params);

    PageHeaderIterator iter = new PageHeaderIterator(request, client, "ETag");
    assertEquals(page1Etag, Utility.stripQuotes(iter.next()));
    assertEquals(page2Etag, Utility.stripQuotes(iter.next()));
    assertEquals(page3Etag, Utility.stripQuotes(iter.next()));
    assertFalse(iter.hasNext());

    mockServer.stop();
  }
예제 #5
0
  /**
   * Tests that PageHeaderIterator throws a NoSuchElement exception when its next method is called
   * with a initial request to an non-existent repository
   *
   * @throws NoSuchElementException
   */
  @Test(expected = NoSuchElementException.class)
  public void testHeaderIteratorInvalidRepo() throws NoSuchElementException {
    GitHubClientEx client = new GitHubClientEx();

    Map<String, String> params = new HashMap<>();
    params.put("state", "all");

    PagedRequest<Milestone> request = new PagedRequest<>();
    String path = SEGMENT_REPOS + "/nonexistentrepo";
    request.setUri(path);
    request.setResponseContentType(CONTENT_TYPE_JSON);
    request.setParams(params);

    PageHeaderIterator iter = new PageHeaderIterator(request, client, "ETag");
    if (iter.hasNext()) {
      iter.next();
    }
  }