Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
74588bc7
Commit
74588bc7
authored
6 years ago
by
Greg Messner
Browse files
Options
Download
Email Patches
Plain Diff
Added createPipeline() method that takes the variables param (#321).
parent
87ea8f6d
main
5.0.x
5.0.x.jdk17
6.x
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/gitlab4j/api/GitLabApiForm.java
+32
-0
src/main/java/org/gitlab4j/api/GitLabApiForm.java
src/main/java/org/gitlab4j/api/PipelineApi.java
+20
-1
src/main/java/org/gitlab4j/api/PipelineApi.java
with
52 additions
and
1 deletion
+52
-1
src/main/java/org/gitlab4j/api/GitLabApiForm.java
+
32
-
0
View file @
74588bc7
...
...
@@ -2,6 +2,8 @@ package org.gitlab4j.api;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
javax.ws.rs.core.Form
;
import
javax.ws.rs.core.MultivaluedHashMap
;
...
...
@@ -134,6 +136,36 @@ public class GitLabApiForm extends Form {
return
(
this
);
}
/**
* Fluent method for adding an array of hash type query and form parameters to a get() or post() call.
*
* @param name the name of the field/attribute to add
* @param variables a Map containing array of hashes
* @param required the field is required flag
* @return this GitLabAPiForm instance
* @throws IllegalArgumentException if a required parameter is null or empty
*/
public
GitLabApiForm
withParam
(
String
name
,
Map
<
String
,
?>
variables
,
boolean
required
)
throws
IllegalArgumentException
{
if
(
variables
==
null
||
variables
.
isEmpty
())
{
if
(
required
)
{
throw
new
IllegalArgumentException
(
name
+
" cannot be empty or null"
);
}
return
(
this
);
}
for
(
Entry
<
String
,
?>
variable
:
variables
.
entrySet
())
{
Object
value
=
variable
.
getValue
();
if
(
value
!=
null
)
{
this
.
param
(
name
+
"[][key]"
,
variable
.
getKey
());
this
.
param
(
name
+
"[][value]"
,
value
.
toString
());
}
}
return
(
this
);
}
/**
* Fluent method for adding query and form parameters to a get() or post() call.
* If required is true and value is null, will throw an IllegalArgumentException.
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/gitlab4j/api/PipelineApi.java
+
20
-
1
View file @
74588bc7
package
org.gitlab4j.api
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.stream.Stream
;
...
...
@@ -224,7 +225,25 @@ public class PipelineApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs during execution
*/
public
Pipeline
createPipeline
(
Object
projectIdOrPath
,
String
ref
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"ref"
,
ref
);
return
(
createPipeline
(
projectIdOrPath
,
ref
,
null
));
}
/**
* Create a pipelines in a project.
*
* <pre><code>GitLab Endpoint: POST /projects/:id/pipeline</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param ref reference to commit
* @param variables a Map containing the variables available in the pipeline
* @return a Pipeline instance with the newly created pipeline info
* @throws GitLabApiException if any exception occurs during execution
*/
public
Pipeline
createPipeline
(
Object
projectIdOrPath
,
String
ref
,
Map
<
String
,
String
>
variables
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"ref"
,
ref
,
true
)
.
withParam
(
"variables"
,
variables
,
false
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
.
asMap
(),
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"pipeline"
);
return
(
response
.
readEntity
(
Pipeline
.
class
));
}
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Explore
Projects
Groups
Snippets