Commit 835ec7da authored by Greg Messner's avatar Greg Messner
Browse files

All ref query params are now properly URL encoded (#531)

parent 0c5b586d
...@@ -212,7 +212,7 @@ public class JobApi extends AbstractApi implements Constants { ...@@ -212,7 +212,7 @@ public class JobApi extends AbstractApi implements Constants {
Form formData = new GitLabApiForm().withParam("job", jobName, true); Form formData = new GitLabApiForm().withParam("job", jobName, true);
Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.MEDIA_TYPE_WILDCARD, Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.MEDIA_TYPE_WILDCARD,
"projects", getProjectIdOrPath(projectIdOrPath), "jobs", "artifacts", ref, "download"); "projects", getProjectIdOrPath(projectIdOrPath), "jobs", "artifacts", urlEncode(ref), "download");
try { try {
...@@ -247,7 +247,7 @@ public class JobApi extends AbstractApi implements Constants { ...@@ -247,7 +247,7 @@ public class JobApi extends AbstractApi implements Constants {
public InputStream downloadArtifactsFile(Object projectIdOrPath, String ref, String jobName) throws GitLabApiException { public InputStream downloadArtifactsFile(Object projectIdOrPath, String ref, String jobName) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("job", jobName, true); Form formData = new GitLabApiForm().withParam("job", jobName, true);
Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.MEDIA_TYPE_WILDCARD, Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.MEDIA_TYPE_WILDCARD,
"projects", getProjectIdOrPath(projectIdOrPath), "jobs", "artifacts", ref, "download"); "projects", getProjectIdOrPath(projectIdOrPath), "jobs", "artifacts", urlEncode(ref), "download");
return (response.readEntity(InputStream.class)); return (response.readEntity(InputStream.class));
} }
......
...@@ -195,7 +195,7 @@ public class PipelineApi extends AbstractApi implements Constants { ...@@ -195,7 +195,7 @@ public class PipelineApi extends AbstractApi implements Constants {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("scope", scope) .withParam("scope", scope)
.withParam("status", status) .withParam("status", status)
.withParam("ref", ref) .withParam("ref", (ref != null ? urlEncode(ref) : null))
.withParam("yaml_errors", yamlErrors) .withParam("yaml_errors", yamlErrors)
.withParam("name", name) .withParam("name", name)
.withParam("username", username) .withParam("username", username)
......
...@@ -5,6 +5,7 @@ import java.io.IOException; ...@@ -5,6 +5,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
...@@ -384,7 +385,7 @@ public class RepositoryApi extends AbstractApi { ...@@ -384,7 +385,7 @@ public class RepositoryApi extends AbstractApi {
Form formData = new GitLabApiForm() Form formData = new GitLabApiForm()
.withParam("id", getProjectIdOrPath(projectIdOrPath), true) .withParam("id", getProjectIdOrPath(projectIdOrPath), true)
.withParam("path", filePath, false) .withParam("path", filePath, false)
.withParam(isApiVersion(ApiVersion.V3) ? "ref_name" : "ref", refName, false) .withParam(isApiVersion(ApiVersion.V3) ? "ref_name" : "ref", (refName != null ? urlEncode(refName) : null), false)
.withParam("recursive", recursive, false); .withParam("recursive", recursive, false);
return (new Pager<TreeItem>(this, TreeItem.class, itemsPerPage, formData.asMap(), "projects", return (new Pager<TreeItem>(this, TreeItem.class, itemsPerPage, formData.asMap(), "projects",
getProjectIdOrPath(projectIdOrPath), "repository", "tree")); getProjectIdOrPath(projectIdOrPath), "repository", "tree"));
...@@ -696,7 +697,17 @@ public class RepositoryApi extends AbstractApi { ...@@ -696,7 +697,17 @@ public class RepositoryApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Commit getMergeBase(Object projectIdOrPath, List<String> refs) throws GitLabApiException { public Commit getMergeBase(Object projectIdOrPath, List<String> refs) throws GitLabApiException {
GitLabApiForm queryParams = new GitLabApiForm().withParam("refs", refs, true);
if (refs == null || refs.size() < 2) {
throw new RuntimeException("refs must conatin at least 2 refs");
}
List<String> encodedRefs = new ArrayList<>(refs.size());
for (String ref : refs) {
encodedRefs.add(urlEncode(ref));
}
GitLabApiForm queryParams = new GitLabApiForm().withParam("refs", encodedRefs, true);
Response response = get(Response.Status.OK, queryParams.asMap(), "projects", Response response = get(Response.Status.OK, queryParams.asMap(), "projects",
getProjectIdOrPath(projectIdOrPath), "repository", "merge_base"); getProjectIdOrPath(projectIdOrPath), "repository", "merge_base");
return (response.readEntity(Commit.class)); return (response.readEntity(Commit.class));
......
...@@ -412,20 +412,19 @@ public class RepositoryFileApi extends AbstractApi { ...@@ -412,20 +412,19 @@ public class RepositoryFileApi extends AbstractApi {
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/files/:filepath</code></pre> * <pre><code>GitLab Endpoint: GET /projects/:id/repository/files/:filepath</code></pre>
* *
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param commitOrBranchName the commit or branch name to get the file contents for * @param ref the commit or branch name to get the file contents for
* @param filepath the path of the file to get * @param filepath the path of the file to get
* @return an InputStream to read the raw file from * @return an InputStream to read the raw file from
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public InputStream getRawFile(Object projectIdOrPath, String commitOrBranchName, String filepath) throws GitLabApiException { public InputStream getRawFile(Object projectIdOrPath, String ref, String filepath) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("ref", (ref != null ? ref : null), true);
if (isApiVersion(ApiVersion.V3)) { if (isApiVersion(ApiVersion.V3)) {
Form formData = new GitLabApiForm().withParam("file_path", filepath, true);
Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.MEDIA_TYPE_WILDCARD, Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.MEDIA_TYPE_WILDCARD,
"projects", getProjectIdOrPath(projectIdOrPath), "repository", "blobs", commitOrBranchName); "projects", getProjectIdOrPath(projectIdOrPath), "repository", "blobs", ref);
return (response.readEntity(InputStream.class)); return (response.readEntity(InputStream.class));
} else { } else {
Form formData = new GitLabApiForm().withParam("ref", commitOrBranchName, true);
Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.MEDIA_TYPE_WILDCARD, Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.MEDIA_TYPE_WILDCARD,
"projects", getProjectIdOrPath(projectIdOrPath), "repository", "files", urlEncode(filepath), "raw"); "projects", getProjectIdOrPath(projectIdOrPath), "repository", "files", urlEncode(filepath), "raw");
return (response.readEntity(InputStream.class)); return (response.readEntity(InputStream.class));
......
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