use of org.gitlab4j.api.models.MergeRequest in project legend-sdlc by finos.
the class GitLabComparisonApi method getReviewWorkspaceCreationComparison.
@Override
public Comparison getReviewWorkspaceCreationComparison(String projectId, String reviewId) {
LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null");
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
RepositoryApi repositoryApi = getGitLabApi(gitLabProjectId.getGitLabMode()).getRepositoryApi();
MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi(gitLabProjectId.getGitLabMode()).getMergeRequestApi(), gitLabProjectId, reviewId);
WorkspaceInfo workspaceInfo = parseWorkspaceBranchName(mergeRequest.getSourceBranch());
if (workspaceInfo == null) {
throw new LegendSDLCServerException("Unknown review in project " + projectId + ": " + reviewId, Response.Status.NOT_FOUND);
}
DiffRef diffRef = mergeRequest.getDiffRefs();
if ((diffRef == null) || (diffRef.getStartSha() == null) || (diffRef.getHeadSha() == null)) {
throw new LegendSDLCServerException("Unable to get revision info for review " + reviewId + " in project " + projectId);
}
String fromRevisionId = diffRef.getBaseSha();
String toRevisionId = diffRef.getHeadSha();
ProjectStructure fromProjectStructure = getProjectStructure(projectId, workspaceInfo.getWorkspaceId(), fromRevisionId, workspaceInfo.getWorkspaceType(), workspaceInfo.getWorkspaceAccessType());
ProjectStructure toProjectStructure = getProjectStructure(projectId, workspaceInfo.getWorkspaceId(), toRevisionId, workspaceInfo.getWorkspaceType(), workspaceInfo.getWorkspaceAccessType());
return getComparisonResult(gitLabProjectId, repositoryApi, fromRevisionId, toRevisionId, fromProjectStructure, toProjectStructure);
}
use of org.gitlab4j.api.models.MergeRequest in project legend-sdlc by finos.
the class GitLabEntityApi method getReviewFromEntityAccessContext.
public EntityAccessContext getReviewFromEntityAccessContext(String projectId, String reviewId) {
LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null");
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi(gitLabProjectId.getGitLabMode()).getMergeRequestApi(), gitLabProjectId, reviewId);
validateMergeRequestForComparison(mergeRequest);
DiffRef diffRef = mergeRequest.getDiffRefs();
if (diffRef != null && diffRef.getStartSha() != null && diffRef.getHeadSha() != null) {
String revisionId = diffRef.getStartSha();
return new GitLabEntityAccessContext() {
@Override
protected ProjectFileAccessProvider.FileAccessContext getFileAccessContext(ProjectFileAccessProvider projectFileAccessProvider) {
return projectFileAccessProvider.getFileAccessContext(projectId, null, null, null, revisionId);
}
@Override
protected String getInfoForException() {
return "review " + reviewId + " of project " + projectId;
}
};
} else {
throw new LegendSDLCServerException("Unable to get [from] revision info in project " + projectId + " for review " + reviewId);
}
}
use of org.gitlab4j.api.models.MergeRequest in project legend-sdlc by finos.
the class GitLabEntityApi method getReviewToEntityAccessContext.
public EntityAccessContext getReviewToEntityAccessContext(String projectId, String reviewId) {
LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null");
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi(gitLabProjectId.getGitLabMode()).getMergeRequestApi(), gitLabProjectId, reviewId);
validateMergeRequestForComparison(mergeRequest);
DiffRef diffRef = mergeRequest.getDiffRefs();
if (diffRef != null && diffRef.getStartSha() != null && diffRef.getHeadSha() != null) {
String revisionId = diffRef.getHeadSha();
return new GitLabEntityAccessContext() {
@Override
protected ProjectFileAccessProvider.FileAccessContext getFileAccessContext(ProjectFileAccessProvider projectFileAccessProvider) {
return projectFileAccessProvider.getFileAccessContext(projectId, null, null, null, revisionId);
}
@Override
protected String getInfoForException() {
return "review " + reviewId + " of project " + projectId;
}
};
} else {
throw new LegendSDLCServerException("Unable to get [to] revision info in project " + projectId + " for review " + reviewId);
}
}
use of org.gitlab4j.api.models.MergeRequest in project choerodon-starters by open-hand.
the class MergeRequestApi method acceptMergeRequest.
/**
* Merge changes to the merge request. If the MR has any conflicts and can not be merged,
* you'll get a 405 and the error message 'Branch cannot be merged'. If merge request is
* already merged or closed, you'll get a 406 and the error message 'Method Not Allowed'.
* If the sha parameter is passed and does not match the HEAD of the source, you'll get
* a 409 and the error message 'SHA does not match HEAD of source branch'. If you don't
* have permissions to accept this merge request, you'll get a 401.
* <p>
* PUT /projects/:id/merge_requests/:merge_request_iid/merge
*
* @param projectId the ID of a project
* @param mergeRequestId the internal ID of the merge request
* @param mergeCommitMessage, custom merge commit message, optional
* @param shouldRemoveSourceBranch, if true removes the source branch, optional
* @param mergeWhenPipelineSucceeds, if true the MR is merged when the pipeline, optional
* @return the merged merge request
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest acceptMergeRequest(Integer projectId, Integer mergeRequestId, String mergeCommitMessage, Boolean shouldRemoveSourceBranch, Boolean mergeWhenPipelineSucceeds) throws GitLabApiException {
if (projectId == null) {
throw new GitLabApiException("projectId cannot be null");
}
if (mergeRequestId == null) {
throw new GitLabApiException("mergeRequestId cannot be null");
}
Form formData = new GitLabApiForm().withParam("merge_commit_message", mergeCommitMessage).withParam("should_remove_source_branch", shouldRemoveSourceBranch).withParam("merge_when_pipeline_succeeds", mergeWhenPipelineSucceeds);
Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_requests", mergeRequestId, "merge");
return (response.readEntity(MergeRequest.class));
}
use of org.gitlab4j.api.models.MergeRequest in project choerodon-starters by open-hand.
the class MergeRequestApi method getMergeRequests.
/**
* Get all merge requests for the specified project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param state the state parameter can be used to get only merge requests with a given state (opened, closed, or merged) or all of them (all).
* @param page the page to get
* @param perPage the number of MergeRequest instances per page
* @return all merge requests for the specified project
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequest> getMergeRequests(Object projectIdOrPath, MergeRequestState state, int page, int perPage) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("state", state).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests");
return (response.readEntity(new GenericType<List<MergeRequest>>() {
}));
}
Aggregations