use of org.gitlab4j.api.MergeRequestApi in project legend-sdlc by finos.
the class GitLabReviewApi method revokeReviewApproval.
@Override
public Review revokeReviewApproval(String projectId, String reviewId) {
LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null");
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
MergeRequestApi mergeRequestApi = getGitLabApi(gitLabProjectId.getGitLabMode()).getMergeRequestApi();
MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, reviewId);
try {
MergeRequest revokeApprovalMergeRequest = mergeRequestApi.unapproveMergeRequest(gitLabProjectId.getGitLabId(), mergeRequest.getIid());
// The MergeRequest that comes back from the unapproveMergeRequest call is not adequate
// for creating a Review, as most relevant properties are null. The only useful thing we
// get from it is the last update time.
mergeRequest.setUpdatedAt(revokeApprovalMergeRequest.getUpdatedAt());
return fromGitLabMergeRequest(projectId, mergeRequest);
} catch (Exception e) {
throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to revoke approval of review " + reviewId + " in project " + projectId, () -> "Unknown review in project " + projectId + ": " + reviewId, () -> "Error revoking review approval " + reviewId + " in project " + projectId);
}
}
use of org.gitlab4j.api.MergeRequestApi in project legend-sdlc by finos.
the class GitLabReviewApi method editReview.
@Override
public Review editReview(String projectId, String reviewId, String title, String description, List<String> labels) {
LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null");
LegendSDLCServerException.validateNonNull(title, "title may not be null");
LegendSDLCServerException.validateNonNull(description, "description may not be null");
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
GitLabApi gitLabApi = getGitLabApi(gitLabProjectId.getGitLabMode());
MergeRequestApi mergeRequestApi = gitLabApi.getMergeRequestApi();
MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, reviewId);
if (!isOpen(mergeRequest)) {
throw new LegendSDLCServerException("Only open reviews can be edited: state of review " + mergeRequest.getIid() + " in project " + gitLabProjectId.toString() + " is " + getReviewState(mergeRequest));
}
try {
MergeRequestParams mergeRequestParams = new MergeRequestParams().withTitle(title).withDescription(description);
if (labels != null) {
mergeRequestParams.withLabels(labels);
}
MergeRequest editedRequest = mergeRequestApi.updateMergeRequest(gitLabProjectId.getGitLabId(), mergeRequest.getIid(), mergeRequestParams);
return fromGitLabMergeRequest(projectId, editedRequest);
} catch (Exception e) {
throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to edit review " + reviewId + " in project " + projectId, () -> "Unknown review in project " + projectId + ": " + reviewId, () -> "Error editing review " + reviewId + " in project " + projectId);
}
}
use of org.gitlab4j.api.MergeRequestApi in project legend-sdlc by finos.
the class GitLabReviewApi method closeReview.
@Override
public Review closeReview(String projectId, String reviewId) {
LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null");
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
MergeRequestApi mergeRequestApi = getGitLabApi(gitLabProjectId.getGitLabMode()).getMergeRequestApi();
MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, reviewId);
validateMergeRequestReviewState(mergeRequest, ReviewState.OPEN);
try {
MergeRequest closeMergeRequest = updateMergeRequestState(mergeRequestApi, gitLabProjectId, mergeRequest, StateEvent.CLOSE);
return fromGitLabMergeRequest(projectId, closeMergeRequest);
} catch (Exception e) {
throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to close review " + reviewId + " in project " + projectId, () -> "Unknown review in project " + projectId + ": " + reviewId, () -> "Error closing review " + reviewId + " in project " + projectId);
}
}
use of org.gitlab4j.api.MergeRequestApi in project legend-sdlc by finos.
the class GitlabWorkflowApi method getReviewWorkflowAccessContext.
@Override
public WorkflowAccessContext getReviewWorkflowAccessContext(String projectId, String reviewId) {
LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null");
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
MergeRequestApi mergeRequestApi = getGitLabApi(gitLabProjectId.getGitLabMode()).getMergeRequestApi();
MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, reviewId, true);
WorkspaceInfo workspaceInfo = parseWorkspaceBranchName(mergeRequest.getSourceBranch());
if (workspaceInfo == null) {
throw new LegendSDLCServerException("Unknown review in project " + projectId + ": " + reviewId, Response.Status.NOT_FOUND);
}
return new GitLabWorkflowAccessContext(gitLabProjectId) {
@Override
protected String getRef() {
return "refs/merge-requests/" + reviewId + "/head";
}
@Override
protected String getRefInfoForException() {
return "review " + reviewId + " of project " + projectId;
}
@Override
protected ProjectFileAccessProvider.RevisionAccessContext getRevisionAccessContext() {
return getProjectFileAccessProvider().getWorkspaceRevisionAccessContext(projectId, workspaceInfo.getWorkspaceId(), workspaceInfo.getWorkspaceType(), workspaceInfo.getWorkspaceAccessType());
}
};
}
Aggregations