diff --git a/src/main/java/org/gitlab4j/api/CommitsApi.java b/src/main/java/org/gitlab4j/api/CommitsApi.java index 1c2907fa93b7727a1832ee5ae1a0a0597f171b38..195777a93470b02e93b6450945d5defe3185f741 100644 --- a/src/main/java/org/gitlab4j/api/CommitsApi.java +++ b/src/main/java/org/gitlab4j/api/CommitsApi.java @@ -537,8 +537,46 @@ public class CommitsApi extends AbstractApi { * @throws GitLabApiException GitLabApiException if any exception occurs during execution */ public List getDiff(Object projectIdOrPath, String sha) throws GitLabApiException { - Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "repository", "commits", sha, "diff"); - return (response.readEntity(new GenericType>() {})); + return (getDiff(projectIdOrPath, sha, getDefaultPerPage()).all()); + } + + /** + * Get the Pager of diffs of a commit in a project. + * + *
GitLab Endpoint: GET /projects/:id/repository/commits/:sha/diff
+ * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @param sha a commit hash or name of a branch or tag + * @param itemsPerPage the number of Diff instances that will be fetched per page + * @return a Pager of Diff instances for the specified project ID/sha pair + * @throws GitLabApiException GitLabApiException if any exception occurs during execution + */ + public Pager getDiff(Object projectIdOrPath, String sha, int itemsPerPage) throws GitLabApiException { + + if (projectIdOrPath == null) { + throw new RuntimeException("projectIdOrPath cannot be null"); + } + + if (sha == null || sha.trim().isEmpty()) { + throw new RuntimeException("sha cannot be null"); + } + + return (new Pager(this, Diff.class, itemsPerPage, null, + "projects", getProjectIdOrPath(projectIdOrPath), "repository", "commits", sha, "diff")); + } + + /** + * Get the Diff of diffs of a commit in a project. + * + *
GitLab Endpoint: GET /projects/:id/repository/commits/:sha/diff
+ * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @param sha a commit hash or name of a branch or tag + * @return a Stream of Diff instances for the specified project ID/sha pair + * @throws GitLabApiException GitLabApiException if any exception occurs during execution + */ + public Stream getDiffStream(Object projectIdOrPath, String sha) throws GitLabApiException { + return (getDiff(projectIdOrPath, sha, getDefaultPerPage()).stream()); } /** diff --git a/src/test/java/org/gitlab4j/api/TestCommitsApi.java b/src/test/java/org/gitlab4j/api/TestCommitsApi.java index c41ba9f9fa82a71d8d01836347174887ee9dc499..a0175eb2de8dc516d55ddda81eebbe5bd6b0638f 100644 --- a/src/test/java/org/gitlab4j/api/TestCommitsApi.java +++ b/src/test/java/org/gitlab4j/api/TestCommitsApi.java @@ -13,6 +13,7 @@ import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Optional; +import java.util.stream.Stream; import javax.ws.rs.core.Response; import org.gitlab4j.api.models.Branch; @@ -95,6 +96,18 @@ public class TestCommitsApi extends AbstractIntegrationTest { assertTrue(diffs.size() > 0); } + @Test + public void testDiffStream() throws GitLabApiException { + + assertNotNull(testProject); + + List commits = gitLabApi.getCommitsApi().getCommits(testProject.getId()); + assertTrue(commits.size() > 0); + + Stream diffs = gitLabApi.getCommitsApi().getDiffStream(testProject.getId(), commits.get(0).getId()); + assertTrue(diffs.count() > 0); + } + @Test public void testComments() throws GitLabApiException, ParseException {