Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
835ec7da
Commit
835ec7da
authored
Mar 19, 2020
by
Greg Messner
Browse files
All ref query params are now properly URL encoded (#531)
parent
0c5b586d
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/JobApi.java
View file @
835ec7da
...
...
@@ -212,7 +212,7 @@ public class JobApi extends AbstractApi implements Constants {
Form
formData
=
new
GitLabApiForm
().
withParam
(
"job"
,
jobName
,
true
);
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
{
...
...
@@ -247,7 +247,7 @@ public class JobApi extends AbstractApi implements Constants {
public
InputStream
downloadArtifactsFile
(
Object
projectIdOrPath
,
String
ref
,
String
jobName
)
throws
GitLabApiException
{
Form
formData
=
new
GitLabApiForm
().
withParam
(
"job"
,
jobName
,
true
);
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
));
}
...
...
src/main/java/org/gitlab4j/api/PipelineApi.java
View file @
835ec7da
...
...
@@ -195,7 +195,7 @@ public class PipelineApi extends AbstractApi implements Constants {
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"scope"
,
scope
)
.
withParam
(
"status"
,
status
)
.
withParam
(
"ref"
,
ref
)
.
withParam
(
"ref"
,
(
ref
!=
null
?
urlEncode
(
ref
)
:
null
)
)
.
withParam
(
"yaml_errors"
,
yamlErrors
)
.
withParam
(
"name"
,
name
)
.
withParam
(
"username"
,
username
)
...
...
src/main/java/org/gitlab4j/api/RepositoryApi.java
View file @
835ec7da
...
...
@@ -5,6 +5,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.nio.file.Files
;
import
java.nio.file.StandardCopyOption
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Stream
;
...
...
@@ -384,7 +385,7 @@ public class RepositoryApi extends AbstractApi {
Form
formData
=
new
GitLabApiForm
()
.
withParam
(
"id"
,
getProjectIdOrPath
(
projectIdOrPath
),
true
)
.
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
);
return
(
new
Pager
<
TreeItem
>(
this
,
TreeItem
.
class
,
itemsPerPage
,
formData
.
asMap
(),
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"repository"
,
"tree"
));
...
...
@@ -696,7 +697,17 @@ public class RepositoryApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
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"
,
getProjectIdOrPath
(
projectIdOrPath
),
"repository"
,
"merge_base"
);
return
(
response
.
readEntity
(
Commit
.
class
));
...
...
src/main/java/org/gitlab4j/api/RepositoryFileApi.java
View file @
835ec7da
...
...
@@ -412,20 +412,19 @@ public class RepositoryFileApi extends AbstractApi {
* <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
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
* @return an InputStream to read the raw file from
* @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
))
{
Form
formData
=
new
GitLabApiForm
().
withParam
(
"file_path"
,
filepath
,
true
);
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
));
}
else
{
Form
formData
=
new
GitLabApiForm
().
withParam
(
"ref"
,
commitOrBranchName
,
true
);
Response
response
=
getWithAccepts
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
MediaType
.
MEDIA_TYPE_WILDCARD
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"repository"
,
"files"
,
urlEncode
(
filepath
),
"raw"
);
return
(
response
.
readEntity
(
InputStream
.
class
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment