Unverified Commit c3a99e9f authored by Jérémie Bresson's avatar Jérémie Bresson Committed by GitHub
Browse files

Change the response type of "createFile" and "updateFile" (#953)

Fixes #893
parent df054eee
...@@ -16,6 +16,7 @@ import jakarta.ws.rs.core.Response; ...@@ -16,6 +16,7 @@ import jakarta.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Blame; import org.gitlab4j.api.models.Blame;
import org.gitlab4j.api.models.RepositoryFile; import org.gitlab4j.api.models.RepositoryFile;
import org.gitlab4j.api.models.RepositoryFileResponse;
/** /**
* This class provides an entry point to all the GitLab API repository files calls. * This class provides an entry point to all the GitLab API repository files calls.
...@@ -211,7 +212,7 @@ public class RepositoryFileApi extends AbstractApi { ...@@ -211,7 +212,7 @@ public class RepositoryFileApi extends AbstractApi {
* @return a RepositoryFile instance with the created file info * @return a RepositoryFile instance with the created file info
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public RepositoryFile createFile(Object projectIdOrPath, RepositoryFile file, String branchName, String commitMessage) throws GitLabApiException { public RepositoryFileResponse createFile(Object projectIdOrPath, RepositoryFile file, String branchName, String commitMessage) throws GitLabApiException {
Form formData = createForm(file, branchName, commitMessage); Form formData = createForm(file, branchName, commitMessage);
Response response; Response response;
...@@ -223,7 +224,7 @@ public class RepositoryFileApi extends AbstractApi { ...@@ -223,7 +224,7 @@ public class RepositoryFileApi extends AbstractApi {
"projects", getProjectIdOrPath(projectIdOrPath), "repository", "files", urlEncode(file.getFilePath())); "projects", getProjectIdOrPath(projectIdOrPath), "repository", "files", urlEncode(file.getFilePath()));
} }
return (response.readEntity(RepositoryFile.class)); return (response.readEntity(RepositoryFileResponse.class));
} }
/** /**
...@@ -246,7 +247,7 @@ public class RepositoryFileApi extends AbstractApi { ...@@ -246,7 +247,7 @@ public class RepositoryFileApi extends AbstractApi {
* @deprecated Will be removed in version 6.0, replaced by {@link #createFile(Object, RepositoryFile, String, String)} * @deprecated Will be removed in version 6.0, replaced by {@link #createFile(Object, RepositoryFile, String, String)}
*/ */
@Deprecated @Deprecated
public RepositoryFile createFile(RepositoryFile file, Long projectId, String branchName, String commitMessage) throws GitLabApiException { public RepositoryFileResponse createFile(RepositoryFile file, Long projectId, String branchName, String commitMessage) throws GitLabApiException {
return (createFile(projectId, file, branchName, commitMessage)); return (createFile(projectId, file, branchName, commitMessage));
} }
...@@ -268,7 +269,7 @@ public class RepositoryFileApi extends AbstractApi { ...@@ -268,7 +269,7 @@ public class RepositoryFileApi extends AbstractApi {
* @return a RepositoryFile instance with the updated file info * @return a RepositoryFile instance with the updated file info
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public RepositoryFile updateFile(Object projectIdOrPath, RepositoryFile file, String branchName, String commitMessage) throws GitLabApiException { public RepositoryFileResponse updateFile(Object projectIdOrPath, RepositoryFile file, String branchName, String commitMessage) throws GitLabApiException {
Form formData = createForm(file, branchName, commitMessage); Form formData = createForm(file, branchName, commitMessage);
Response response; Response response;
...@@ -280,7 +281,7 @@ public class RepositoryFileApi extends AbstractApi { ...@@ -280,7 +281,7 @@ public class RepositoryFileApi extends AbstractApi {
"projects", getProjectIdOrPath(projectIdOrPath), "repository", "files", urlEncode(file.getFilePath())); "projects", getProjectIdOrPath(projectIdOrPath), "repository", "files", urlEncode(file.getFilePath()));
} }
return (response.readEntity(RepositoryFile.class)); return (response.readEntity(RepositoryFileResponse.class));
} }
/** /**
...@@ -303,7 +304,7 @@ public class RepositoryFileApi extends AbstractApi { ...@@ -303,7 +304,7 @@ public class RepositoryFileApi extends AbstractApi {
* @deprecated Will be removed in version 6.0, replaced by {@link #updateFile(Object, RepositoryFile, String, String)} * @deprecated Will be removed in version 6.0, replaced by {@link #updateFile(Object, RepositoryFile, String, String)}
*/ */
@Deprecated @Deprecated
public RepositoryFile updateFile(RepositoryFile file, Long projectId, String branchName, String commitMessage) throws GitLabApiException { public RepositoryFileResponse updateFile(RepositoryFile file, Long projectId, String branchName, String commitMessage) throws GitLabApiException {
return (updateFile(projectId, file, branchName, commitMessage)); return (updateFile(projectId, file, branchName, commitMessage));
} }
......
package org.gitlab4j.api.models;
import java.util.Base64;
import org.gitlab4j.api.Constants.Encoding;
import org.gitlab4j.api.utils.JacksonJson;
import com.fasterxml.jackson.annotation.JsonIgnore;
public class RepositoryFileResponse {
private String filePath; // full path to file. Ex. lib/class.rb
private String branch;
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public String getBranch() {
return branch;
}
public void setBranch(String branch) {
this.branch = branch;
}
@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
...@@ -105,6 +105,7 @@ import org.gitlab4j.api.models.RegistryRepository; ...@@ -105,6 +105,7 @@ import org.gitlab4j.api.models.RegistryRepository;
import org.gitlab4j.api.models.Release; import org.gitlab4j.api.models.Release;
import org.gitlab4j.api.models.RemoteMirror; import org.gitlab4j.api.models.RemoteMirror;
import org.gitlab4j.api.models.RepositoryFile; import org.gitlab4j.api.models.RepositoryFile;
import org.gitlab4j.api.models.RepositoryFileResponse;
import org.gitlab4j.api.models.Runner; import org.gitlab4j.api.models.Runner;
import org.gitlab4j.api.models.RunnerDetail; import org.gitlab4j.api.models.RunnerDetail;
import org.gitlab4j.api.models.SearchBlob; import org.gitlab4j.api.models.SearchBlob;
...@@ -555,6 +556,12 @@ public class TestGitLabApiBeans { ...@@ -555,6 +556,12 @@ public class TestGitLabApiBeans {
RepositoryFile file = unmarshalResource(RepositoryFile.class, "repository-file.json"); RepositoryFile file = unmarshalResource(RepositoryFile.class, "repository-file.json");
assertTrue(compareJson(file, "repository-file.json")); assertTrue(compareJson(file, "repository-file.json"));
} }
@Test
public void testRepositoryFileResponse() throws Exception {
RepositoryFileResponse file = unmarshalResource(RepositoryFileResponse.class, "repository-file-response.json");
assertTrue(compareJson(file, "repository-file-response.json"));
}
@Test @Test
public void testRunnerDetail() throws Exception { public void testRunnerDetail() throws Exception {
......
...@@ -18,6 +18,7 @@ import org.gitlab4j.api.models.Pipeline; ...@@ -18,6 +18,7 @@ import org.gitlab4j.api.models.Pipeline;
import org.gitlab4j.api.models.PipelineSchedule; import org.gitlab4j.api.models.PipelineSchedule;
import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.RepositoryFile; import org.gitlab4j.api.models.RepositoryFile;
import org.gitlab4j.api.models.RepositoryFileResponse;
import org.gitlab4j.api.models.Trigger; import org.gitlab4j.api.models.Trigger;
import org.gitlab4j.api.models.Variable; import org.gitlab4j.api.models.Variable;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
...@@ -39,8 +40,8 @@ public class TestPipelineApi extends AbstractIntegrationTest { ...@@ -39,8 +40,8 @@ public class TestPipelineApi extends AbstractIntegrationTest {
private static GitLabApi gitLabApi; private static GitLabApi gitLabApi;
private static Project testProject; private static Project testProject;
private static RepositoryFile createdGitlabCiYml; private static RepositoryFileResponse createdGitlabCiYml;
private static RepositoryFile gitlabCiYml; private static RepositoryFileResponse gitlabCiYml;
public TestPipelineApi() { public TestPipelineApi() {
super(); super();
...@@ -91,7 +92,10 @@ public class TestPipelineApi extends AbstractIntegrationTest { ...@@ -91,7 +92,10 @@ public class TestPipelineApi extends AbstractIntegrationTest {
Optional<RepositoryFile> fileInfo = Optional<RepositoryFile> fileInfo =
gitLabApi.getRepositoryFileApi().getOptionalFileInfo(testProject, ".gitlab-ci.yml", "master"); gitLabApi.getRepositoryFileApi().getOptionalFileInfo(testProject, ".gitlab-ci.yml", "master");
if (fileInfo.isPresent()) { if (fileInfo.isPresent()) {
gitlabCiYml = fileInfo.get(); RepositoryFileResponse file = new RepositoryFileResponse();
file.setBranch(fileInfo.get().getRef());
file.setFilePath(fileInfo.get().getFilePath());
gitlabCiYml = file;
} else { } else {
try { try {
......
...@@ -17,6 +17,7 @@ import java.util.Optional; ...@@ -17,6 +17,7 @@ import java.util.Optional;
import org.gitlab4j.api.models.Branch; import org.gitlab4j.api.models.Branch;
import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.RepositoryFile; import org.gitlab4j.api.models.RepositoryFile;
import org.gitlab4j.api.models.RepositoryFileResponse;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
...@@ -156,7 +157,7 @@ public class TestRepositoryFileApi extends AbstractIntegrationTest { ...@@ -156,7 +157,7 @@ public class TestRepositoryFileApi extends AbstractIntegrationTest {
RepositoryFile file = new RepositoryFile(); RepositoryFile file = new RepositoryFile();
file.setFilePath(TEST_FILEPATH); file.setFilePath(TEST_FILEPATH);
file.setContent(TEST_CONTENT); file.setContent(TEST_CONTENT);
RepositoryFile createdFile = gitLabApi.getRepositoryFileApi().createFile(project.getId(), file, TEST_BRANCH_NAME, "Testing createFile()."); RepositoryFileResponse createdFile = gitLabApi.getRepositoryFileApi().createFile(project.getId(), file, TEST_BRANCH_NAME, "Testing createFile().");
assertNotNull(createdFile); assertNotNull(createdFile);
gitLabApi.getRepositoryFileApi().deleteFile(project.getId(), TEST_FILEPATH, TEST_BRANCH_NAME, "Testing deleteFile()."); gitLabApi.getRepositoryFileApi().deleteFile(project.getId(), TEST_FILEPATH, TEST_BRANCH_NAME, "Testing deleteFile().");
...@@ -175,7 +176,7 @@ public class TestRepositoryFileApi extends AbstractIntegrationTest { ...@@ -175,7 +176,7 @@ public class TestRepositoryFileApi extends AbstractIntegrationTest {
RepositoryFile file = new RepositoryFile(); RepositoryFile file = new RepositoryFile();
file.setFilePath(TEST_FILEPATH); file.setFilePath(TEST_FILEPATH);
file.setContent(""); file.setContent("");
RepositoryFile createdFile = gitLabApi.getRepositoryFileApi().createFile(project.getId(), file, TEST_BRANCH_NAME, "Testing createFile()."); RepositoryFileResponse createdFile = gitLabApi.getRepositoryFileApi().createFile(project.getId(), file, TEST_BRANCH_NAME, "Testing createFile().");
assertNotNull(createdFile); assertNotNull(createdFile);
gitLabApi.getRepositoryFileApi().deleteFile(project.getId(), TEST_FILEPATH, TEST_BRANCH_NAME, "Testing deleteFile()."); gitLabApi.getRepositoryFileApi().deleteFile(project.getId(), TEST_FILEPATH, TEST_BRANCH_NAME, "Testing deleteFile().");
...@@ -194,7 +195,7 @@ public class TestRepositoryFileApi extends AbstractIntegrationTest { ...@@ -194,7 +195,7 @@ public class TestRepositoryFileApi extends AbstractIntegrationTest {
RepositoryFile file = new RepositoryFile(); RepositoryFile file = new RepositoryFile();
file.setFilePath(TEST_FILEPATH); file.setFilePath(TEST_FILEPATH);
file.setContent(TEST_CONTENT); file.setContent(TEST_CONTENT);
RepositoryFile createdFile = gitLabApi.getRepositoryFileApi().createFile(project.getId(), file, TEST_BRANCH_NAME, "Testing createFile()."); RepositoryFileResponse createdFile = gitLabApi.getRepositoryFileApi().createFile(project.getId(), file, TEST_BRANCH_NAME, "Testing createFile().");
assertNotNull(createdFile); assertNotNull(createdFile);
Optional<RepositoryFile> optionalFile = gitLabApi.getRepositoryFileApi().getOptionalFile(project, TEST_FILEPATH, TEST_BRANCH_NAME); Optional<RepositoryFile> optionalFile = gitLabApi.getRepositoryFileApi().getOptionalFile(project, TEST_FILEPATH, TEST_BRANCH_NAME);
......
{
"file_path": "app/project.rb",
"branch": "master"
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment