Skip to content

Commit 94b37c5

Browse files
swilson11gmessner
authored andcommitted
Add a variation of the getCommits method that supports Paging and a path (#167)
* Add a variation of the getCommits() method that supports Paging and a path. A simple variation to make it easy to find all commits for a given file.
1 parent c22fe5b commit 94b37c5

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/main/java/org/gitlab4j/api/CommitsApi.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,30 @@ public List<Commit> getCommits(int projectId, String ref, String path) throws Gi
149149
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
150150
*/
151151
public List<Commit> getCommits(int projectId, String ref, Date since, Date until, int page, int perPage) throws GitLabApiException {
152+
return getCommits(projectId, ref, since, until, null, page, perPage);
153+
}
154+
155+
/**
156+
* Get a list of repository commits in a project.
157+
*
158+
* GET /projects/:id/repository/commits
159+
*
160+
* @param projectId the project ID to get the list of commits for
161+
* @param ref the name of a repository branch or tag or if not given the default branch
162+
* @param since only commits after or on this date will be returned
163+
* @param until only commits before or on this date will be returned
164+
* @param path the path to file of a project
165+
* @param page the page to get
166+
* @param perPage the number of commits per page
167+
* @return a list containing the commits for the specified project ID
168+
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
169+
*/
170+
public List<Commit> getCommits(int projectId, String ref, Date since, Date until, String path, int page, int perPage) throws GitLabApiException {
152171
Form formData = new GitLabApiForm()
153172
.withParam("ref_name", ref)
154173
.withParam("since", ISO8601.toString(since, false))
155174
.withParam("until", ISO8601.toString(until, false))
175+
.withParam("path", (path == null ? null : urlEncode(path)))
156176
.withParam(PAGE_PARAM, page)
157177
.withParam(PER_PAGE_PARAM, perPage);
158178
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "repository", "commits");
@@ -173,10 +193,29 @@ public List<Commit> getCommits(int projectId, String ref, Date since, Date until
173193
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
174194
*/
175195
public Pager<Commit> getCommits(int projectId, String ref, Date since, Date until, int itemsPerPage) throws GitLabApiException {
196+
return getCommits(projectId, ref, since,until, null, itemsPerPage);
197+
}
198+
199+
/**
200+
* Get a Pager of repository commits in a project
201+
*
202+
* GET /projects/:id/repository/commits
203+
*
204+
* @param projectId the project ID to get the list of commits for
205+
* @param ref the name of a repository branch or tag or if not given the default branch
206+
* @param since only commits after or on this date will be returned
207+
* @param until only commits before or on this date will be returned
208+
* @param itemsPerPage the number of Commit instances that will be fetched per page
209+
* @param path the path to file of a project
210+
* @return a Pager containing the commits for the specified project ID
211+
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
212+
*/
213+
public Pager<Commit> getCommits(int projectId, String ref, Date since, Date until, String path, int itemsPerPage) throws GitLabApiException {
176214
Form formData = new GitLabApiForm()
177215
.withParam("ref_name", ref)
178216
.withParam("since", ISO8601.toString(since, false))
179-
.withParam("until", ISO8601.toString(until, false));
217+
.withParam("until", ISO8601.toString(until, false))
218+
.withParam("path", (path == null ? null : urlEncode(path)));
180219
return (new Pager<Commit>(this, Commit.class, itemsPerPage, formData.asMap(), "projects", projectId, "repository", "commits"));
181220
}
182221

0 commit comments

Comments
 (0)