@@ -78,7 +78,7 @@ protected RepositoryFile getFileV3(String filePath, Integer projectId, String re
7878 * content (required) - File content
7979 * commit_message (required) - Commit message
8080 *
81- * @param file full path to new file. Ex. lib/class.rb
81+ * @param file a ReposityoryFile instance with info for the file to create
8282 * @param projectId the project ID
8383 * @param branchName the name of branch
8484 * @param commitMessage the commit message
@@ -87,7 +87,9 @@ protected RepositoryFile getFileV3(String filePath, Integer projectId, String re
8787 */
8888 public RepositoryFile createFile (RepositoryFile file , Integer projectId , String branchName , String commitMessage ) throws GitLabApiException {
8989 Form formData = file2form (file , branchName , commitMessage );
90- Response response = post (Response .Status .CREATED , formData , "projects" , projectId , "repository" , "files" , urlEncode (file .getFilePath ()));
90+ Response response = isApiVersion (ApiVersion .V3 ) ?
91+ post (Response .Status .CREATED , formData , "projects" , projectId , "repository" , "files" ) :
92+ post (Response .Status .CREATED , formData , "projects" , projectId , "repository" , "files" , urlEncode (file .getFilePath ()));
9193 return (response .readEntity (RepositoryFile .class ));
9294 }
9395
@@ -102,16 +104,18 @@ public RepositoryFile createFile(RepositoryFile file, Integer projectId, String
102104 * content (required) - File content
103105 * commit_message (required) - Commit message
104106 *
105- * @param file full path to new file. Ex. lib/class.rb
107+ * @param file a ReposityoryFile instance with info for the file to update
106108 * @param projectId the project ID
107109 * @param branchName the name of branch
108110 * @param commitMessage the commit message
109111 * @return a RepositoryFile instance with the updated file info
110112 * @throws GitLabApiException if any exception occurs
111113 */
112114 public RepositoryFile updateFile (RepositoryFile file , Integer projectId , String branchName , String commitMessage ) throws GitLabApiException {
113- Form form = file2form (file , branchName , commitMessage );
114- Response response = put (Response .Status .OK , form .asMap (), "projects" , projectId , "repository" , "files" , urlEncode (file .getFilePath ()));
115+ Form formData = file2form (file , branchName , commitMessage );
116+ Response response = isApiVersion (ApiVersion .V3 ) ?
117+ put (Response .Status .CREATED , formData .asMap (), "projects" , projectId , "repository" , "files" ) :
118+ put (Response .Status .CREATED , formData .asMap (), "projects" , projectId , "repository" , "files" , urlEncode (file .getFilePath ()));
115119 return (response .readEntity (RepositoryFile .class ));
116120 }
117121
@@ -140,7 +144,13 @@ public void deleteFile(String filePath, Integer projectId, String branchName, St
140144 addFormParam (form , isApiVersion (ApiVersion .V3 ) ? "branch_name" : "branch" , branchName , true );
141145 addFormParam (form , "commit_message" , commitMessage , true );
142146 Response .Status expectedStatus = (isApiVersion (ApiVersion .V3 ) ? Response .Status .OK : Response .Status .NO_CONTENT );
143- delete (expectedStatus , form .asMap (), "projects" , projectId , "repository" , "files" , urlEncode (filePath ));
147+
148+ if (isApiVersion (ApiVersion .V3 )) {
149+ addFormParam (form , "file_path" , filePath , true );
150+ delete (expectedStatus , form .asMap (), "projects" , projectId , "repository" , "files" );
151+ } else {
152+ delete (expectedStatus , form .asMap (), "projects" , projectId , "repository" , "files" , urlEncode (filePath ));
153+ }
144154 }
145155
146156 /**
@@ -198,8 +208,15 @@ public InputStream getRawFile(Integer projectId, String commitOrBranchName, Stri
198208 }
199209
200210 private Form file2form (RepositoryFile file , String branchName , String commitMessage ) {
211+
201212 Form form = new Form ();
202- addFormParam (form , isApiVersion (ApiVersion .V3 ) ? "branch_name" : "branch" , branchName , true );
213+ if (isApiVersion (ApiVersion .V3 )) {
214+ addFormParam (form , "file_path" , file .getFilePath (), true );
215+ addFormParam (form , "branch_name" , branchName , true );
216+ } else {
217+ addFormParam (form , "branch" , branchName , true );
218+ }
219+
203220 addFormParam (form , "encoding" , file .getEncoding (), false );
204221 addFormParam (form , "content" , file .getContent (), true );
205222 addFormParam (form , "commit_message" , commitMessage , true );
0 commit comments