@@ -22,28 +22,101 @@ public RepositoryFileApi(GitLabApi gitLabApi) {
2222 super (gitLabApi );
2323 }
2424
25+ /**
26+ * Get information on a file in the repository. Allows you to receive information about file in repository like name, size.
27+ * Only works with GitLab 11.1.0+, returns an empty object for earlier versions of GitLab.
28+ *
29+ * HEAD /projects/:id/repository/files
30+ *
31+ * @param projectIdOrPath the id, path of the project, or a Project instance holding the project ID or path
32+ * @param filePath (required) - Full path to the file. Ex. lib/class.rb
33+ * @param ref (required) - The name of branch, tag or commit
34+ * @return a RepositoryFile instance with the file info
35+ * @throws GitLabApiException if any exception occurs
36+ * @since GitLab-11.1.0
37+ */
38+ public RepositoryFile getFileInfo (Object projectIdOrPath , String filePath , String ref ) throws GitLabApiException {
39+
40+ Form form = new Form ();
41+ addFormParam (form , "ref" , ref , true );
42+ Response response = head (Response .Status .OK , form .asMap (),
43+ "projects" , getProjectIdOrPath (projectIdOrPath ), "repository" , "files" , urlEncode (filePath ));
44+
45+ RepositoryFile file = new RepositoryFile ();
46+ file .setBlobId (response .getHeaderString ("X-Gitlab-Blob-Id" ));
47+ file .setCommitId (response .getHeaderString ("X-Gitlab-Commit-Id" ));
48+ file .setEncoding (response .getHeaderString ("X-Gitlab-Encoding" ));
49+ file .setFileName (response .getHeaderString ("X-Gitlab-File-Name" ));
50+ file .setFilePath (response .getHeaderString ("X-Gitlab-File-Path" ));
51+ file .setLastCommitId (response .getHeaderString ("X-Gitlab-Last-Commit-Id" ));
52+ file .setRef (response .getHeaderString ("X-Gitlab-Ref" ));
53+
54+ String sizeStr = response .getHeaderString ("X-Gitlab-Size" );
55+ file .setSize (sizeStr != null ? Integer .valueOf (sizeStr ) : -1 );
56+
57+ return (file );
58+ }
59+
2560 /**
2661 * Get file from repository. Allows you to receive information about file in repository like name, size, content.
2762 * Note that file content is Base64 encoded.
2863 *
2964 * GET /projects/:id/repository/files
3065 *
31- * @param filePath (required) - Full path to new file. Ex. lib/class.rb
66+ * @param projectIdOrPath the id, path of the project, or a Project instance holding the project ID or path
67+ * @param filePath (required) - Full path to the file. Ex. lib/class.rb
68+ * @param ref (required) - The name of branch, tag or commit
69+ * @return a RepositoryFile instance with the file info and file content
70+ * @throws GitLabApiException if any exception occurs
71+ */
72+ public RepositoryFile getFile (Object projectIdOrPath , String filePath , String ref ) throws GitLabApiException {
73+ return (getFile (projectIdOrPath , filePath , ref , true ));
74+ }
75+
76+ /**
77+ * Get file from repository. Allows you to receive information about file in repository like name, size, content.
78+ * Note that file content is Base64 encoded.
79+ *
80+ * GET /projects/:id/repository/files
81+ *
82+ * @param filePath (required) - Full path to the file. Ex. lib/class.rb
3283 * @param projectId (required) - the project ID
3384 * @param ref (required) - The name of branch, tag or commit
34- * @return a RepositoryFile instance with the file info
85+ * @return a RepositoryFile instance with the file info and file content
3586 * @throws GitLabApiException if any exception occurs
87+ * @deprecated Will be removed in version 5.0, replaced by {@link #getFile(Object, String, String)}
3688 */
3789 public RepositoryFile getFile (String filePath , Integer projectId , String ref ) throws GitLabApiException {
3890
3991 if (isApiVersion (ApiVersion .V3 )) {
4092 return (getFileV3 (filePath , projectId , ref ));
4193 }
4294
95+ return (getFile (projectId , filePath , ref , true ));
96+ }
97+
98+ /**
99+ * Get file from repository. Allows you to receive information about file in repository like name, size, and optionally content.
100+ * Note that file content is Base64 encoded.
101+ *
102+ * GET /projects/:id/repository/files
103+ *
104+ * @param projectIdOrPath the id, path of the project, or a Project instance holding the project ID or path
105+ * @param filePath (required) - Full path to the file. Ex. lib/class.rb
106+ * @param ref (required) - The name of branch, tag or commit
107+ * @param includeContent if true will also fetch file content
108+ * @return a RepositoryFile instance with the file info and optionally file content
109+ * @throws GitLabApiException if any exception occurs
110+ */
111+ public RepositoryFile getFile (Object projectIdOrPath , String filePath , String ref , boolean includeContent ) throws GitLabApiException {
112+
113+ if (!includeContent ) {
114+ return (getFileInfo (projectIdOrPath , filePath , ref ));
115+ }
116+
43117 Form form = new Form ();
44118 addFormParam (form , "ref" , ref , true );
45- Response response = get (Response .Status .OK , form .asMap (),
46- "projects" , projectId , "repository" , "files" , urlEncode (filePath ));
119+ Response response = get (Response .Status .OK , form .asMap (), "projects" , getProjectIdOrPath (projectIdOrPath ), "repository" , "files" , urlEncode (filePath ));
47120 return (response .readEntity (RepositoryFile .class ));
48121 }
49122
@@ -58,6 +131,7 @@ public RepositoryFile getFile(String filePath, Integer projectId, String ref) th
58131 * @param ref (required) - The name of branch, tag or commit
59132 * @return a RepositoryFile instance with the file info
60133 * @throws GitLabApiException if any exception occurs
134+ * @deprecated Will be removed in version 5.0
61135 */
62136 protected RepositoryFile getFileV3 (String filePath , Integer projectId , String ref ) throws GitLabApiException {
63137 Form form = new Form ();
0 commit comments