Skip to content

Commit b5cf400

Browse files
authored
feat: Add changedFiles for PR Client (#238)
1 parent ae3cb19 commit b5cf400

File tree

3 files changed

+148
-73
lines changed

3 files changed

+148
-73
lines changed

src/main/java/com/spotify/github/v3/clients/GitHubClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.spotify.github.v3.comment.CommentReaction;
4141
import com.spotify.github.v3.exceptions.ReadOnlyRepositoryException;
4242
import com.spotify.github.v3.exceptions.RequestNotOkException;
43+
import com.spotify.github.v3.git.FileItem;
4344
import com.spotify.github.v3.git.Reference;
4445
import com.spotify.github.v3.orgs.TeamInvitation;
4546
import com.spotify.github.v3.prs.PullRequestItem;
@@ -108,6 +109,9 @@ public class GitHubClient {
108109
static final TypeReference<List<TeamInvitation>> LIST_PENDING_TEAM_INVITATIONS =
109110
new TypeReference<>() {};
110111

112+
static final TypeReference<List<FileItem>> LIST_FILE_ITEMS =
113+
new TypeReference<>() {};
114+
111115
private static final String GET_ACCESS_TOKEN_URL = "app/installations/%s/access_tokens";
112116

113117
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

src/main/java/com/spotify/github/v3/clients/PullRequestClient.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,18 @@
2020

2121
package com.spotify.github.v3.clients;
2222

23-
import java.io.InputStreamReader;
24-
import java.io.Reader;
25-
import java.lang.invoke.MethodHandles;
26-
import java.util.Iterator;
27-
import java.util.List;
28-
import java.util.Map;
29-
import static java.util.Objects.isNull;
30-
import java.util.concurrent.CompletableFuture;
31-
32-
import javax.ws.rs.core.HttpHeaders;
33-
34-
import org.slf4j.Logger;
35-
import org.slf4j.LoggerFactory;
36-
37-
import com.google.common.base.Strings;
38-
import com.google.common.collect.ImmutableMap;
39-
import com.spotify.github.async.AsyncPage;
4023
import static com.spotify.github.v3.clients.GitHubClient.IGNORE_RESPONSE_CONSUMER;
4124
import static com.spotify.github.v3.clients.GitHubClient.LIST_COMMIT_TYPE_REFERENCE;
25+
import static com.spotify.github.v3.clients.GitHubClient.LIST_FILE_ITEMS;
4226
import static com.spotify.github.v3.clients.GitHubClient.LIST_PR_TYPE_REFERENCE;
4327
import static com.spotify.github.v3.clients.GitHubClient.LIST_REVIEW_REQUEST_TYPE_REFERENCE;
4428
import static com.spotify.github.v3.clients.GitHubClient.LIST_REVIEW_TYPE_REFERENCE;
29+
import static java.util.Objects.isNull;
30+
31+
import com.google.common.base.Strings;
32+
import com.google.common.collect.ImmutableMap;
33+
import com.spotify.github.async.AsyncPage;
34+
import com.spotify.github.v3.git.FileItem;
4535
import com.spotify.github.v3.prs.Comment;
4636
import com.spotify.github.v3.prs.MergeParameters;
4737
import com.spotify.github.v3.prs.PullRequest;
@@ -54,6 +44,16 @@
5444
import com.spotify.github.v3.prs.requests.PullRequestParameters;
5545
import com.spotify.github.v3.prs.requests.PullRequestUpdate;
5646
import com.spotify.github.v3.repos.CommitItem;
47+
import java.io.InputStreamReader;
48+
import java.io.Reader;
49+
import java.lang.invoke.MethodHandles;
50+
import java.util.Iterator;
51+
import java.util.List;
52+
import java.util.Map;
53+
import java.util.concurrent.CompletableFuture;
54+
import javax.ws.rs.core.HttpHeaders;
55+
import org.slf4j.Logger;
56+
import org.slf4j.LoggerFactory;
5757

5858
/** Pull call API client */
5959
public class PullRequestClient {
@@ -63,6 +63,7 @@ public class PullRequestClient {
6363
private static final String PR_NUMBER_TEMPLATE = "/repos/%s/%s/pulls/%s";
6464
private static final String PR_COMMITS_TEMPLATE = "/repos/%s/%s/pulls/%s/commits";
6565
private static final String PR_REVIEWS_TEMPLATE = "/repos/%s/%s/pulls/%s/reviews";
66+
private static final String PR_CHANGED_FILES_TEMPLATE = "/repos/%s/%s/pulls/%s/files";
6667
private static final String PR_REVIEW_REQUESTS_TEMPLATE =
6768
"/repos/%s/%s/pulls/%s/requested_reviewers";
6869
private static final String PR_COMMENT_REPLIES_TEMPLATE =
@@ -449,6 +450,11 @@ public CompletableFuture<Reader> diff(final long prNumber) {
449450
});
450451
}
451452

453+
public Iterator<AsyncPage<FileItem>> changedFiles(final long prNumber) {
454+
final String path = String.format(PR_CHANGED_FILES_TEMPLATE, owner, repo, prNumber);
455+
return new GithubPageIterator<>(new GithubPage<>(github, path, LIST_FILE_ITEMS));
456+
}
457+
452458
/**
453459
* List pull requests using given parameters.
454460
*

0 commit comments

Comments
 (0)