Commit ec39b573 authored by orangeStas's avatar orangeStas Committed by Greg Messner
Browse files

Added get commits by path method (#73)

* Added get commits by path method
parent 4f83b9cb
...@@ -87,6 +87,26 @@ public class CommitsApi extends AbstractApi { ...@@ -87,6 +87,26 @@ public class CommitsApi extends AbstractApi {
return (response.readEntity(new GenericType<List<Commit>>() {})); return (response.readEntity(new GenericType<List<Commit>>() {}));
} }
/**
* Get a list of file commits in a project
*
* GET /projects/:id/repository/commits?path=:file_path
*
* @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 path the path to file of a project
* @return a list containing the commits for the specified project ID and file
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public List<Commit> getCommits(int projectId, String ref, String path) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("ref_name", ref)
.withParam(PER_PAGE_PARAM, getDefaultPerPage());
String pathArg = (path == null || path.isEmpty()) ? "commits" : "commits" + "?path=" + path;
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "repository", pathArg);
return (response.readEntity(new GenericType<List<Commit>>() {}));
}
/** /**
* Get a list of repository commits in a project. * Get a list of repository commits in a project.
* *
......
...@@ -147,4 +147,15 @@ public class TestCommitsApi { ...@@ -147,4 +147,15 @@ public class TestCommitsApi {
assertNotNull(pager); assertNotNull(pager);
assertTrue(pager.getTotalItems() > 0); assertTrue(pager.getTotalItems() > 0);
} }
}
@Test
public void testCommitsByPath() throws GitLabApiException {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
CommitsApi commitsApi = gitLabApi.getCommitsApi();
List<Commit> commits = commitsApi.getCommits(project.getId(), "master",
"README");
assertNotNull(commits);
assertTrue(commits.size() > 0);
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment