Skip to content

Add a variation of the getCommits method that supports Paging and a path #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/main/java/org/gitlab4j/api/CommitsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,30 @@ public List<Commit> getCommits(int projectId, String ref, String path) throws Gi
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public List<Commit> 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<Commit> 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");
Expand All @@ -173,10 +193,29 @@ public List<Commit> getCommits(int projectId, String ref, Date since, Date until
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public Pager<Commit> getCommits(int projectId, String ref, Date since, Date until, int itemsPerPage) throws GitLabApiException {
return getCommits(projectId, ref, since,until, null, itemsPerPage);
}

/**
* 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<Commit> 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))
.withParam("until", ISO8601.toString(until, false));
.withParam("until", ISO8601.toString(until, false))
.withParam("path", (path == null ? null : urlEncode(path)));
return (new Pager<Commit>(this, Commit.class, itemsPerPage, formData.asMap(), "projects", projectId, "repository", "commits"));
}

Expand Down