From 62309b4a13ca954fbf04cb37e24244d17e4986f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AD=E5=B9=BB?= Date: Wed, 20 May 2015 15:10:31 +0800 Subject: [PATCH] add a getTree method with 2 more additional parameters --- .../messners/gitlab/api/RepositoryApi.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/messners/gitlab/api/RepositoryApi.java b/src/main/java/com/messners/gitlab/api/RepositoryApi.java index ec130bfe..4d8d8e45 100644 --- a/src/main/java/com/messners/gitlab/api/RepositoryApi.java +++ b/src/main/java/com/messners/gitlab/api/RepositoryApi.java @@ -128,14 +128,33 @@ public class RepositoryApi extends AbstractApi { * GET /projects/:id/repository/tree * * @param projectId - * @return a tree with the directories and files of a project + * @return a tree with the root directories and files of a project * @throws GitLabApiException */ public List getTree (Integer projectId) throws GitLabApiException { - Response response = get(Response.Status.OK, null, "projects", projectId, "repository", "tree"); - return (response.readEntity(new GenericType>() {})); + return this.getTree(projectId, "/", "master"); } + /** + * Get a list of repository files and directories in a project. + * + * GET /projects/:id/repository/tree + * + * id (required) - The ID of a project + * path (optional) - The path inside repository. Used to get contend of subdirectories + * ref_name (optional) - The name of a repository branch or tag or if not given the default branch + * @return a tree with the directories and files of a project + * @throws GitLabApiException + */ + public List getTree (Integer projectId, String filePath, String refName) throws GitLabApiException { + Form formData = new Form(); + addFormParam(formData, "id", projectId, true); + addFormParam(formData, "path", filePath, false); + addFormParam(formData, "ref_name", refName, false); + Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "repository", "tree"); + return (response.readEntity(new GenericType>() {})); + } + /** * Get the raw file contents for a file by commit sha and path. -- GitLab