Skip to content

Commit 2eb39b0

Browse files
authored
Add missing parameters in ApprovalRuleParams (#1008)
Fixes #984
1 parent 7d1d6b1 commit 2eb39b0

File tree

1 file changed

+86
-15
lines changed

1 file changed

+86
-15
lines changed

src/main/java/org/gitlab4j/api/models/ApprovalRuleParams.java

Lines changed: 86 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,95 @@
66

77
public class ApprovalRuleParams {
88

9+
private Integer approvalsRequired;
910
private String name;
10-
private Integer approvalsRequired;
11-
private List<Long> userIds;
11+
private Boolean appliesToAllProtectedBranches;
1212
private List<Long> groupIds;
13+
private List<Long> protectedBranchIds;
14+
private String reportType;
15+
private String ruleType;
16+
private List<Long> userIds;
17+
private List<String> usernames;
1318

19+
/**
20+
* @param approvalsRequired The number of required approvals for this rule.
21+
* @return this ApprovalRuleParams instance
22+
*/
23+
public ApprovalRuleParams withApprovalsRequired(Integer approvalsRequired) {
24+
this.approvalsRequired = approvalsRequired;
25+
return (this);
26+
}
27+
28+
/**
29+
* @param name The name of the approval rule.
30+
* @return this ApprovalRuleParams instance
31+
*/
1432
public ApprovalRuleParams withName(String name) {
15-
this.name = name;
16-
return (this);
33+
this.name = name;
34+
return (this);
1735
}
1836

19-
public ApprovalRuleParams withApprovalsRequired(Integer approvalsRequired) {
20-
this.approvalsRequired = approvalsRequired;
21-
return (this);
37+
/**
38+
* @param appliesToAllProtectedBranches Whether the rule is applied to all protected branches. If set to true, the value of protected_branch_ids is ignored. Default is false. Introduced in GitLab 15.3.
39+
* @return this ApprovalRuleParams instance
40+
*/
41+
public ApprovalRuleParams withAppliesToAllProtectedBranches(Boolean appliesToAllProtectedBranches) {
42+
this.appliesToAllProtectedBranches = appliesToAllProtectedBranches;
43+
return (this);
44+
}
45+
46+
/**
47+
* @param groupIds The IDs of groups as approvers.
48+
* @return this ApprovalRuleParams instance
49+
*/
50+
public ApprovalRuleParams withGroupIds(List<Long> groupIds) {
51+
this.groupIds = groupIds;
52+
return (this);
2253
}
2354

55+
/**
56+
* @param protectedBranchIds The IDs of protected branches to scope the rule by. To identify the ID, use the API.
57+
* @return this ApprovalRuleParams instance
58+
*/
59+
public ApprovalRuleParams withProtectedBranchIds(List<Long> protectedBranchIds) {
60+
this.protectedBranchIds = protectedBranchIds;
61+
return (this);
62+
}
63+
64+
/**
65+
* @param reportType The report type required when the rule type is report_approver. The supported report types are license_scanning (Deprecated in GitLab 15.9) and code_coverage.
66+
* @return this ApprovalRuleParams instance
67+
*/
68+
public ApprovalRuleParams withReportType(String reportType) {
69+
this.reportType = reportType;
70+
return (this);
71+
}
72+
73+
/**
74+
* @param ruleType The type of rule. any_approver is a pre-configured default rule with approvals_required at 0. Other rules are regular and report_approver.
75+
* @return this ApprovalRuleParams instance
76+
*/
77+
public ApprovalRuleParams withRuleType(String ruleType) {
78+
this.ruleType = ruleType;
79+
return (this);
80+
}
81+
82+
/**
83+
* @param userIds The IDs of users as approvers. If you provide both user_ids and usernames, both lists of users are added.
84+
* @return this ApprovalRuleParams instance
85+
*/
2486
public ApprovalRuleParams withUserIds(List<Long> userIds) {
25-
this.userIds = userIds;
26-
return (this);
87+
this.userIds = userIds;
88+
return (this);
2789
}
2890

29-
public ApprovalRuleParams withGroupIds(List<Long> groupIds) {
30-
this.groupIds = groupIds;
31-
return (this);
91+
/**
92+
* @param usernames The usernames of approvers for this rule (same as user_ids but requires a list of usernames). If you provide both user_ids and usernames, both lists of users are added.
93+
* @return this ApprovalRuleParams instance
94+
*/
95+
public ApprovalRuleParams withUsernames(List<String> usernames) {
96+
this.usernames = usernames;
97+
return (this);
3298
}
3399

34100
/**
@@ -37,10 +103,15 @@ public ApprovalRuleParams withGroupIds(List<Long> groupIds) {
37103
* @return a GitLabApiForm instance holding the form parameters for this ApprovalRuleParams instance
38104
*/
39105
public GitLabApiForm getForm() {
40-
return new GitLabApiForm()
41-
.withParam("name", name)
106+
return new GitLabApiForm()
42107
.withParam("approvals_required", approvalsRequired, true)
108+
.withParam("name", name, true)
109+
.withParam("applies_to_all_protected_branches", appliesToAllProtectedBranches)
110+
.withParam("group_ids", groupIds)
111+
.withParam("protected_branch_ids", protectedBranchIds)
112+
.withParam("report_type", reportType)
113+
.withParam("rule_type", ruleType)
43114
.withParam("user_ids", userIds)
44-
.withParam("group_ids", groupIds);
115+
.withParam("usernames", usernames);
45116
}
46117
}

0 commit comments

Comments
 (0)