use of org.gitlab4j.api.models.RepositoryFile in project choerodon-starters by open-hand.
the class RepositoryFileApi method getFileV3.
/**
* Get file from repository. Allows you to receive information about file in repository like name, size, content.
* Note that file content is Base64 encoded.
* <p>
* GET /projects/:id/repository/files
*
* @param filePath (required) - Full path to new file. Ex. lib/class.rb
* @param projectId (required) - the project ID
* @param ref (required) - The name of branch, tag or commit
* @return a RepositoryFile instance with the file info
* @throws GitLabApiException if any exception occurs
*/
protected RepositoryFile getFileV3(String filePath, Integer projectId, String ref) throws GitLabApiException {
Form form = new Form();
addFormParam(form, "file_path", filePath, true);
addFormParam(form, "ref", ref, true);
Response response = get(Response.Status.OK, form.asMap(), "projects", projectId, "repository", "files");
return (response.readEntity(RepositoryFile.class));
}
use of org.gitlab4j.api.models.RepositoryFile in project choerodon-starters by open-hand.
the class RepositoryFileApi method createFile.
/**
* Create new file in repository
* <p>
* POST /projects/:id/repository/files
* <p>
* 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
*
* @param file a ReposityoryFile instance with info for the file to create
* @param projectId the project ID
* @param branchName the name of branch
* @param commitMessage the commit message
* @return a RepositoryFile instance with the created file info
* @throws GitLabApiException if any exception occurs
*/
public RepositoryFile createFile(RepositoryFile file, Integer projectId, String branchName, String commitMessage) throws GitLabApiException {
Form formData = file2form(file, branchName, commitMessage);
Response response;
if (isApiVersion(ApiVersion.V3)) {
response = post(Response.Status.CREATED, formData, "projects", projectId, "repository", "files");
} else {
response = post(Response.Status.CREATED, formData, "projects", projectId, "repository", "files", urlEncode(file.getFilePath()));
}
return (response.readEntity(RepositoryFile.class));
}
use of org.gitlab4j.api.models.RepositoryFile in project OpenUnison by TremoloSecurity.
the class CreateGitFile method doTask.
@Override
public boolean doTask(User user, Map<String, Object> request) throws ProvisioningException {
int approvalID = 0;
if (request.containsKey("APPROVAL_ID")) {
approvalID = (Integer) request.get("APPROVAL_ID");
}
Workflow workflow = (Workflow) request.get("WORKFLOW");
GitlabUserProvider gitlab = (GitlabUserProvider) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.targetName).getProvider();
GitLabApi api = gitlab.getApi();
String localNamespace = task.renderTemplate(this.namespace, request);
String localProjectName = task.renderTemplate(this.project, request);
String localPath = task.renderTemplate(this.path, request);
String localBranch = task.renderTemplate(this.branch, request);
String localContent = task.renderTemplate(this.content, request);
String localCommit = task.renderTemplate(this.commitMessage, request);
try {
Project existingProject = api.getProjectApi().getProject(localNamespace, localProjectName);
RepositoryFile rf = new RepositoryFile();
rf.setFilePath(localPath);
rf.setContent(localContent);
RepositoryFile result = api.getRepositoryFileApi().createFile(existingProject, rf, localBranch, localCommit);
GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().logAction(gitlab.getName(), false, ActionType.Add, approvalID, workflow, "gitlab-file-" + existingProject.getNameWithNamespace() + "-file", localPath + " / " + result.getCommitId());
} catch (GitLabApiException e) {
throw new ProvisioningException("Error looking up project " + localNamespace + "/" + localProjectName, e);
}
return true;
}
use of org.gitlab4j.api.models.RepositoryFile in project choerodon-starters by open-hand.
the class RepositoryFileApi method getFile.
/**
* Get file from repository. Allows you to receive information about file in repository like name, size, content.
* Note that file content is Base64 encoded.
* <p>
* GET /projects/:id/repository/files
*
* @param filePath (required) - Full path to new file. Ex. lib/class.rb
* @param projectId (required) - the project ID
* @param ref (required) - The name of branch, tag or commit
* @return a RepositoryFile instance with the file info
* @throws GitLabApiException if any exception occurs
*/
public RepositoryFile getFile(String filePath, Integer projectId, String ref) throws GitLabApiException {
if (isApiVersion(ApiVersion.V3)) {
return (getFileV3(filePath, projectId, ref));
}
Form form = new Form();
addFormParam(form, "ref", ref, true);
Response response = get(Response.Status.OK, form.asMap(), "projects", projectId, "repository", "files", urlEncode(filePath));
return (response.readEntity(RepositoryFile.class));
}
use of org.gitlab4j.api.models.RepositoryFile in project choerodon-starters by open-hand.
the class RepositoryFileApi method updateFile.
/**
* Update existing file in repository
* <p>
* PUT /projects/:id/repository/files
* <p>
* 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
*
* @param file a ReposityoryFile instance with info for the file to update
* @param projectId the project ID
* @param branchName the name of branch
* @param commitMessage the commit message
* @return a RepositoryFile instance with the updated file info
* @throws GitLabApiException if any exception occurs
*/
public RepositoryFile updateFile(RepositoryFile file, Integer projectId, String branchName, String commitMessage) throws GitLabApiException {
Form formData = file2form(file, branchName, commitMessage);
Response response;
if (isApiVersion(ApiVersion.V3)) {
response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "repository", "files");
} else {
response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "repository", "files", urlEncode(file.getFilePath()));
}
return (response.readEntity(RepositoryFile.class));
}
Aggregations