Search in sources :

Example 11 with MergeRequest

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);
}
Also used : LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) MergeRequest(org.gitlab4j.api.models.MergeRequest) GitLabProjectId(org.finos.legend.sdlc.server.gitlab.GitLabProjectId) RepositoryApi(org.gitlab4j.api.RepositoryApi) ProjectStructure(org.finos.legend.sdlc.server.project.ProjectStructure) DiffRef(org.gitlab4j.api.models.DiffRef)

Example 12 with MergeRequest

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);
    }
}
Also used : ProjectFileAccessProvider(org.finos.legend.sdlc.server.project.ProjectFileAccessProvider) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) MergeRequest(org.gitlab4j.api.models.MergeRequest) GitLabProjectId(org.finos.legend.sdlc.server.gitlab.GitLabProjectId) DiffRef(org.gitlab4j.api.models.DiffRef)

Example 13 with MergeRequest

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);
    }
}
Also used : ProjectFileAccessProvider(org.finos.legend.sdlc.server.project.ProjectFileAccessProvider) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) MergeRequest(org.gitlab4j.api.models.MergeRequest) GitLabProjectId(org.finos.legend.sdlc.server.gitlab.GitLabProjectId) DiffRef(org.gitlab4j.api.models.DiffRef)

Example 14 with MergeRequest

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));
}
Also used : Response(javax.ws.rs.core.Response) MergeRequest(org.gitlab4j.api.models.MergeRequest) Form(javax.ws.rs.core.Form)

Example 15 with MergeRequest

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>>() {
    }));
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) MergeRequest(org.gitlab4j.api.models.MergeRequest) Form(javax.ws.rs.core.Form)

Aggregations

MergeRequest (org.gitlab4j.api.models.MergeRequest)32 GitLabProjectId (org.finos.legend.sdlc.server.gitlab.GitLabProjectId)25 LegendSDLCServerException (org.finos.legend.sdlc.server.error.LegendSDLCServerException)22 GitLabApiException (org.gitlab4j.api.GitLabApiException)17 MergeRequestApi (org.gitlab4j.api.MergeRequestApi)15 RepositoryApi (org.gitlab4j.api.RepositoryApi)9 ProjectFileAccessProvider (org.finos.legend.sdlc.server.project.ProjectFileAccessProvider)7 DiffRef (org.gitlab4j.api.models.DiffRef)7 Response (javax.ws.rs.core.Response)6 GitLabApi (org.gitlab4j.api.GitLabApi)6 List (java.util.List)5 Form (javax.ws.rs.core.Form)5 Project (org.finos.legend.sdlc.domain.model.project.Project)5 ProjectType (org.finos.legend.sdlc.domain.model.project.ProjectType)5 Review (org.finos.legend.sdlc.domain.model.review.Review)5 Entity (org.finos.legend.sdlc.domain.model.entity.Entity)4 Workspace (org.finos.legend.sdlc.domain.model.project.workspace.Workspace)4 ProjectStructure (org.finos.legend.sdlc.server.project.ProjectStructure)2 Branch (org.gitlab4j.api.models.Branch)2 MergeRequestParams (org.gitlab4j.api.models.MergeRequestParams)2