Search in sources :

Example 1 with MergeRequestParams

use of org.gitlab4j.api.models.MergeRequestParams 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);
    }
}
Also used : GitLabApi(org.gitlab4j.api.GitLabApi) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) MergeRequest(org.gitlab4j.api.models.MergeRequest) MergeRequestParams(org.gitlab4j.api.models.MergeRequestParams) GitLabProjectId(org.finos.legend.sdlc.server.gitlab.GitLabProjectId) MergeRequestApi(org.gitlab4j.api.MergeRequestApi) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) GitLabApiException(org.gitlab4j.api.GitLabApiException)

Aggregations

LegendSDLCServerException (org.finos.legend.sdlc.server.error.LegendSDLCServerException)1 GitLabProjectId (org.finos.legend.sdlc.server.gitlab.GitLabProjectId)1 GitLabApi (org.gitlab4j.api.GitLabApi)1 GitLabApiException (org.gitlab4j.api.GitLabApiException)1 MergeRequestApi (org.gitlab4j.api.MergeRequestApi)1 MergeRequest (org.gitlab4j.api.models.MergeRequest)1 MergeRequestParams (org.gitlab4j.api.models.MergeRequestParams)1