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
ae4ae02f
Unverified
Commit
ae4ae02f
authored
Nov 17, 2019
by
Greg Messner
Committed by
GitHub
Nov 17, 2019
Browse files
Add approvals api support - #470 (#476)
parent
a8976d32
Changes
14
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
ae4ae02f
...
...
@@ -53,7 +53,7 @@ To utilize GitLab4J™ API in your Java project, simply add the following de
```
java
dependencies
{
...
compile
group:
'
org
.
gitlab4j
'
,
name:
'
gitlab4j
-
api
'
,
version:
'
4.1
2
.
18
'
compile
group:
'
org
.
gitlab4j
'
,
name:
'
gitlab4j
-
api
'
,
version:
'
4.1
4
.
0
'
}
```
...
...
@@ -64,7 +64,7 @@ dependencies {
<dependency>
<groupId>
org.gitlab4j
</groupId>
<artifactId>
gitlab4j-api
</artifactId>
<version>
4.1
2.18
</version>
<version>
4.1
4.0
</version>
</dependency>
```
...
...
pom.xml
View file @
ae4ae02f
...
...
@@ -5,7 +5,7 @@
<groupId>
org.gitlab4j
</groupId>
<artifactId>
gitlab4j-api
</artifactId>
<packaging>
jar
</packaging>
<version>
4.1
2.19
-SNAPSHOT
</version>
<version>
4.1
4.0
-SNAPSHOT
</version>
<name>
GitLab4J-API - GitLab API Java Client
</name>
<description>
GitLab4J-API (gitlab4j-api) provides a full featured Java client library for working with GitLab repositories and servers via the GitLab REST API.
</description>
<url>
https://github.com/gitlab4j/gitlab4j-api
</url>
...
...
src/main/java/org/gitlab4j/api/MergeRequestApi.java
View file @
ae4ae02f
...
...
@@ -10,6 +10,9 @@ import javax.ws.rs.core.MultivaluedMap;
import
javax.ws.rs.core.Response
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.models.ApprovalRule
;
import
org.gitlab4j.api.models.ApprovalRuleParams
;
import
org.gitlab4j.api.models.ApprovalState
;
import
org.gitlab4j.api.models.Commit
;
import
org.gitlab4j.api.models.Issue
;
import
org.gitlab4j.api.models.MergeRequest
;
...
...
@@ -19,6 +22,8 @@ import org.gitlab4j.api.models.Participant;
/**
* This class implements the client side API for the GitLab merge request calls.
* @see <a href="https://docs.gitlab.com/ce/api/merge_requests.html">Merge requests API at GitLab</a>
* @see <a href="https://docs.gitlab.com/ce/api/merge_request_approvals.html">Merge request approvals API at GitLab</a>
*/
public
class
MergeRequestApi
extends
AbstractApi
{
...
...
@@ -664,7 +669,7 @@ public class MergeRequestApi extends AbstractApi {
/**
* Get the merge request with approval information.
*
* Note: This API endpoint is only available on 8.9
EE
and above.
* Note: This API endpoint is only available on 8.9
Starter
and above.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/approvals</code></pre>
*
...
...
@@ -674,6 +679,22 @@ public class MergeRequestApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
public
MergeRequest
getMergeRequestApprovals
(
Object
projectIdOrPath
,
Integer
mergeRequestIid
)
throws
GitLabApiException
{
return
(
getApprovals
(
projectIdOrPath
,
mergeRequestIid
));
}
/**
* Get the merge request with approval information.
*
* Note: This API endpoint is only available on 8.9 Starter and above.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/approvals</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return a MergeRequest instance with approval information included
* @throws GitLabApiException if any exception occurs
*/
public
MergeRequest
getApprovals
(
Object
projectIdOrPath
,
Integer
mergeRequestIid
)
throws
GitLabApiException
{
if
(
mergeRequestIid
==
null
)
{
throw
new
RuntimeException
(
"mergeRequestIid cannot be null"
);
...
...
@@ -683,6 +704,162 @@ public class MergeRequestApi extends AbstractApi {
return
(
response
.
readEntity
(
MergeRequest
.
class
));
}
/**
* Get the approval state of a merge request.
* Note: This API endpoint is only available on 12.3 Starter and above.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/approval_state</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return a ApprovalState instance with approval state
* @throws GitLabApiException if any exception occurs
*/
public
ApprovalState
getApprovalState
(
Object
projectIdOrPath
,
Integer
mergeRequestIid
)
throws
GitLabApiException
{
if
(
mergeRequestIid
==
null
)
{
throw
new
RuntimeException
(
"mergeRequestIid cannot be null"
);
}
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"merge_requests"
,
mergeRequestIid
,
"approval_state"
);
return
(
response
.
readEntity
(
ApprovalState
.
class
));
}
/**
* Get a list of the merge request level approval rules.
* Note: This API endpoint is only available on 12.3 Starter and above.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/approval_rules</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return a List of ApprovalRule instances for the specified merge request.
* @throws GitLabApiException if any exception occurs
*/
public
List
<
ApprovalRule
>
getApprovalRules
(
Object
projectIdOrPath
,
Integer
mergeRequestIid
)
throws
GitLabApiException
{
return
(
getApprovalRules
(
projectIdOrPath
,
mergeRequestIid
,
-
1
).
all
());
}
/**
* Get a Pager of the merge request level approval rules.
* Note: This API endpoint is only available on 12.3 Starter and above.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/approval_rules</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @param itemsPerPage the number of ApprovalRule instances that will be fetched per page
* @return a Pager of ApprovalRule instances for the specified merge request.
* @throws GitLabApiException if any exception occurs
*/
public
Pager
<
ApprovalRule
>
getApprovalRules
(
Object
projectIdOrPath
,
Integer
mergeRequestIid
,
int
itemsPerPage
)
throws
GitLabApiException
{
if
(
mergeRequestIid
==
null
)
{
throw
new
RuntimeException
(
"mergeRequestIid cannot be null"
);
}
return
(
new
Pager
<
ApprovalRule
>(
this
,
ApprovalRule
.
class
,
itemsPerPage
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"merge_requests"
,
mergeRequestIid
,
"approval_rules"
));
}
/**
* Get a Stream of the merge request level approval rules.
* Note: This API endpoint is only available on 12.3 Starter and above.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/approval_rules</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return a Stream of ApprovalRule instances for the specified merge request.
* @throws GitLabApiException if any exception occurs
*/
public
Stream
<
ApprovalRule
>
getApprovalRulesStream
(
Object
projectIdOrPath
,
Integer
mergeRequestIid
)
throws
GitLabApiException
{
return
(
getApprovalRules
(
projectIdOrPath
,
mergeRequestIid
,
-
1
).
stream
());
}
/**
* Create a merge request level approval rule.
* Note: This API endpoint is only available on 12.3 Starter and above.
*
* <pre><code>GitLab Endpoint: POST /projects/:id/merge_requests/:merge_request_iid/approval_rules</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @param projectRuleId the ID of a project-level approval rule
* @param params the ApprovalRuleParams instance holding the parameters for the approval rule
* @return a ApprovalRule instance with approval configuration
* @throws GitLabApiException if any exception occurs
*/
public
ApprovalRule
createApprovalRule
(
Object
projectIdOrPath
,
Integer
mergeRequestIid
,
Integer
projectRuleId
,
ApprovalRuleParams
params
)
throws
GitLabApiException
{
if
(
mergeRequestIid
==
null
)
{
throw
new
RuntimeException
(
"mergeRequestIid cannot be null"
);
}
GitLabApiForm
formData
=
params
.
getForm
();
formData
.
withParam
(
"approval_project_rule_id"
,
projectRuleId
);
Response
response
=
post
(
Response
.
Status
.
OK
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"merge_requests"
,
mergeRequestIid
,
"approval_rules"
);
return
(
response
.
readEntity
(
ApprovalRule
.
class
));
}
/**
* Update the specified the merge request level approval rule.
* Note: This API endpoint is only available on 12.3 Starter and above.
*
* <pre><code>GitLab Endpoint: PUT /projects/:id/merge_requests/:merge_request_iid/approval_rules/:approval_rule_id</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @param approvalRuleId the ID of the approval rule
* @param params the ApprovalRuleParams instance holding the parameters for the approval rule update
* @return a ApprovalRule instance with approval configuration
* @throws GitLabApiException if any exception occurs
*/
public
ApprovalRule
updateApprovalRule
(
Object
projectIdOrPath
,
Integer
mergeRequestIid
,
Integer
approvalRuleId
,
ApprovalRuleParams
params
)
throws
GitLabApiException
{
if
(
mergeRequestIid
==
null
)
{
throw
new
RuntimeException
(
"mergeRequestIid cannot be null"
);
}
if
(
approvalRuleId
==
null
)
{
throw
new
RuntimeException
(
"approvalRuleId cannot be null"
);
}
GitLabApiForm
formData
=
params
.
getForm
();
Response
response
=
putWithFormData
(
Response
.
Status
.
OK
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"merge_requests"
,
mergeRequestIid
,
"approval_rules"
,
approvalRuleId
);
return
(
response
.
readEntity
(
ApprovalRule
.
class
));
}
/**
* Delete the specified the merge request level approval rule.
* Note: This API endpoint is only available on 12.3 Starter and above.
*
* <pre><code>GitLab Endpoint: DELETE /projects/:id/merge_requests/:merge_request_iid/approval_rules/:approval_rule_id</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @param approvalRuleId the ID of the approval rule
* @throws GitLabApiException if any exception occurs
*/
public
void
deleteApprovalRule
(
Object
projectIdOrPath
,
Integer
mergeRequestIid
,
Integer
approvalRuleId
)
throws
GitLabApiException
{
if
(
mergeRequestIid
==
null
)
{
throw
new
RuntimeException
(
"mergeRequestIid cannot be null"
);
}
if
(
approvalRuleId
==
null
)
{
throw
new
RuntimeException
(
"approvalRuleId cannot be null"
);
}
delete
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"merge_requests"
,
mergeRequestIid
,
"approval_rules"
,
approvalRuleId
);
}
/**
* Approve a merge request.
*
...
...
@@ -867,4 +1044,18 @@ public class MergeRequestApi extends AbstractApi {
public
Stream
<
Issue
>
getClosesIssuesStream
(
Object
projectIdOrPath
,
Integer
mergeRequestIid
)
throws
GitLabApiException
{
return
(
getClosesIssues
(
projectIdOrPath
,
mergeRequestIid
,
getDefaultPerPage
()).
stream
());
}
/**
* Get list containing all the issues that would be closed by merging the provided merge request.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/closes_issues</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param mergeRequestIid the IID of the merge request to get the closes issues for
* @return a List containing all the issues that would be closed by merging the provided merge request
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Issue
>
getApprovalStatus
(
Object
projectIdOrPath
,
Integer
mergeRequestIid
)
throws
GitLabApiException
{
return
(
getClosesIssues
(
projectIdOrPath
,
mergeRequestIid
,
getDefaultPerPage
()).
all
());
}
}
src/main/java/org/gitlab4j/api/Pager.java
View file @
ae4ae02f
...
...
@@ -73,6 +73,10 @@ public class Pager<T> implements Iterator<List<T>>, Constants {
javaType
=
mapper
.
getTypeFactory
().
constructCollectionType
(
List
.
class
,
type
);
if
(
itemsPerPage
<
1
)
{
itemsPerPage
=
api
.
getDefaultPerPage
();
}
// Make sure the per_page parameter is present
if
(
queryParams
==
null
)
{
queryParams
=
new
GitLabApiForm
().
withParam
(
PER_PAGE_PARAM
,
itemsPerPage
).
asMap
();
...
...
src/main/java/org/gitlab4j/api/ProjectApi.java
View file @
ae4ae02f
...
...
@@ -40,6 +40,8 @@ import javax.ws.rs.core.Response;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.models.AccessLevel
;
import
org.gitlab4j.api.models.AccessRequest
;
import
org.gitlab4j.api.models.ApprovalRule
;
import
org.gitlab4j.api.models.ApprovalRuleParams
;
import
org.gitlab4j.api.models.Badge
;
import
org.gitlab4j.api.models.Event
;
import
org.gitlab4j.api.models.FileUpload
;
...
...
@@ -47,6 +49,7 @@ import org.gitlab4j.api.models.Issue;
import
org.gitlab4j.api.models.Member
;
import
org.gitlab4j.api.models.Namespace
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.ProjectApprovalsConfig
;
import
org.gitlab4j.api.models.ProjectFetches
;
import
org.gitlab4j.api.models.ProjectFilter
;
import
org.gitlab4j.api.models.ProjectHook
;
...
...
@@ -64,6 +67,8 @@ import org.gitlab4j.api.models.Visibility;
* @see <a href="https://docs.gitlab.com/ce/api/members.html">Group and project members API at GitLab</a>
* @see <a href="https://docs.gitlab.com/ce/api/access_requests.html#group-and-project-access-requests-api">Group and project access requests API</a>
* @see <a href="https://docs.gitlab.com/ee/api/project_badges.html">Project badges API</a>
* @see <a href="https://docs.gitlab.com/ce/api/merge_request_approvals.html">
* Merge request approvals API (Project-level) at GitLab</a>
*/
public
class
ProjectApi
extends
AbstractApi
implements
Constants
{
...
...
@@ -3063,4 +3068,142 @@ public class ProjectApi extends AbstractApi implements Constants {
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"badges"
,
"render"
);
return
(
response
.
readEntity
(
Badge
.
class
));
}
/**
* Get the project's approval information.
* Note: This API endpoint is only available on 10.6 Starter and above.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/approvals</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a ProjectApprovalsConfig instance with the project's approvals configuration
* @throws GitLabApiException if any exception occurs
*/
public
ProjectApprovalsConfig
getApprovalsConfiguration
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"approvals"
);
return
(
response
.
readEntity
(
ProjectApprovalsConfig
.
class
));
}
/**
* Set the project's approvals configuration.
* Note: This API endpoint is only available on 10.6 Starter and above.
*
* <pre><code>GitLab Endpoint: POST /projects/:id/approvals</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param config a ProjectApprovalsConfig instance with the approval configuration
* @return a ProjectApprovalsConfig instance with the project's approvals configuration
* @throws GitLabApiException if any exception occurs
*/
public
ProjectApprovalsConfig
getApprovalsConfiguration
(
Object
projectIdOrPath
,
ProjectApprovalsConfig
config
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
config
.
getForm
();
Response
response
=
post
(
Response
.
Status
.
OK
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"approvals"
);
return
(
response
.
readEntity
(
ProjectApprovalsConfig
.
class
));
}
/**
* Get a list of the project-level approval rules.
* Note: This API endpoint is only available on 12.3 Starter and above.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/approval_rules</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a List of ApprovalRuke instances for the specified project.
* @throws GitLabApiException if any exception occurs
*/
public
List
<
ApprovalRule
>
getApprovalRules
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
return
(
getApprovalRules
(
projectIdOrPath
,
-
1
).
all
());
}
/**
* Get a Pager of the project-level approval rules.
* Note: This API endpoint is only available on 12.3 Starter and above.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/approval_rules</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param itemsPerPage the number of ApprovalRule instances that will be fetched per page
* @return a Pager of ApprovalRuke instances for the specified project.
* @throws GitLabApiException if any exception occurs
*/
public
Pager
<
ApprovalRule
>
getApprovalRules
(
Object
projectIdOrPath
,
int
itemsPerPage
)
throws
GitLabApiException
{
return
(
new
Pager
<
ApprovalRule
>(
this
,
ApprovalRule
.
class
,
itemsPerPage
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"approval_rules"
));
}
/**
* Get a Stream of the project-level approval rules.
* Note: This API endpoint is only available on 12.3 Starter and above.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/approval_rules</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a Stream of ApprovalRule instances for the specified project.
* @throws GitLabApiException if any exception occurs
*/
public
Stream
<
ApprovalRule
>
getApprovalRulesStream
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
return
(
getApprovalRules
(
projectIdOrPath
,
-
1
).
stream
());
}
/**
* Create a project-level approval rule.
* Note: This API endpoint is only available on 12.3 Starter and above.
*
* <pre><code>GitLab Endpoint: POST /projects/:id/approval_rules</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param params the ApprovalRuleParams instance holding the parameters for the approval rule
* @return a ApprovalRule instance with approval configuration
* @throws GitLabApiException if any exception occurs
*/
public
ApprovalRule
createApprovalRule
(
Object
projectIdOrPath
,
ApprovalRuleParams
params
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
params
.
getForm
();
Response
response
=
post
(
Response
.
Status
.
OK
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"approval_rules"
);
return
(
response
.
readEntity
(
ApprovalRule
.
class
));
}
/**
* Update the specified the project-level approval rule.
* Note: This API endpoint is only available on 12.3 Starter and above.
*
* <pre><code>GitLab Endpoint: PUT /projects/:id/approval_rules/:approval_rule_id</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param approvalRuleId the ID of the approval rule
* @param params the ApprovalRuleParams instance holding the parameters for the approval rule update
* @return a ApprovalRule instance with approval configuration
* @throws GitLabApiException if any exception occurs
*/
public
ApprovalRule
updateApprovalRule
(
Object
projectIdOrPath
,
Integer
approvalRuleId
,
ApprovalRuleParams
params
)
throws
GitLabApiException
{
if
(
approvalRuleId
==
null
)
{
throw
new
RuntimeException
(
"approvalRuleId cannot be null"
);
}
GitLabApiForm
formData
=
params
.
getForm
();
Response
response
=
putWithFormData
(
Response
.
Status
.
OK
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"approval_rules"
,
approvalRuleId
);
return
(
response
.
readEntity
(
ApprovalRule
.
class
));
}
/**
* Delete the specified the project-level approval rule.
* Note: This API endpoint is only available on 12.3 Starter and above.
*
* <pre><code>GitLab Endpoint: DELETE /projects/:id/approval_rules/:approval_rule_id</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param approvalRuleId the ID of the approval rule
* @throws GitLabApiException if any exception occurs
*/
public
void
deleteApprovalRule
(
Object
projectIdOrPath
,
Integer
approvalRuleId
)
throws
GitLabApiException
{
if
(
approvalRuleId
==
null
)
{
throw
new
RuntimeException
(
"approvalRuleId cannot be null"
);
}
delete
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"approval_rules"
,
approvalRuleId
);
}
}
src/main/java/org/gitlab4j/api/models/ApprovalRule.java
0 → 100644
View file @
ae4ae02f
package
org.gitlab4j.api.models
;
import
java.util.List
;
import
org.gitlab4j.api.utils.JacksonJson
;
import
com.fasterxml.jackson.databind.annotation.JsonDeserialize
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
public
class
ApprovalRule
{
private
Integer
id
;
private
String
name
;
private
String
ruleType
;
private
List
<
User
>
eligibleApprovers
;
private
Integer
approvalsRequired
;
private
ApprovalRule
sourceRule
;
private
List
<
User
>
users
;
private
List
<
Group
>
groups
;
private
Boolean
containsHiddenGroups
;
@JsonSerialize
(
using
=
JacksonJson
.
UserListSerializer
.
class
)
@JsonDeserialize
(
using
=
JacksonJson
.
UserListDeserializer
.
class
)
private
List
<
User
>
approvedBy
;
private
Boolean
approved
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getRuleType
()
{
return
ruleType
;
}
public
void
setRuleType
(
String
ruleType
)
{
this
.
ruleType
=
ruleType
;
}
public
List
<
User
>
getEligibleApprovers
()
{
return
eligibleApprovers
;
}
public
void
setEligibleApprovers
(
List
<
User
>
eligibleApprovers
)
{
this
.
eligibleApprovers
=
eligibleApprovers
;
}
public
Integer
getApprovalsRequired
()
{
return
approvalsRequired
;
}
public
void
setApprovalsRequired
(
Integer
approvalsRequired
)
{
this
.
approvalsRequired
=
approvalsRequired
;
}
public
ApprovalRule
getSourceRule
()
{
return
sourceRule
;
}
public
void
setSourceRule
(
ApprovalRule
sourceRule
)
{
this
.
sourceRule
=
sourceRule
;
}
public
List
<
User
>
getUsers
()
{
return
users
;
}
public
void
setUsers
(
List
<
User
>
users
)
{
this
.
users
=
users
;
}
public
List
<
Group
>
getGroups
()
{
return
groups
;
}
public
void
setGroups
(
List
<
Group
>
groups
)
{
this
.
groups
=
groups
;
}
public
Boolean
getContainsHiddenGroups
()
{
return
containsHiddenGroups
;
}
public
void
setContainsHiddenGroups
(
Boolean
containsHiddenGroups
)
{
this
.
containsHiddenGroups
=
containsHiddenGroups
;
}
public
List
<
User
>
getApprovedBy
()
{
return
approvedBy
;
}
public
void
setApprovedBy
(
List
<
User
>
approvedBy
)
{
this
.
approvedBy
=
approvedBy
;
}
public
Boolean
getApproved
()
{
return
approved
;
}
public
void
setApproved
(
Boolean
approved
)
{
this
.
approved
=
approved
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
}
}
src/main/java/org/gitlab4j/api/models/ApprovalRuleParams.java
0 → 100644
View file @
ae4ae02f
package
org.gitlab4j.api.models
;
import
java.util.List
;
import
org.gitlab4j.api.GitLabApiForm
;
public
class
ApprovalRuleParams
{
private
String
name
;
private
Integer
approvalsRequired
;
private
List
<
Integer
>
userIds
;
private
List
<
Integer
>
groupIds
;
public
ApprovalRuleParams
withName
(
String
name
)
{
this
.
name
=
name
;
return
(
this
);
}
public
ApprovalRuleParams
withApprovalsRequired
(
Integer
approvalsRequired
)
{
this
.
approvalsRequired
=
approvalsRequired
;
return
(
this
);
}
public
ApprovalRuleParams
withUserIds
(
List
<
Integer
>
userIds
)
{
this
.
userIds
=
userIds
;
return
(
this
);
}
public
ApprovalRuleParams
withGroupIds
(
List
<
Integer
>
groupIds
)
{
this
.
groupIds
=
groupIds
;
return
(
this
);
}
/**
* Get the form params specified by this instance.
*
* @return a GitLabApiForm instance holding the form parameters for this ApprovalRuleParams instance
*/
public
GitLabApiForm
getForm
()
{
return
new
GitLabApiForm
()
.
withParam
(
"name"
,
name
)
.
withParam
(
"approvals_required"
,
approvalsRequired
,
true
)
.
withParam
(
"user_ids"
,
userIds
)
.
withParam
(
"group_ids"
,
groupIds
);
}
}
src/main/java/org/gitlab4j/api/models/ApprovalState.java
0 → 100644
View file @
ae4ae02f
package
org.gitlab4j.api.models
;
import
java.util.List
;
import
org.gitlab4j.api.utils.JacksonJson
;
public
class
ApprovalState
{
private
Boolean
approvalRulesOverwritten
;
private
List
<
ApprovalRule
>
rules
;
public
Boolean
getApprovalRulesOverwritten
()
{
return
approvalRulesOverwritten
;
}
public
void
setApprovalRulesOverwritten
(
Boolean
approvalRulesOverwritten
)
{
this
.
approvalRulesOverwritten
=
approvalRulesOverwritten
;
}
public
List
<
ApprovalRule
>
getRules
()
{
return
rules
;
}
public
void
setRules
(
List
<
ApprovalRule
>
rules
)
{
this
.
rules
=
rules
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
}
}
src/main/java/org/gitlab4j/api/models/ApprovedBy.java
0 → 100644
View file @
ae4ae02f
package
org.gitlab4j.api.models
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
/**
* This class is used by various models to represent the approved_by property,
* which can contain a User or Group instance.
*
* @since 4.19.0
*/
public
class
ApprovedBy
{
private
User
user
;
private
Group
group
;
public
User
getUser
()
{
return
user
;
}
public
void
setUser
(
User
user
)
{
if
(
group
!=
null
)
{
throw
new
RuntimeException
(
"ApprovedBy is already set to a group, cannot be set to a user"
);
}
this
.
user
=
user
;
}
public
Group
getGroup
()
{
return
group
;
}
public
void
setGroup
(
Group
group
)
{
if
(
user
!=
null
)
{
throw
new
RuntimeException
(
"ApprovedBy is already set to a user, cannot be set to a group"
);
}
this
.
group
=
group
;
}
/**
* Return the user or group that represents this ApprovedBy instance. Returned
* object will either be an instance of a User or Group.
*
* @return the user or group that represents this ApprovedBy instance
*/
@JsonIgnore
public
Object
getApprovedBy
()
{
return
(
user
!=
null
?
user
:
group
);
}
}
src/main/java/org/gitlab4j/api/models/ProjectApprovalsConfig.java
0 → 100644
View file @
ae4ae02f
package
org.gitlab4j.api.models
;
import
org.gitlab4j.api.GitLabApiForm
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
public
class
ProjectApprovalsConfig
{
private
Integer
approvalsBeforeMerge
;
private
Boolean
resetApprovalsOnPush
;
private
Boolean
disableOverridingApproversPerMergeRequest
;
private
Boolean
mergeRequestsAuthorApproval
;
private
Boolean
mergeRequestsDisableCommittersApproval
;
public
Integer
getApprovalsBeforeMerge
()
{
return
approvalsBeforeMerge
;
}
public
void
setApprovalsBeforeMerge
(
Integer
approvalsBeforeMerge
)
{
this
.
approvalsBeforeMerge
=
approvalsBeforeMerge
;
}
public
ProjectApprovalsConfig
withApprovalsBeforeMerge
(
Integer
approvalsBeforeMerge
)
{
this
.
approvalsBeforeMerge
=
approvalsBeforeMerge
;
return
(
this
);
}
public
Boolean
getResetApprovalsOnPush
()
{
return
resetApprovalsOnPush
;
}
public
void
setResetApprovalsOnPush
(
Boolean
resetApprovalsOnPush
)
{
this
.
resetApprovalsOnPush
=
resetApprovalsOnPush
;
}
public
ProjectApprovalsConfig
withResetApprovalsOnPush
(
Boolean
resetApprovalsOnPush
)
{
this
.
resetApprovalsOnPush
=
resetApprovalsOnPush
;
return
(
this
);
}
public
Boolean
getDisableOverridingApproversPerMergeRequest
()
{
return
disableOverridingApproversPerMergeRequest
;
}
public
void
setDisableOverridingApproversPerMergeRequest
(
Boolean
disableOverridingApproversPerMergeRequest
)
{
this
.
disableOverridingApproversPerMergeRequest
=
disableOverridingApproversPerMergeRequest
;
}
public
ProjectApprovalsConfig
withDisableOverridingApproversPerMergeRequest
(
Boolean
disableOverridingApproversPerMergeRequest
)
{
this
.
disableOverridingApproversPerMergeRequest
=
disableOverridingApproversPerMergeRequest
;
return
(
this
);
}
public
Boolean
getMergeRequestsAuthorApproval
()
{
return
mergeRequestsAuthorApproval
;
}
public
void
setMergeRequestsAuthorApproval
(
Boolean
mergeRequestsAuthorApproval
)
{
this
.
mergeRequestsAuthorApproval
=
mergeRequestsAuthorApproval
;
}
public
ProjectApprovalsConfig
withMergeRequestsAuthorApproval
(
Boolean
mergeRequestsAuthorApproval
)
{
this
.
mergeRequestsAuthorApproval
=
mergeRequestsAuthorApproval
;
return
(
this
);
}
public
Boolean
getMergeRequestsDisableCommittersApproval
()
{
return
mergeRequestsDisableCommittersApproval
;
}
public
void
setMergeRequestsDisableCommittersApproval
(
Boolean
mergeRequestsDisableCommittersApproval
)
{
this
.
mergeRequestsDisableCommittersApproval
=
mergeRequestsDisableCommittersApproval
;
}
public
ProjectApprovalsConfig
withMergeRequestsDisableCommittersApproval
(
Boolean
mergeRequestsDisableCommittersApproval
)
{
this
.
mergeRequestsDisableCommittersApproval
=
mergeRequestsDisableCommittersApproval
;
return
(
this
);
}
/**
* Get the form params specified by this instance.
*
* @return a GitLabApiForm instance holding the form parameters for this ProjectApprovalsConfig instance
*/
@JsonIgnore
public
GitLabApiForm
getForm
()
{
return
new
GitLabApiForm
()
.
withParam
(
"approvals_before_merge"
,
approvalsBeforeMerge
)
.
withParam
(
"reset_approvals_on_push"
,
resetApprovalsOnPush
)
.
withParam
(
"disable_overriding_approvers_per_merge_reques"
,
disableOverridingApproversPerMergeRequest
)
.
withParam
(
"merge_requests_author_approval"
,
mergeRequestsAuthorApproval
)
.
withParam
(
"merge_requests_disable_committers_approval"
,
mergeRequestsDisableCommittersApproval
);
}
}
src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
View file @
ae4ae02f
...
...
@@ -36,6 +36,7 @@ import java.util.Map;
import
org.gitlab4j.api.models.AccessRequest
;
import
org.gitlab4j.api.models.Application
;
import
org.gitlab4j.api.models.ApplicationSettings
;
import
org.gitlab4j.api.models.ApprovalRule
;
import
org.gitlab4j.api.models.ArtifactsFile
;
import
org.gitlab4j.api.models.AwardEmoji
;
import
org.gitlab4j.api.models.Badge
;
...
...
@@ -79,6 +80,7 @@ import org.gitlab4j.api.models.PackageFile;
import
org.gitlab4j.api.models.Pipeline
;
import
org.gitlab4j.api.models.PipelineSchedule
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.ProjectApprovalsConfig
;
import
org.gitlab4j.api.models.ProjectFetches
;
import
org.gitlab4j.api.models.ProjectHook
;
import
org.gitlab4j.api.models.ProjectUser
;
...
...
@@ -406,6 +408,12 @@ public class TestGitLabApiBeans {
assertTrue
(
compareJson
(
variable
,
"project-variable-details.json"
));
}
@Test
public
void
testProjectApprovalsCofig
()
throws
Exception
{
ProjectApprovalsConfig
approvalsConfig
=
unmarshalResource
(
ProjectApprovalsConfig
.
class
,
"project-approvals-config.json"
);
assertTrue
(
compareJson
(
approvalsConfig
,
"project-approvals-config.json"
));
}
@Test
public
void
testProtectedBranch
()
throws
Exception
{
ProtectedBranch
protectedBranch
=
unmarshalResource
(
ProtectedBranch
.
class
,
"protected-branch.json"
);
...
...
@@ -479,6 +487,12 @@ public class TestGitLabApiBeans {
assertTrue
(
compareJson
(
mergeRequestApprovals
,
"approvals.json"
));
}
@Test
public
void
testMergeRequestApprovalRule
()
throws
Exception
{
ApprovalRule
approvalRule
=
unmarshalResource
(
ApprovalRule
.
class
,
"approval-rule.json"
);
assertTrue
(
compareJson
(
approvalRule
,
"approval-rule.json"
));
}
@Test
public
void
testMergeRequest
()
throws
Exception
{
MergeRequest
mergeRequest
=
unmarshalResource
(
MergeRequest
.
class
,
"merge-request.json"
);
...
...
src/test/resources/org/gitlab4j/api/approval-rule.json
0 → 100644
View file @
ae4ae02f
{
"id"
:
1
,
"name"
:
"security"
,
"rule_type"
:
"regular"
,
"eligible_approvers"
:
[
{
"id"
:
2
,
"name"
:
"John Doe"
,
"username"
:
"jdoe"
,
"state"
:
"active"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/0?s=80&d=identicon"
,
"web_url"
:
"http://localhost/jdoe"
},
{
"id"
:
50
,
"name"
:
"Group Member 1"
,
"username"
:
"group_member_1"
,
"state"
:
"active"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/0?s=80&d=identicon"
,
"web_url"
:
"http://localhost/group_member_1"
}
],
"approvals_required"
:
1
,
"users"
:
[
{
"id"
:
2
,
"name"
:
"John Doe"
,
"username"
:
"jdoe"
,
"state"
:
"active"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/0?s=80&d=identicon"
,
"web_url"
:
"http://localhost/jdoe"
}
],
"groups"
:
[
{
"id"
:
5
,
"name"
:
"group1"
,
"path"
:
"group1"
,
"description"
:
""
,
"visibility"
:
"public"
,
"lfs_enabled"
:
false
,
"web_url"
:
"http://localhost/groups/group1"
,
"request_access_enabled"
:
false
,
"full_name"
:
"group1"
,
"full_path"
:
"group1"
}
],
"contains_hidden_groups"
:
false
}
\ No newline at end of file
src/test/resources/org/gitlab4j/api/approval-state.json
0 → 100644
View file @
ae4ae02f
{
"approval_rules_overwritten"
:
true
,
"rules"
:
[
{
"id"
:
1
,
"name"
:
"Ruby"
,
"rule_type"
:
"regular"
,
"eligible_approvers"
:
[
{
"id"
:
4
,
"name"
:
"John Doe"
,
"username"
:
"jdoe"
,
"state"
:
"active"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/0?s=80&d=identicon"
,
"web_url"
:
"http://localhost/jdoe"
}
],
"approvals_required"
:
2
,
"users"
:
[
{
"id"
:
4
,
"name"
:
"John Doe"
,
"username"
:
"jdoe"
,
"state"
:
"active"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/0?s=80&d=identicon"
,
"web_url"
:
"http://localhost/jdoe"
}
],
"groups"
:
[],
"contains_hidden_groups"
:
false
,
"approved_by"
:
[
{
"id"
:
4
,
"name"
:
"John Doe"
,
"username"
:
"jdoe"
,
"state"
:
"active"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/0?s=80&d=identicon"
,
"web_url"
:
"http://localhost/jdoe"
}
],
"approved"
:
true
}
]
}
\ No newline at end of file
src/test/resources/org/gitlab4j/api/project-approvals-config.json
0 → 100644
View file @
ae4ae02f
{
"approvals_before_merge"
:
2
,
"reset_approvals_on_push"
:
true
,
"disable_overriding_approvers_per_merge_request"
:
false
,
"merge_requests_author_approval"
:
false
,
"merge_requests_disable_committers_approval"
:
false
}
\ No newline at end of file
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