Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
java-gitlab-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
java-gitlab-api
Commits
e42d54df
Commit
e42d54df
authored
Sep 02, 2016
by
Tim Olshansky
Committed by
GitHub
Sep 02, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #156 from zakyvit/master
Build variables implementation
parents
78d599c2
b22fb80a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
218 additions
and
1 deletion
+218
-1
GitlabAPI.java
src/main/java/org/gitlab/api/GitlabAPI.java
+130
-0
GitlabBuildVariable.java
src/main/java/org/gitlab/api/models/GitlabBuildVariable.java
+40
-0
GitlabAPITest.java
src/test/java/org/gitlab/api/GitlabAPITest.java
+48
-1
No files found.
src/main/java/org/gitlab/api/GitlabAPI.java
View file @
e42d54df
...
...
@@ -2241,4 +2241,134 @@ public class GitlabAPI {
+
GitlabNote
.
URL
+
noteId
+
GitlabAward
.
URL
+
"/"
+
award
.
getId
();
retrieve
().
method
(
"DELETE"
).
to
(
tailUrl
,
Void
.
class
);
}
/**
* Gets build variables associated with a project.
* @param projectId The ID of the project.
* @return A non-null list of variables.
* @throws IOException
*/
public
List
<
GitlabBuildVariable
>
getBuildVariables
(
Integer
projectId
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
projectId
+
GitlabBuildVariable
.
URL
;
GitlabBuildVariable
[]
variables
=
retrieve
().
to
(
tailUrl
,
GitlabBuildVariable
[].
class
);
return
Arrays
.
asList
(
variables
);
}
/**
* Gets build variables associated with a project.
* @param project The project associated with variables.
* @return A non-null list of variables.
* @throws IOException
*/
public
List
<
GitlabBuildVariable
>
getBuildVariables
(
GitlabProject
project
)
throws
IOException
{
return
getBuildVariables
(
project
.
getId
());
}
/**
* Gets build variable associated with a project and key.
* @param projectId The ID of the project.
* @param key The key of the variable.
* @return A variable.
* @throws IOException
*/
public
GitlabBuildVariable
getBuildVariable
(
Integer
projectId
,
String
key
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
projectId
+
GitlabBuildVariable
.
URL
+
key
;
return
retrieve
().
to
(
tailUrl
,
GitlabBuildVariable
.
class
);
}
/**
* Gets build variable associated with a project and key.
* @param project The project associated with the variable.
* @return A variable.
* @throws IOException
*/
public
GitlabBuildVariable
getBuildVariable
(
GitlabProject
project
,
String
key
)
throws
IOException
{
return
getBuildVariable
(
project
.
getId
(),
key
);
}
/**
* Creates a new build variable.
* @param projectId The ID of the project containing the new variable.
* @param key The key of the variable.
* @param value The value of the variable
* @return The newly created variable.
* @throws IOException
*/
public
GitlabBuildVariable
createBuildVariable
(
Integer
projectId
,
String
key
,
String
value
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
projectId
+
GitlabBuildVariable
.
URL
;
return
dispatch
().
with
(
"key"
,
key
)
.
with
(
"value"
,
value
)
.
to
(
tailUrl
,
GitlabBuildVariable
.
class
);
}
/**
* Creates a new variable.
* @param projectId The ID of the project containing the variable.
* @param variable The variable to create.
* @return The newly created variable.
*/
public
GitlabBuildVariable
createBuildVariable
(
Integer
projectId
,
GitlabBuildVariable
variable
)
throws
IOException
{
String
key
=
variable
.
getKey
();
String
value
=
variable
.
getValue
();
return
createBuildVariable
(
projectId
,
key
,
value
);
}
/**
* Deletes an existing variable.
* @param projectId The ID of the project containing the variable.
* @param key The key of the variable to delete.
* @throws IOException
*/
public
void
deleteBuildVariable
(
Integer
projectId
,
String
key
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
projectId
+
GitlabBuildVariable
.
URL
+
key
;
retrieve
().
method
(
"DELETE"
).
to
(
tailUrl
,
Void
.
class
);
}
/**
* Deletes an existing variable.
* @param projectId The ID of the project containing the variable.
* @param variable The variable to delete.
* @throws IOException
*/
public
void
deleteBuildVariable
(
Integer
projectId
,
GitlabBuildVariable
variable
)
throws
IOException
{
deleteBuildVariable
(
projectId
,
variable
.
getKey
());
}
/**
* Updates an existing variable.
* @param projectId The ID of the project containing the variable.
* @param key The key of the variable to update.
* @param newValue The updated value.
* @return The updated, deserialized variable.
* @throws IOException
*/
public
GitlabBuildVariable
updateBuildVariable
(
Integer
projectId
,
String
key
,
String
newValue
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
projectId
+
GitlabBuildVariable
.
URL
+
key
;
GitlabHTTPRequestor
requestor
=
retrieve
().
method
(
"PUT"
);
if
(
newValue
!=
null
)
{
requestor
=
requestor
.
with
(
"value"
,
newValue
);
}
return
requestor
.
to
(
tailUrl
,
GitlabBuildVariable
.
class
);
}
}
src/main/java/org/gitlab/api/models/GitlabBuildVariable.java
0 → 100644
View file @
e42d54df
package
org
.
gitlab
.
api
.
models
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
/**
* @author Vitezslav Zak
*/
public
class
GitlabBuildVariable
{
public
final
static
String
URL
=
"/variables/"
;
public
GitlabBuildVariable
()
{
}
public
GitlabBuildVariable
(
String
key
,
String
value
)
{
this
.
key
=
key
;
this
.
value
=
value
;
}
@JsonProperty
(
"key"
)
private
String
key
;
@JsonProperty
(
"value"
)
private
String
value
;
public
String
getKey
()
{
return
key
;
}
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
}
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
}
src/test/java/org/gitlab/api/GitlabAPITest.java
View file @
e42d54df
package
org
.
gitlab
.
api
;
import
org.gitlab.api.models.GitlabBuildVariable
;
import
org.gitlab.api.models.GitlabProject
;
import
org.gitlab.api.models.GitlabGroup
;
import
org.gitlab.api.models.GitlabUser
;
import
org.junit.Before
;
...
...
@@ -65,6 +67,51 @@ public class GitlabAPITest {
assertEquals
(
expected
+
"/"
,
api
.
getUrl
(
""
).
toString
());
}
@Test
public
void
testCreateUpdateDeleteVariable
()
throws
IOException
{
String
key
=
randVal
(
"key"
);
String
value
=
randVal
(
"value"
);
String
newValue
=
randVal
(
"new_value"
);
String
projectName
=
randVal
(
"project"
);
GitlabProject
project
=
api
.
createProject
(
projectName
);
assertNotNull
(
project
);
GitlabBuildVariable
variable
=
api
.
createBuildVariable
(
project
.
getId
(),
key
,
value
);
assertNotNull
(
variable
);
GitlabBuildVariable
refetched
=
api
.
getBuildVariable
(
project
.
getId
(),
key
);
assertNotNull
(
refetched
);
assertEquals
(
refetched
.
getKey
(),
variable
.
getKey
());
assertEquals
(
refetched
.
getValue
(),
variable
.
getValue
());
api
.
updateBuildVariable
(
project
.
getId
(),
key
,
newValue
);
GitlabBuildVariable
postUpdate
=
api
.
getBuildVariable
(
project
.
getId
(),
key
);
assertNotNull
(
postUpdate
);
assertEquals
(
postUpdate
.
getKey
(),
variable
.
getKey
());
assertNotEquals
(
postUpdate
.
getValue
(),
variable
.
getValue
());
assertEquals
(
postUpdate
.
getValue
(),
newValue
);
api
.
deleteBuildVariable
(
project
.
getId
(),
key
);
// expect a 404, but we have no access to it
try
{
GitlabBuildVariable
shouldNotExist
=
api
.
getBuildVariable
(
project
.
getId
(),
key
);
assertNull
(
shouldNotExist
);
}
catch
(
FileNotFoundException
thisIsSoOddForAnRESTApiClient
)
{
assertTrue
(
true
);
// expected
}
api
.
deleteProject
(
project
.
getId
());
}
@Test
public
void
testCreateUpdateDeleteUser
()
throws
IOException
{
...
...
@@ -142,6 +189,6 @@ public class GitlabAPITest {
}
private
String
randVal
(
String
postfix
)
{
return
rand
+
"
-
"
+
postfix
;
return
rand
+
"
_
"
+
postfix
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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