@@ -22,28 +22,101 @@ public RepositoryFileApi(GitLabApi gitLabApi) {
22
22
super (gitLabApi );
23
23
}
24
24
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
+
25
60
/**
26
61
* Get file from repository. Allows you to receive information about file in repository like name, size, content.
27
62
* Note that file content is Base64 encoded.
28
63
*
29
64
* GET /projects/:id/repository/files
30
65
*
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
32
83
* @param projectId (required) - the project ID
33
84
* @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
35
86
* @throws GitLabApiException if any exception occurs
87
+ * @deprecated Will be removed in version 5.0, replaced by {@link #getFile(Object, String, String)}
36
88
*/
37
89
public RepositoryFile getFile (String filePath , Integer projectId , String ref ) throws GitLabApiException {
38
90
39
91
if (isApiVersion (ApiVersion .V3 )) {
40
92
return (getFileV3 (filePath , projectId , ref ));
41
93
}
42
94
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
+
43
117
Form form = new Form ();
44
118
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 ));
47
120
return (response .readEntity (RepositoryFile .class ));
48
121
}
49
122
@@ -58,6 +131,7 @@ public RepositoryFile getFile(String filePath, Integer projectId, String ref) th
58
131
* @param ref (required) - The name of branch, tag or commit
59
132
* @return a RepositoryFile instance with the file info
60
133
* @throws GitLabApiException if any exception occurs
134
+ * @deprecated Will be removed in version 5.0
61
135
*/
62
136
protected RepositoryFile getFileV3 (String filePath , Integer projectId , String ref ) throws GitLabApiException {
63
137
Form form = new Form ();
0 commit comments