Search in sources :

Example 6 with PullRequestReviewService

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)));
}
Also used : Context(android.content.Context) ReviewActivity(com.gh4a.activities.ReviewActivity) Review(com.meisolsson.githubsdk.model.Review) PullRequestReviewService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewService) ApiHelpers(com.gh4a.utils.ApiHelpers) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) Intent(android.content.Intent) HashMap(java.util.HashMap) Single(io.reactivex.Single) PullRequestReviewCommentService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService) VisibleForTesting(android.support.annotation.VisibleForTesting) RxUtils(com.gh4a.utils.RxUtils) FragmentActivity(android.support.v4.app.FragmentActivity) Optional(com.gh4a.utils.Optional) Map(java.util.Map) TimelineItem(com.gh4a.model.TimelineItem) ServiceFactory(com.gh4a.ServiceFactory) IntentUtils(com.gh4a.utils.IntentUtils) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) ApiHelpers(com.gh4a.utils.ApiHelpers) Review(com.meisolsson.githubsdk.model.Review) HashMap(java.util.HashMap) Map(java.util.Map) PullRequestReviewService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewService) PullRequestReviewCommentService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService)

Aggregations

ApiHelpers (com.gh4a.utils.ApiHelpers)6 PullRequestReviewService (com.meisolsson.githubsdk.service.pull_request.PullRequestReviewService)6 Intent (android.content.Intent)5 ServiceFactory (com.gh4a.ServiceFactory)5 IntentUtils (com.gh4a.utils.IntentUtils)5 RxUtils (com.gh4a.utils.RxUtils)5 Single (io.reactivex.Single)5 Optional (com.gh4a.utils.Optional)4 Bundle (android.os.Bundle)3 AlertDialog (android.support.v7.app.AlertDialog)3 View (android.view.View)3 R (com.gh4a.R)3 TimelineItem (com.gh4a.model.TimelineItem)3 Review (com.meisolsson.githubsdk.model.Review)3 ReviewComment (com.meisolsson.githubsdk.model.ReviewComment)3 PullRequestReviewCommentService (com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService)3 HashMap (java.util.HashMap)3 Activity (android.app.Activity)2 Context (android.content.Context)2 Nullable (android.support.annotation.Nullable)2