Commit d4abafc3 authored by Greg Messner's avatar Greg Messner
Browse files

Mods to bring in-line with GitLab API documentation.

parent 0aca947c
......@@ -43,7 +43,7 @@ import org.gitlab4j.api.models.Member;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.ProjectHook;
import org.gitlab4j.api.models.ProjectUser;
import org.gitlab4j.api.models.PushRule;
import org.gitlab4j.api.models.PushRules;
import org.gitlab4j.api.models.Snippet;
import org.gitlab4j.api.models.Visibility;
......@@ -1938,54 +1938,25 @@ public class ProjectApi extends AbstractApi implements Constants {
}
/**
* Get a list of project's push rules. Only returns the first page
* Get the project's push rules.
*
* GET /projects/:id/push_rule
*
* @param projectId the project ID to get the push rules for
* @return a list of project's push rules
* @return the push rules for the specified project
* @throws GitLabApiException if any exception occurs
*/
public List<PushRule> getPushRules(Integer projectId) throws GitLabApiException {
return (getPushRules(projectId, 1, getDefaultPerPage()));
public PushRules getPushRules(Integer projectId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "push_rule");
return (response.readEntity(PushRules.class));
}
/**
* Get a list of project's push rules using the specified page and per page settings.
*
* GET /projects/:id/push_rule
*
* @param projectId the project ID to get the push rules for
* @param page the page to get
* @param perPage the number of push rules per page
* @return the list of push rules in the specified range
* @throws GitLabApiException if any exception occurs
*/
public List<PushRule> getPushRules(Integer projectId, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "push_rule");
return (response.readEntity(new GenericType<List<PushRule>>() {}));
}
/**
* Get a Pager of project's push rules.
*
* GET /projects/:id/push_rule
*
* @param projectId the project ID to get the push rules for
* @param itemsPerPage the number of push rules per page
* @return a Pager instance for paging over the project's push rules
* @throws GitLabApiException if any exception occurs
*/
public Pager<PushRule> getPushRules(Integer projectId, int itemsPerPage) throws GitLabApiException {
return (new Pager<PushRule>(this, PushRule.class, itemsPerPage, null, "projects", projectId, "push_rule"));
}
/**
* Creates new push rule for the specified project.
* Adds a push rule to a specified project.
*
* POST /projects/:id/push_rule
*
* The following properties on the PushRule instance are utilized in the creation of the push rule:
* The following properties on the PushRules instance are utilized in the creation of the push rule:
*
*<code>
* denyDeleteTag (optional) - Deny deleting a tag
......@@ -1999,11 +1970,11 @@ public class ProjectApi extends AbstractApi implements Constants {
*</code>
*
* @param projectId the project ID to add the push rule to
* @param pushRule the PUshRule instance containing the push rule configuration to add
* @return a PushRule instance with the newly created push rule info
* @param pushRule the PushRule instance containing the push rule configuration to add
* @return a PushRules instance with the newly created push rule info
* @throws GitLabApiException if any exception occurs
*/
public PushRule createPushRule(Integer projectId, PushRule pushRule) throws GitLabApiException {
public PushRules createPushRules(Integer projectId, PushRules pushRule) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
......@@ -2020,7 +1991,7 @@ public class ProjectApi extends AbstractApi implements Constants {
.withParam("max_file_size", pushRule.getMaxFileSize());
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "push_rule");
return (response.readEntity(PushRule.class));
return (response.readEntity(PushRules.class));
}
/**
......@@ -2028,7 +1999,7 @@ public class ProjectApi extends AbstractApi implements Constants {
*
* PUT /projects/:id/push_rule/:push_rule_id
*
* The following properties on the PushRule instance are utilized when updating the push rule:
* The following properties on the PushRules instance are utilized when updating the push rule:
*
*<code>
* denyDeleteTag (optional) - Deny deleting a tag
......@@ -2042,21 +2013,16 @@ public class ProjectApi extends AbstractApi implements Constants {
*</code>
*
* @param projectId the project ID to update the push rule for
* @param pushRuleId the push rule ID to update
* @param pushRule the PUshRule instance containing the push rule configuration to update
* @return a PushRule instance with the newly created push rule info
* @param pushRule the PushRules instance containing the push rule configuration to update
* @return a PushRules instance with the newly created push rule info
* @throws GitLabApiException if any exception occurs
*/
public PushRule updatePushRule(Integer projectId, Integer pushRuleId, PushRule pushRule) throws GitLabApiException {
public PushRules updatePushRules(Integer projectId, PushRules pushRule) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
if (pushRuleId == null) {
throw new RuntimeException("pushRuleId cannot be null");
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("deny_delete_tag", pushRule.getDenyDeleteTag())
.withParam("member_check", pushRule.getMemberCheck())
......@@ -2067,30 +2033,25 @@ public class ProjectApi extends AbstractApi implements Constants {
.withParam("file_name_regex", pushRule.getFileNameRegex())
.withParam("max_file_size", pushRule.getMaxFileSize());
Response response = post(Response.Status.OK, formData, "projects", projectId, "push_rule", pushRuleId);
return (response.readEntity(PushRule.class));
Response response = post(Response.Status.OK, formData, "projects", projectId, "push_rule");
return (response.readEntity(PushRules.class));
}
/**
* Removes a push rule from a project. This is an idempotent method and can be
* called multiple times. Either the push rule is available or not.
*
* DELETE /projects/:id/push_rule/:push_rule_id
* DELETE /projects/:id/push_rule
*
* @param projectId the project ID to delete the push rule from
* @param pushRuleId the push rule ID to delete
* @throws GitLabApiException if any exception occurs
*/
public void deletePushRule(Integer projectId, Integer pushRuleId) throws GitLabApiException {
public void deletePushRules(Integer projectId) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
if (pushRuleId == null) {
throw new RuntimeException("pushRuleId cannot be null");
}
delete(Response.Status.OK, null, "projects", projectId, "push_rule", pushRuleId);
delete(Response.Status.OK, null, "projects", projectId, "push_rule");
}
}
\ No newline at end of file
......@@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class PushRule {
public class PushRules {
private Integer id;
private Integer projectId;
......@@ -38,7 +38,7 @@ public class PushRule {
this.projectId = projectId;
}
public PushRule withProjectId(Integer projectId) {
public PushRules withProjectId(Integer projectId) {
this.projectId = projectId;
return (this);
}
......@@ -51,7 +51,7 @@ public class PushRule {
this.commitMessageRegex = commitMessageRegex;
}
public PushRule withCommitMessageRegex(String commitMessageRegex) {
public PushRules withCommitMessageRegex(String commitMessageRegex) {
this.commitMessageRegex = commitMessageRegex;
return (this);
}
......@@ -64,7 +64,7 @@ public class PushRule {
this.branchNameRegex = branchNameRegex;
}
public PushRule withBranchNameRegex(String branchNameRegex) {
public PushRules withBranchNameRegex(String branchNameRegex) {
this.branchNameRegex = branchNameRegex;
return (this);
}
......@@ -77,7 +77,7 @@ public class PushRule {
this.denyDeleteTag = denyDeleteTag;
}
public PushRule withDenyDeleteTag(Boolean denyDeleteTag) {
public PushRules withDenyDeleteTag(Boolean denyDeleteTag) {
this.denyDeleteTag = denyDeleteTag;
return (this);
}
......@@ -98,7 +98,7 @@ public class PushRule {
this.memberCheck = memberCheck;
}
public PushRule withMemberCheck(Boolean memberCheck) {
public PushRules withMemberCheck(Boolean memberCheck) {
this.memberCheck = memberCheck;
return (this);
}
......@@ -111,7 +111,7 @@ public class PushRule {
this.preventSecrets = preventSecrets;
}
public PushRule withPreventSecrets(Boolean preventSecrets) {
public PushRules withPreventSecrets(Boolean preventSecrets) {
this.preventSecrets = preventSecrets;
return (this);
}
......@@ -124,7 +124,7 @@ public class PushRule {
this.authorEmailRegex = authorEmailRegex;
}
public PushRule withAuthorEmailRegex(String authorEmailRegex) {
public PushRules withAuthorEmailRegex(String authorEmailRegex) {
this.authorEmailRegex = authorEmailRegex;
return (this);
}
......@@ -137,7 +137,7 @@ public class PushRule {
this.fileNameRegex = fileNameRegex;
}
public PushRule withFileNameRegex(String fileNameRegex) {
public PushRules withFileNameRegex(String fileNameRegex) {
this.fileNameRegex = fileNameRegex;
return (this);
}
......@@ -150,7 +150,7 @@ public class PushRule {
this.maxFileSize = maxFileSize;
}
public PushRule withMaxFileSize(Integer maxFileSize) {
public PushRules withMaxFileSize(Integer maxFileSize) {
this.maxFileSize = maxFileSize;
return (this);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment