Search in sources :

Example 1 with DiffRef

use of org.gitlab4j.api.models.DiffRef in project legend-sdlc by finos.

the class GitLabProjectConfigurationApi method getReviewFromProjectConfiguration.

@Override
public ProjectConfiguration getReviewFromProjectConfiguration(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 getProjectRevisionProjectConfiguration(projectId, revisionId);
    } else {
        throw new LegendSDLCServerException("Unable to get [from] revision info in project " + projectId + " for review " + reviewId);
    }
}
Also used : 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 2 with DiffRef

use of org.gitlab4j.api.models.DiffRef 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 3 with DiffRef

use of org.gitlab4j.api.models.DiffRef 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 4 with DiffRef

use of org.gitlab4j.api.models.DiffRef 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 5 with DiffRef

use of org.gitlab4j.api.models.DiffRef in project legend-sdlc by finos.

the class GitLabProjectConfigurationApi method getReviewToProjectConfiguration.

@Override
public ProjectConfiguration getReviewToProjectConfiguration(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 getProjectRevisionProjectConfiguration(projectId, revisionId);
    } else {
        throw new LegendSDLCServerException("Unable to get [to] revision info in project " + projectId + " for review " + reviewId);
    }
}
Also used : 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)

Aggregations

LegendSDLCServerException (org.finos.legend.sdlc.server.error.LegendSDLCServerException)7 DiffRef (org.gitlab4j.api.models.DiffRef)7 GitLabProjectId (org.finos.legend.sdlc.server.gitlab.GitLabProjectId)6 MergeRequest (org.gitlab4j.api.models.MergeRequest)6 RepositoryApi (org.gitlab4j.api.RepositoryApi)3 ProjectFileAccessProvider (org.finos.legend.sdlc.server.project.ProjectFileAccessProvider)2 ProjectStructure (org.finos.legend.sdlc.server.project.ProjectStructure)2 GitLabApiException (org.gitlab4j.api.GitLabApiException)1 Commit (org.gitlab4j.api.models.Commit)1