Java Code Examples for org.gitlab4j.api.models.RepositoryFile#setFilePath()
The following examples show how to use
org.gitlab4j.api.models.RepositoryFile#setFilePath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RepositoryFileApi.java From gitlab4j-api with MIT License | 6 votes |
/** * Get information on a file in the repository. Allows you to receive information about file in repository like name, size. * Only works with GitLab 11.1.0+, returns an empty object for earlier versions of GitLab. * * <pre><code>GitLab Endpoint: HEAD /projects/:id/repository/files</code></pre> * * @param projectIdOrPath the id, path of the project, or a Project instance holding the project ID or path * @param filePath (required) - Full path to the file. Ex. lib/class.rb * @param ref (required) - The name of branch, tag or commit * @return a RepositoryFile instance with the file info * @throws GitLabApiException if any exception occurs * @since GitLab-11.1.0 */ public RepositoryFile getFileInfo(Object projectIdOrPath, String filePath, String ref) throws GitLabApiException { Form form = new Form(); addFormParam(form, "ref", (ref != null ? urlEncode(ref) : null), true); Response response = head(Response.Status.OK, form.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "repository", "files", urlEncode(filePath)); RepositoryFile file = new RepositoryFile(); file.setBlobId(response.getHeaderString("X-Gitlab-Blob-Id")); file.setCommitId(response.getHeaderString("X-Gitlab-Commit-Id")); String encoding = response.getHeaderString("X-Gitlab-Encoding"); file.setEncoding(Constants.Encoding.forValue(encoding)); file.setFileName(response.getHeaderString("X-Gitlab-File-Name")); file.setFilePath(response.getHeaderString("X-Gitlab-File-Path")); file.setLastCommitId(response.getHeaderString("X-Gitlab-Last-Commit-Id")); file.setRef(response.getHeaderString("X-Gitlab-Ref")); String sizeStr = response.getHeaderString("X-Gitlab-Size"); file.setSize(sizeStr != null ? Integer.valueOf(sizeStr) : -1); return (file); }
Example 2
Source File: TestRepositoryFileApi.java From gitlab4j-api with MIT License | 6 votes |
@Test public void testCreateFileAndDeleteFile() throws GitLabApiException { Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); assertNotNull(project); Branch branch = gitLabApi.getRepositoryApi().createBranch(project.getId(), TEST_BRANCH_NAME, "master"); assertNotNull(branch); RepositoryFile file = new RepositoryFile(); file.setFilePath(TEST_FILEPATH); file.setContent(TEST_CONTENT); RepositoryFile createdFile = gitLabApi.getRepositoryFileApi().createFile(project.getId(), file, TEST_BRANCH_NAME, "Testing createFile()."); assertNotNull(createdFile); gitLabApi.getRepositoryFileApi().deleteFile(project.getId(), TEST_FILEPATH, TEST_BRANCH_NAME, "Testing deleteFile()."); gitLabApi.getRepositoryApi().deleteBranch(project.getId(), TEST_BRANCH_NAME); }
Example 3
Source File: TestRepositoryFileApi.java From gitlab4j-api with MIT License | 6 votes |
@Test public void testCreateFileWithEmptyContent() throws GitLabApiException { Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); assertNotNull(project); Branch branch = gitLabApi.getRepositoryApi().createBranch(project.getId(), TEST_BRANCH_NAME, "master"); assertNotNull(branch); RepositoryFile file = new RepositoryFile(); file.setFilePath(TEST_FILEPATH); file.setContent(""); RepositoryFile createdFile = gitLabApi.getRepositoryFileApi().createFile(project.getId(), file, TEST_BRANCH_NAME, "Testing createFile()."); assertNotNull(createdFile); gitLabApi.getRepositoryFileApi().deleteFile(project.getId(), TEST_FILEPATH, TEST_BRANCH_NAME, "Testing deleteFile()."); gitLabApi.getRepositoryApi().deleteBranch(project.getId(), TEST_BRANCH_NAME); }
Example 4
Source File: TestPipelineApi.java From gitlab4j-api with MIT License | 6 votes |
@BeforeClass public static void setup() { // Must setup the connection to the GitLab test server and get the test Project instance gitLabApi = baseTestSetup(); testProject = getTestProject(); Optional<RepositoryFile> fileInfo = gitLabApi.getRepositoryFileApi().getOptionalFileInfo(testProject, ".gitlab-ci.yml", "master"); if (fileInfo.isPresent()) { gitlabCiYml = fileInfo.get(); } else { try { RepositoryFile file = new RepositoryFile(); file.setFilePath(".gitlab-ci.yml"); file.setContent(TEST_GITLAB_CI_YML_CONTENT); createdGitlabCiYml = gitLabApi.getRepositoryFileApi().createFile( testProject, file, "master", "Need for testing pipelines."); gitlabCiYml = createdGitlabCiYml; System.out.println("Created .gitlab-ci.yml file for testing purposes."); } catch (Exception ignore) {} } }
Example 5
Source File: TestCommitsApi.java From gitlab4j-api with MIT License | 5 votes |
@BeforeClass public static void setup() { // Must setup the connection to the GitLab test server and get the test Project instance gitLabApi = baseTestSetup(); testProject = getTestProject(); if (!gitLabApi.getRepositoryFileApi().getOptionalFile(testProject, TEST_PROJECT_SUBDIRECTORY_PATH, "master").isPresent()) { try { RepositoryFile repoFile = new RepositoryFile(); repoFile.setFilePath(TEST_PROJECT_SUBDIRECTORY_PATH); repoFile.setContent("This is a test project used to test GitLab4J-API."); gitLabApi.getRepositoryFileApi().createFile(testProject, repoFile, "master", "Initial commit."); } catch (GitLabApiException ignore) {} } }