Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.messners.gitlab.api;
  
  
This class provides an entry point to all the GitLab API repository files calls.

Author(s):
lonfee88 <lonfee88@gmail.com>
 
 public class RepositoryFileApi extends AbstractApi {
 
 	public RepositoryFileApi (GitLabApi gitLabApi) {
 		super(gitLabApi);
 	}

    
Get file from repository Allows you to receive information about file in repository like name, size, content. Note that file content is Base64 encoded. GET /projects/:id/repository/files

Parameters:
file_path (required) - Full path to new file. Ex. lib/class.rb
projectId
ref (required) - The name of branch, tag or commit
Returns:
Throws:
GitLabApiException
 
 	public RepositoryFile getFile(String filePathInteger projectIdString refthrows GitLabApiException {   
         Form form = new Form();
         addFormParam(form"file_path"filePathtrue);
         addFormParam(form"ref"reftrue);
         Response response = get(..form.asMap(),"projects"projectId"repository""files");
         return (response.readEntity(RepositoryFile.class));
     }

Create new file in repository POST /projects/:id/repository/files file_path (required) - Full path to new file. Ex. lib/class.rb branch_name (required) - The name of branch encoding (optional) - 'text' or 'base64'. Text is default. content (required) - File content commit_message (required) - Commit message

Parameters:
file
projectId
branchName
commitMessage
Returns:
Throws:
GitLabApiException
 
 	public RepositoryFile createFile (RepositoryFile fileInteger projectIdString branchName,  String commitMessagethrows GitLabApiException {
 	    Form formData = file2form(filebranchNamecommitMessage);
         Response response = post(..formData"projects"projectId"repository""files");
         return (response.readEntity(RepositoryFile.class));
     }

Update existing file in repository PUT /projects/:id/repository/files file_path (required) - Full path to new file. Ex. lib/class.rb branch_name (required) - The name of branch encoding (optional) - 'text' or 'base64'. Text is default. content (required) - File content commit_message (required) - Commit message

Parameters:
file
projectId
branchName
commitMessage
Returns:
Throws:
GitLabApiException
 
 	public RepositoryFile updateFile (RepositoryFile fileInteger projectIdString branchName,  String commitMessagethrows GitLabApiException {
 	    Form form = file2form(filebranchNamecommitMessage);     
         Response response = put(..form.asMap(), "projects"projectId"repository""files");
         return (response.readEntity(RepositoryFile.class));
     }

Delete existing file in repository DELETE /projects/:id/repository/files file_path (required) - Full path to file. Ex. lib/class.rb branch_name (required) - The name of branch commit_message (required) - Commit message

Parameters:
filePath
projectId
branchName
commitMessage
Throws:
GitLabApiException
	public void deleteFile (String filePathInteger projectIdString branchName,  String commitMessagethrows GitLabApiException {
        if (filePath == null) {
            throw new RuntimeException("filePath cannot be null");
        }
        Form form = new Form();
        addFormParam(form"file_path"filePathtrue);
        addFormParam(form"branch_name"branchNametrue);
        addFormParam(form"commit_message"commitMessagetrue);
        delete(..form.asMap(), "projects"projectId"repository""files");
    }
	private Form file2form(RepositoryFile fileString branchNameString commitMessage){
	    Form form = new Form();
	    addFormParam(form"file_path"file.getFilePath(), true);
	    addFormParam(form"branch_name"branchNametrue);
	    addFormParam(form"encoding"file.getEncoding(), false);
	    addFormParam(form"content"file.getContent(), true);
	    addFormParam(form"commit_message"commitMessagetrue);
	    return form;
	}
New to GrepCode? Check out our FAQ X