use of org.gitlab4j.api.models.MergeRequestFilter in project legend-sdlc by finos.
the class GitLabReviewApi method getReviews.
@Override
public List<Review> getReviews(Set<ProjectType> projectTypes, boolean assignedToMe, boolean authoredByMe, List<String> labels, ReviewState state, Instant since, Instant until, Integer limit) {
if (assignedToMe && authoredByMe) {
throw new LegendSDLCServerException("assignedToMe and authoredByMe may not both be true", Status.BAD_REQUEST);
}
Set<GitLabMode> modes = EnumSet.noneOf(GitLabMode.class);
if (projectTypes == null || projectTypes.isEmpty()) {
getValidGitLabModes().forEach(modes::add);
} else {
projectTypes.forEach(a -> modes.add(getGitLabModeFromProjectType(a)));
}
MergeRequestFilter mergeRequestFilter = withMergeRequestLabels(withMergeRequestFilters(new MergeRequestFilter(), state, since, until).withScope(assignedToMe ? MergeRequestScope.ASSIGNED_TO_ME : (authoredByMe ? MergeRequestScope.CREATED_BY_ME : MergeRequestScope.ALL)), labels);
return addReviewFilters(modes.stream().flatMap(mode -> getReviewStream(mode, mergeRequestFilter)), state, since, until, limit).collect(Collectors.toList());
}
use of org.gitlab4j.api.models.MergeRequestFilter in project legend-sdlc by finos.
the class GitLabReviewApi method getReviews.
@Override
public List<Review> getReviews(String projectId, ReviewState state, Iterable<String> revisionIds, Instant since, Instant until, Integer limit) {
LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
Set<String> revisionIdSet;
if (revisionIds == null) {
revisionIdSet = Collections.emptySet();
} else if (revisionIds instanceof Set) {
revisionIdSet = (Set<String>) revisionIds;
} else {
revisionIdSet = Sets.mutable.withAll(revisionIds);
}
Stream<MergeRequest> mergeRequestStream;
try {
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
if (!revisionIdSet.isEmpty()) {
// TODO: we might want to do this differently since the number of revision IDs can be huge
// we can have a threshold for which we change our strategy to to make a single call for
// merge requests by the other criteria and then filter by revisionIds.
MutableIntSet mergeRequestIds = IntSets.mutable.empty();
CommitsApi commitsApi = getGitLabApi(gitLabProjectId.getGitLabMode()).getCommitsApi();
// Combine all MRs associated with each revision
mergeRequestStream = revisionIdSet.stream().flatMap(revisionId -> {
try {
return PagerTools.stream(withRetries(() -> commitsApi.getMergeRequests(gitLabProjectId.getGitLabId(), revisionId, ITEMS_PER_PAGE)));
} catch (Exception e) {
throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to get reviews associated with revision " + revisionId + " for project " + projectId, () -> "Unknown revision (" + revisionId + ") or project (" + projectId + ")", () -> "Error getting reviews associated with revision " + revisionId + " for project " + projectId);
}
}).filter(// remove duplicates
mr -> (mr.getIid() != null) && mergeRequestIds.add(mr.getIid()));
MergeRequestState mergeRequestState = getMergeRequestState(state);
if (mergeRequestState != MergeRequestState.ALL) {
String mergeRequestStateString = mergeRequestState.toString();
mergeRequestStream = mergeRequestStream.filter(mr -> mergeRequestStateString.equalsIgnoreCase(mr.getState()));
}
} else {
// if no revision ID is specified we will use the default merge request API from Gitlab to take advantage of the filter
MergeRequestFilter mergeRequestFilter = withMergeRequestFilters(new MergeRequestFilter(), state, since, until).withProjectId(gitLabProjectId.getGitLabId());
mergeRequestStream = PagerTools.stream(withRetries(() -> getGitLabApi(gitLabProjectId.getGitLabMode()).getMergeRequestApi().getMergeRequests(mergeRequestFilter, ITEMS_PER_PAGE)));
}
Stream<Review> stream = mergeRequestStream.filter(BaseGitLabApi::isReviewMergeRequest).map(mr -> fromGitLabMergeRequest(projectId, mr));
return addReviewFilters(stream, state, since, until, limit).collect(Collectors.toList());
} catch (Exception e) {
throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to get reviews for project " + projectId + ((state == null) ? "" : (" with state " + state)), () -> "Unknown project (" + projectId + ")", () -> "Error getting reviews for project " + projectId + ((state == null) ? "" : (" with state " + state)));
}
}
Aggregations