use of com.meisolsson.githubsdk.service.pull_request.PullRequestReviewService in project gh4a by slapperwan.
the class PullRequestReviewCommentLoadTask method load.
public static Single<Optional<Intent>> load(Context context, String repoOwner, String repoName, int pullRequestNumber, IntentUtils.InitialCommentMarker marker) {
final PullRequestReviewService reviewService = ServiceFactory.get(PullRequestReviewService.class, false);
final PullRequestReviewCommentService commentService = ServiceFactory.get(PullRequestReviewCommentService.class, false);
return ApiHelpers.PageIterator.toSingle(page -> commentService.getPullRequestComments(repoOwner, repoName, pullRequestNumber, page)).compose(RxUtils.sortList(ApiHelpers.COMMENT_COMPARATOR)).flatMap(comments -> {
Map<String, ReviewComment> commentsByDiffHunkId = new HashMap<>();
for (ReviewComment comment : comments) {
String id = TimelineItem.Diff.getDiffHunkId(comment);
if (!commentsByDiffHunkId.containsKey(id)) {
// Because the comment we are looking for could be a reply to another
// review we have to keep track of initial comments for each diff hunk
commentsByDiffHunkId.put(id, comment);
}
if (marker.matches(comment.id(), null)) {
// Once found the comment we are looking for get a correct review id from
// the initial diff hunk comment
ReviewComment initialComment = commentsByDiffHunkId.get(id);
long reviewId = initialComment.pullRequestReviewId();
return reviewService.getReview(repoOwner, repoName, pullRequestNumber, reviewId).map(ApiHelpers::throwOnFailure).map(Optional::of);
}
}
return Single.just(Optional.<Review>absent());
}).map(reviewOpt -> reviewOpt.map(review -> ReviewActivity.makeIntent(context, repoOwner, repoName, pullRequestNumber, review, marker)));
}
Aggregations