From 668e68e1e504dec36224a673c7298f9caf16ca2b Mon Sep 17 00:00:00 2001 From: swilson11 Date: Tue, 3 Apr 2018 15:35:27 -0700 Subject: [PATCH 1/2] Add a variation of the getCommits method that supports Paging and a path Simple variation to make it easy to find all commits for a given file. --- .../java/org/gitlab4j/api/CommitsApi.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/org/gitlab4j/api/CommitsApi.java b/src/main/java/org/gitlab4j/api/CommitsApi.java index 649de9737..554e0a21d 100644 --- a/src/main/java/org/gitlab4j/api/CommitsApi.java +++ b/src/main/java/org/gitlab4j/api/CommitsApi.java @@ -180,6 +180,29 @@ public Pager getCommits(int projectId, String ref, Date since, Date unti return (new Pager(this, Commit.class, itemsPerPage, formData.asMap(), "projects", projectId, "repository", "commits")); } + /** + * Get a Pager of repository commits in a project + * + * GET /projects/:id/repository/commits + * + * @param projectId the project ID to get the list of commits for + * @param ref the name of a repository branch or tag or if not given the default branch + * @param since only commits after or on this date will be returned + * @param until only commits before or on this date will be returned + * @param itemsPerPage the number of Commit instances that will be fetched per page + * @param path the path to file of a project + * @return a Pager containing the commits for the specified project ID + * @throws GitLabApiException GitLabApiException if any exception occurs during execution + */ + public Pager getCommits(int projectId, String ref, Date since, Date until, int itemsPerPage, String path) throws GitLabApiException { + Form formData = new GitLabApiForm() + .withParam("ref_name", ref) + .withParam("since", ISO8601.toString(since, false)) + .withParam("until", ISO8601.toString(until, false)) + .withParam("path", (path == null ? null : urlEncode(path))); + return (new Pager(this, Commit.class, itemsPerPage, formData.asMap(), "projects", projectId, "repository", "commits")); + } + /** * Get a specific commit identified by the commit hash or name of a branch or tag. * From 802de3e304b858a2d2fb5843baa30477ce55f721 Mon Sep 17 00:00:00 2001 From: swilson11 Date: Wed, 4 Apr 2018 16:05:48 -0700 Subject: [PATCH 2/2] Updates from pull request comments Add another missing variant Move path parameter before items per page Have a previous variant call the new variant with a null path --- .../java/org/gitlab4j/api/CommitsApi.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/CommitsApi.java b/src/main/java/org/gitlab4j/api/CommitsApi.java index 554e0a21d..041a542d6 100644 --- a/src/main/java/org/gitlab4j/api/CommitsApi.java +++ b/src/main/java/org/gitlab4j/api/CommitsApi.java @@ -149,10 +149,30 @@ public List getCommits(int projectId, String ref, String path) throws Gi * @throws GitLabApiException GitLabApiException if any exception occurs during execution */ public List getCommits(int projectId, String ref, Date since, Date until, int page, int perPage) throws GitLabApiException { + return getCommits(projectId, ref, since, until, null, page, perPage); + } + + /** + * Get a list of repository commits in a project. + * + * GET /projects/:id/repository/commits + * + * @param projectId the project ID to get the list of commits for + * @param ref the name of a repository branch or tag or if not given the default branch + * @param since only commits after or on this date will be returned + * @param until only commits before or on this date will be returned + * @param path the path to file of a project + * @param page the page to get + * @param perPage the number of commits per page + * @return a list containing the commits for the specified project ID + * @throws GitLabApiException GitLabApiException if any exception occurs during execution + */ + public List getCommits(int projectId, String ref, Date since, Date until, String path, int page, int perPage) throws GitLabApiException { Form formData = new GitLabApiForm() .withParam("ref_name", ref) .withParam("since", ISO8601.toString(since, false)) .withParam("until", ISO8601.toString(until, false)) + .withParam("path", (path == null ? null : urlEncode(path))) .withParam(PAGE_PARAM, page) .withParam(PER_PAGE_PARAM, perPage); Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "repository", "commits"); @@ -173,11 +193,7 @@ public List getCommits(int projectId, String ref, Date since, Date until * @throws GitLabApiException GitLabApiException if any exception occurs during execution */ public Pager getCommits(int projectId, String ref, Date since, Date until, int itemsPerPage) throws GitLabApiException { - Form formData = new GitLabApiForm() - .withParam("ref_name", ref) - .withParam("since", ISO8601.toString(since, false)) - .withParam("until", ISO8601.toString(until, false)); - return (new Pager(this, Commit.class, itemsPerPage, formData.asMap(), "projects", projectId, "repository", "commits")); + return getCommits(projectId, ref, since,until, null, itemsPerPage); } /** @@ -194,7 +210,7 @@ public Pager getCommits(int projectId, String ref, Date since, Date unti * @return a Pager containing the commits for the specified project ID * @throws GitLabApiException GitLabApiException if any exception occurs during execution */ - public Pager getCommits(int projectId, String ref, Date since, Date until, int itemsPerPage, String path) throws GitLabApiException { + public Pager getCommits(int projectId, String ref, Date since, Date until, String path, int itemsPerPage) throws GitLabApiException { Form formData = new GitLabApiForm() .withParam("ref_name", ref) .withParam("since", ISO8601.toString(since, false))