Commit 5996edbe authored by Cédric Tabin's avatar Cédric Tabin Committed by Tim Olshansky

Improvement of getMergedRequest methods and new cherryPick method (#209)

* New methods to retrieve Merge Requests with a given status

* improvement of the API to retrieve the Merge Requests

* new method to cherry-pick a commit

* new cherryPick method with a GitlabProject and javadoc

* fixed cherryPick method url and method

* moves MergeRequest status constants
parent 32eb941b
......@@ -937,15 +937,71 @@ public class GitlabAPI {
}
public List<GitlabMergeRequest> getOpenMergeRequests(Serializable projectId) throws IOException {
Query query = new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery();
query.append("state", "opened");
return getMergeRequestsWithStatus(projectId, GitlabMergeRequest.STATUS_OPENED);
}
public List<GitlabMergeRequest> getOpenMergeRequests(Serializable projectId, Pagination pagination) throws IOException {
return getMergeRequestsWithStatus(projectId, GitlabMergeRequest.STATUS_OPENED, pagination);
}
public List<GitlabMergeRequest> getOpenMergeRequests(GitlabProject project) throws IOException {
return getMergeRequestsWithStatus(project, GitlabMergeRequest.STATUS_OPENED);
}
public List<GitlabMergeRequest> getOpenMergeRequests(GitlabProject project, Pagination pagination) throws IOException {
return getMergeRequestsWithStatus(project, GitlabMergeRequest.STATUS_OPENED, pagination);
}
public List<GitlabMergeRequest> getMergedMergeRequests(Serializable projectId) throws IOException {
return getMergeRequestsWithStatus(projectId, GitlabMergeRequest.STATUS_MERGED);
}
public List<GitlabMergeRequest> getMergedMergeRequests(Serializable projectId, Pagination pagination) throws IOException {
return getMergeRequestsWithStatus(projectId, GitlabMergeRequest.STATUS_MERGED, pagination);
}
public List<GitlabMergeRequest> getMergedMergeRequests(GitlabProject project) throws IOException {
return getMergeRequestsWithStatus(project, GitlabMergeRequest.STATUS_MERGED);
}
public List<GitlabMergeRequest> getMergedMergeRequests(GitlabProject project, Pagination pagination) throws IOException {
return getMergeRequestsWithStatus(project, GitlabMergeRequest.STATUS_MERGED, pagination);
}
public List<GitlabMergeRequest> getClosedMergeRequests(Serializable projectId) throws IOException {
return getMergeRequestsWithStatus(projectId, GitlabMergeRequest.STATUS_CLOSED);
}
public List<GitlabMergeRequest> getClosedMergeRequests(Serializable projectId, Pagination pagination) throws IOException {
return getMergeRequestsWithStatus(projectId, GitlabMergeRequest.STATUS_CLOSED, pagination);
}
public List<GitlabMergeRequest> getClosedMergeRequests(GitlabProject project) throws IOException {
return getMergeRequestsWithStatus(project, GitlabMergeRequest.STATUS_CLOSED);
}
public List<GitlabMergeRequest> getClosedMergeRequests(GitlabProject project, Pagination pagination) throws IOException {
return getMergeRequestsWithStatus(project, GitlabMergeRequest.STATUS_CLOSED, pagination);
}
public List<GitlabMergeRequest> getMergeRequestsWithStatus(Serializable projectId, String status) throws IOException {
return getMergeRequestsWithStatus(projectId, status, new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE));
}
public List<GitlabMergeRequest> getMergeRequestsWithStatus(Serializable projectId, String state, Pagination pagination) throws IOException {
Query query = pagination.asQuery();
query.append("state", state);
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabMergeRequest.URL + query;
return retrieve().getAll(tailUrl, GitlabMergeRequest[].class);
}
public List<GitlabMergeRequest> getOpenMergeRequests(GitlabProject project) throws IOException {
Query query = new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery();
query.append("state", "opened");
public List<GitlabMergeRequest> getMergeRequestsWithStatus(GitlabProject project, String status) throws IOException {
return getMergeRequestsWithStatus(project, status, new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE));
}
public List<GitlabMergeRequest> getMergeRequestsWithStatus(GitlabProject project, String state, Pagination pagination) throws IOException {
Query query = pagination.asQuery();
query.append("state", state);
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabMergeRequest.URL + query;
return retrieve().getAll(tailUrl, GitlabMergeRequest[].class);
}
......@@ -955,16 +1011,45 @@ public class GitlabAPI {
return retrieve().getAll(tailUrl, GitlabMergeRequest[].class);
}
public List<GitlabMergeRequest> getMergeRequests(Serializable projectId, Pagination pagination) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabMergeRequest.URL + pagination.toString();
return retrieve().getAll(tailUrl, GitlabMergeRequest[].class);
}
public List<GitlabMergeRequest> getMergeRequests(GitlabProject project) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabMergeRequest.URL + PARAM_MAX_ITEMS_PER_PAGE;
return retrieve().getAll(tailUrl, GitlabMergeRequest[].class);
}
public List<GitlabMergeRequest> getMergeRequests(GitlabProject project, Pagination pagination) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabMergeRequest.URL + pagination.toString();
return retrieve().getAll(tailUrl, GitlabMergeRequest[].class);
}
public List<GitlabMergeRequest> getAllMergeRequests(GitlabProject project) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabMergeRequest.URL + PARAM_MAX_ITEMS_PER_PAGE;
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabMergeRequest.URL;
return retrieve().getAll(tailUrl, GitlabMergeRequest[].class);
}
/**
* Cherry picks a commit.
*
* @param projectId The id of the project
* @param sha The sha of the commit
* @param targetBranchName The branch on which the commit must be cherry-picked
* @return the commit of the cherry-pick.
* @throws IOException on gitlab api call error
*/
public GitlabCommit cherryPick(Serializable projectId, String sha, String targetBranchName) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + "/repository/commits/" + sha + "/cherry_pick";
return retrieve().with("branch", targetBranchName).to(tailUrl, GitlabCommit.class);
}
public GitlabCommit cherryPick(GitlabProject project, String sha, String targetBranchName) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + "/repository/commits/" + sha + "/cherry_pick";
return dispatch().with("branch", targetBranchName).to(tailUrl, GitlabCommit.class);
}
/**
* Return Merge Request.
*
......
......@@ -7,6 +7,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class GitlabMergeRequest {
public static final String URL = "/merge_requests";
public static final String STATUS_OPENED = "opened";
public static final String STATUS_MERGED = "merged";
public static final String STATUS_CLOSED = "closed";
private Integer id;
private Integer iid;
......
Markdown is supported
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