Skip to content

Commit d4abafc

Browse files
committed
Mods to bring in-line with GitLab API documentation.
1 parent 0aca947 commit d4abafc

File tree

2 files changed

+31
-70
lines changed

2 files changed

+31
-70
lines changed

src/main/java/org/gitlab4j/api/ProjectApi.java

Lines changed: 21 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import org.gitlab4j.api.models.Project;
4444
import org.gitlab4j.api.models.ProjectHook;
4545
import org.gitlab4j.api.models.ProjectUser;
46-
import org.gitlab4j.api.models.PushRule;
46+
import org.gitlab4j.api.models.PushRules;
4747
import org.gitlab4j.api.models.Snippet;
4848
import org.gitlab4j.api.models.Visibility;
4949

@@ -1938,54 +1938,25 @@ public FileUpload uploadFile(Integer projectId, File fileToUpload, String mediaT
19381938
}
19391939

19401940
/**
1941-
* Get a list of project's push rules. Only returns the first page
1941+
* Get the project's push rules.
19421942
*
19431943
* GET /projects/:id/push_rule
19441944
*
19451945
* @param projectId the project ID to get the push rules for
1946-
* @return a list of project's push rules
1946+
* @return the push rules for the specified project
19471947
* @throws GitLabApiException if any exception occurs
19481948
*/
1949-
public List<PushRule> getPushRules(Integer projectId) throws GitLabApiException {
1950-
return (getPushRules(projectId, 1, getDefaultPerPage()));
1949+
public PushRules getPushRules(Integer projectId) throws GitLabApiException {
1950+
Response response = get(Response.Status.OK, null, "projects", projectId, "push_rule");
1951+
return (response.readEntity(PushRules.class));
19511952
}
19521953

19531954
/**
1954-
* Get a list of project's push rules using the specified page and per page settings.
1955-
*
1956-
* GET /projects/:id/push_rule
1957-
*
1958-
* @param projectId the project ID to get the push rules for
1959-
* @param page the page to get
1960-
* @param perPage the number of push rules per page
1961-
* @return the list of push rules in the specified range
1962-
* @throws GitLabApiException if any exception occurs
1963-
*/
1964-
public List<PushRule> getPushRules(Integer projectId, int page, int perPage) throws GitLabApiException {
1965-
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "push_rule");
1966-
return (response.readEntity(new GenericType<List<PushRule>>() {}));
1967-
}
1968-
1969-
/**
1970-
* Get a Pager of project's push rules.
1971-
*
1972-
* GET /projects/:id/push_rule
1973-
*
1974-
* @param projectId the project ID to get the push rules for
1975-
* @param itemsPerPage the number of push rules per page
1976-
* @return a Pager instance for paging over the project's push rules
1977-
* @throws GitLabApiException if any exception occurs
1978-
*/
1979-
public Pager<PushRule> getPushRules(Integer projectId, int itemsPerPage) throws GitLabApiException {
1980-
return (new Pager<PushRule>(this, PushRule.class, itemsPerPage, null, "projects", projectId, "push_rule"));
1981-
}
1982-
1983-
/**
1984-
* Creates new push rule for the specified project.
1955+
* Adds a push rule to a specified project.
19851956
*
19861957
* POST /projects/:id/push_rule
19871958
*
1988-
* The following properties on the PushRule instance are utilized in the creation of the push rule:
1959+
* The following properties on the PushRules instance are utilized in the creation of the push rule:
19891960
*
19901961
*<code>
19911962
* denyDeleteTag (optional) - Deny deleting a tag
@@ -1999,11 +1970,11 @@ public Pager<PushRule> getPushRules(Integer projectId, int itemsPerPage) throws
19991970
*</code>
20001971
*
20011972
* @param projectId the project ID to add the push rule to
2002-
* @param pushRule the PUshRule instance containing the push rule configuration to add
2003-
* @return a PushRule instance with the newly created push rule info
1973+
* @param pushRule the PushRule instance containing the push rule configuration to add
1974+
* @return a PushRules instance with the newly created push rule info
20041975
* @throws GitLabApiException if any exception occurs
20051976
*/
2006-
public PushRule createPushRule(Integer projectId, PushRule pushRule) throws GitLabApiException {
1977+
public PushRules createPushRules(Integer projectId, PushRules pushRule) throws GitLabApiException {
20071978

20081979
if (projectId == null) {
20091980
throw new RuntimeException("projectId cannot be null");
@@ -2020,15 +1991,15 @@ public PushRule createPushRule(Integer projectId, PushRule pushRule) throws GitL
20201991
.withParam("max_file_size", pushRule.getMaxFileSize());
20211992

20221993
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "push_rule");
2023-
return (response.readEntity(PushRule.class));
1994+
return (response.readEntity(PushRules.class));
20241995
}
20251996

20261997
/**
20271998
* Updates a push rule for the specified project.
20281999
*
20292000
* PUT /projects/:id/push_rule/:push_rule_id
20302001
*
2031-
* The following properties on the PushRule instance are utilized when updating the push rule:
2002+
* The following properties on the PushRules instance are utilized when updating the push rule:
20322003
*
20332004
*<code>
20342005
* denyDeleteTag (optional) - Deny deleting a tag
@@ -2042,21 +2013,16 @@ public PushRule createPushRule(Integer projectId, PushRule pushRule) throws GitL
20422013
*</code>
20432014
*
20442015
* @param projectId the project ID to update the push rule for
2045-
* @param pushRuleId the push rule ID to update
2046-
* @param pushRule the PUshRule instance containing the push rule configuration to update
2047-
* @return a PushRule instance with the newly created push rule info
2016+
* @param pushRule the PushRules instance containing the push rule configuration to update
2017+
* @return a PushRules instance with the newly created push rule info
20482018
* @throws GitLabApiException if any exception occurs
20492019
*/
2050-
public PushRule updatePushRule(Integer projectId, Integer pushRuleId, PushRule pushRule) throws GitLabApiException {
2020+
public PushRules updatePushRules(Integer projectId, PushRules pushRule) throws GitLabApiException {
20512021

20522022
if (projectId == null) {
20532023
throw new RuntimeException("projectId cannot be null");
20542024
}
20552025

2056-
if (pushRuleId == null) {
2057-
throw new RuntimeException("pushRuleId cannot be null");
2058-
}
2059-
20602026
GitLabApiForm formData = new GitLabApiForm()
20612027
.withParam("deny_delete_tag", pushRule.getDenyDeleteTag())
20622028
.withParam("member_check", pushRule.getMemberCheck())
@@ -2067,30 +2033,25 @@ public PushRule updatePushRule(Integer projectId, Integer pushRuleId, PushRule p
20672033
.withParam("file_name_regex", pushRule.getFileNameRegex())
20682034
.withParam("max_file_size", pushRule.getMaxFileSize());
20692035

2070-
Response response = post(Response.Status.OK, formData, "projects", projectId, "push_rule", pushRuleId);
2071-
return (response.readEntity(PushRule.class));
2036+
Response response = post(Response.Status.OK, formData, "projects", projectId, "push_rule");
2037+
return (response.readEntity(PushRules.class));
20722038
}
20732039

20742040
/**
20752041
* Removes a push rule from a project. This is an idempotent method and can be
20762042
* called multiple times. Either the push rule is available or not.
20772043
*
2078-
* DELETE /projects/:id/push_rule/:push_rule_id
2044+
* DELETE /projects/:id/push_rule
20792045
*
20802046
* @param projectId the project ID to delete the push rule from
2081-
* @param pushRuleId the push rule ID to delete
20822047
* @throws GitLabApiException if any exception occurs
20832048
*/
2084-
public void deletePushRule(Integer projectId, Integer pushRuleId) throws GitLabApiException {
2049+
public void deletePushRules(Integer projectId) throws GitLabApiException {
20852050

20862051
if (projectId == null) {
20872052
throw new RuntimeException("projectId cannot be null");
20882053
}
20892054

2090-
if (pushRuleId == null) {
2091-
throw new RuntimeException("pushRuleId cannot be null");
2092-
}
2093-
2094-
delete(Response.Status.OK, null, "projects", projectId, "push_rule", pushRuleId);
2055+
delete(Response.Status.OK, null, "projects", projectId, "push_rule");
20952056
}
20962057
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@XmlRootElement
1010
@XmlAccessorType(XmlAccessType.FIELD)
11-
public class PushRule {
11+
public class PushRules {
1212

1313
private Integer id;
1414
private Integer projectId;
@@ -38,7 +38,7 @@ public void setProjectId(Integer projectId) {
3838
this.projectId = projectId;
3939
}
4040

41-
public PushRule withProjectId(Integer projectId) {
41+
public PushRules withProjectId(Integer projectId) {
4242
this.projectId = projectId;
4343
return (this);
4444
}
@@ -51,7 +51,7 @@ public void setCommitMessageRegex(String commitMessageRegex) {
5151
this.commitMessageRegex = commitMessageRegex;
5252
}
5353

54-
public PushRule withCommitMessageRegex(String commitMessageRegex) {
54+
public PushRules withCommitMessageRegex(String commitMessageRegex) {
5555
this.commitMessageRegex = commitMessageRegex;
5656
return (this);
5757
}
@@ -64,7 +64,7 @@ public void setBranchNameRegex(String branchNameRegex) {
6464
this.branchNameRegex = branchNameRegex;
6565
}
6666

67-
public PushRule withBranchNameRegex(String branchNameRegex) {
67+
public PushRules withBranchNameRegex(String branchNameRegex) {
6868
this.branchNameRegex = branchNameRegex;
6969
return (this);
7070
}
@@ -77,7 +77,7 @@ public void setDenyDeleteTag(Boolean denyDeleteTag) {
7777
this.denyDeleteTag = denyDeleteTag;
7878
}
7979

80-
public PushRule withDenyDeleteTag(Boolean denyDeleteTag) {
80+
public PushRules withDenyDeleteTag(Boolean denyDeleteTag) {
8181
this.denyDeleteTag = denyDeleteTag;
8282
return (this);
8383
}
@@ -98,7 +98,7 @@ public void setMemberCheck(Boolean memberCheck) {
9898
this.memberCheck = memberCheck;
9999
}
100100

101-
public PushRule withMemberCheck(Boolean memberCheck) {
101+
public PushRules withMemberCheck(Boolean memberCheck) {
102102
this.memberCheck = memberCheck;
103103
return (this);
104104
}
@@ -111,7 +111,7 @@ public void setPreventSecrets(Boolean preventSecrets) {
111111
this.preventSecrets = preventSecrets;
112112
}
113113

114-
public PushRule withPreventSecrets(Boolean preventSecrets) {
114+
public PushRules withPreventSecrets(Boolean preventSecrets) {
115115
this.preventSecrets = preventSecrets;
116116
return (this);
117117
}
@@ -124,7 +124,7 @@ public void setAuthorEmailRegex(String authorEmailRegex) {
124124
this.authorEmailRegex = authorEmailRegex;
125125
}
126126

127-
public PushRule withAuthorEmailRegex(String authorEmailRegex) {
127+
public PushRules withAuthorEmailRegex(String authorEmailRegex) {
128128
this.authorEmailRegex = authorEmailRegex;
129129
return (this);
130130
}
@@ -137,7 +137,7 @@ public void setFileNameRegex(String fileNameRegex) {
137137
this.fileNameRegex = fileNameRegex;
138138
}
139139

140-
public PushRule withFileNameRegex(String fileNameRegex) {
140+
public PushRules withFileNameRegex(String fileNameRegex) {
141141
this.fileNameRegex = fileNameRegex;
142142
return (this);
143143
}
@@ -150,7 +150,7 @@ public void setMaxFileSize(Integer maxFileSize) {
150150
this.maxFileSize = maxFileSize;
151151
}
152152

153-
public PushRule withMaxFileSize(Integer maxFileSize) {
153+
public PushRules withMaxFileSize(Integer maxFileSize) {
154154
this.maxFileSize = maxFileSize;
155155
return (this);
156156
}

0 commit comments

Comments
 (0)