Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.messners.gitlab.api;
  
  import java.util.List;
  
  import  com.sun.jersey.api.representation.Form;

This class implements the client side API for the GitLab merge request calls.

Author(s):
Greg Messner <greg@messners.com>
 
 public class MergeRequestApi extends AbstractApi {
 
 	MergeRequestApi (GitLabApi gitLabApi) {
 		super(gitLabApi);
 	}


Get all merge requests for the specified project. GET /projects/:id/merge_requests

Parameters:
projectId the project ID to get the merge requests for
Returns:
all merge requests for the specified project
Throws:
GitLabApiException
 
 	public List<MergeRequestgetMergeRequests (Integer projectIdthrows GitLabApiException {		
 		ClientResponse response = get(..null"projects"projectId"merge_requests");
 		return (response.getEntity(new GenericType<List<MergeRequest>>() {}));
 	}


Get information about a single merge request. GET /projects/:id/merge_request/:merge_request_id

Parameters:
projectId
mergeRequestId
Returns:
the specified MergeRequest instance
Throws:
GitLabApiException
 
 	public MergeRequest getMergeRequest (Integer projectIdInteger mergeRequestIdthrows GitLabApiException {		
 		ClientResponse response = get(..null"projects"projectId"merge_request"mergeRequestId);
 		return (response.getEntity(MergeRequest.class));
 	}


Creates a merge request and optionally assigns a reviewer to it. POST /projects/:id/merge_requests

Parameters:
projectId the ID of a project, required
sourceBranch the source branch, required
targetBranch the target branch, required
title the title for the merge request, required
description the description of the merge request
assigneeId the Assignee user ID, optional
Returns:
the created MergeRequest instance
Throws:
GitLabApiException
 
 	public MergeRequest createMergeRequest (Integer projectIdString sourceBranchString targetBranchString titleString descriptionInteger assigneeId
 			throws GitLabApiException {
 		
 		if (projectId == null) {
 			throw new RuntimeException("projectId cannot be null");
 		}
 		
 		Form formData = new Form();
 		addFormParam(formData"source_branch"sourceBranchtrue);		
 		addFormParam(formData"target_branch"targetBranchtrue);
 		addFormParam(formData"title",         title,        true);
 		addFormParam(formData"description",   description,  false);
 		addFormParam(formData"assignee_id",   assigneeId,   false);
 		
 		ClientResponse response = post(..formData"projects"projectId"merge_requests");
 		return (response.getEntity(MergeRequest.class));
 	}


Updates an existing merge request. You can change branches, title, or even close the MR. PUT /projects/:id/merge_request/:merge_request_id

Parameters:
projectId
mergeRequestId
sourceBranch
targetBranch
title
description
assigneeId
Returns:
the updated merge request
Throws:
GitLabApiException
	public MergeRequest updateMergeRequest (Integer projectIdInteger mergeRequestId
			String sourceBranchString targetBranchString titleString descriptionInteger assigneeIdthrows GitLabApiException {
		if (projectId == null) {
			throw new RuntimeException("mergeRequestId cannot be null");
		}
		if (mergeRequestId == null) {
			throw new RuntimeException("projectId cannot be null");
		}
		Form formData = new Form();
		addFormParam(formData"source_branch"sourceBranchfalse);		
		addFormParam(formData"target_branch"targetBranchfalse);
		addFormParam(formData"title",         title,        false);
		addFormParam(formData"description",   description,  false);
		addFormParam(formData"assignee_id",   assigneeId,   false);
		ClientResponse response = put(..formData"projects"projectId"merge_request"mergeRequestId);
		return (response.getEntity(MergeRequest.class));		
	}


Adds a comment to a merge request. POST /projects/:id/merge_request/:merge_request_id/comments

Parameters:
projectId
mergeRequestId
comments
Returns:
the added merge request comment
Throws:
GitLabApiException
	public MergeRequestComment addMergeRequestComment (Integer projectIdInteger mergeRequestIdString commentsthrows GitLabApiException {
		Form formData = new Form();
		formData.add("note"comments);		
		ClientResponse response = post(..formData"projects"projectId"merge_request"mergeRequestId"comments");
		return (response.getEntity(MergeRequestComment.class));
	}
New to GrepCode? Check out our FAQ X