use of com.meisolsson.githubsdk.service.pull_request.PullRequestService in project gh4a by slapperwan.
the class PullRequestActivity method updatePullRequestState.
private void updatePullRequestState(boolean open) {
@StringRes int dialogMessageResId = open ? R.string.opening_msg : R.string.closing_msg;
@StringRes int errorMessageResId = open ? R.string.issue_error_reopen : R.string.issue_error_close;
String errorMessage = getString(errorMessageResId, mPullRequest.number());
PullRequestService service = ServiceFactory.get(PullRequestService.class, false);
EditPullRequest request = EditPullRequest.builder().state(open ? ApiHelpers.IssueState.OPEN : ApiHelpers.IssueState.CLOSED).build();
service.editPullRequest(mRepoOwner, mRepoName, mPullRequestNumber, request).map(ApiHelpers::throwOnFailure).compose(RxUtils.wrapForBackgroundTask(this, dialogMessageResId, errorMessage)).subscribe(result -> {
mPullRequest = result;
handlePullRequestUpdate();
}, error -> handleActionFailure("Updating pull request failed", error));
}
use of com.meisolsson.githubsdk.service.pull_request.PullRequestService in project gh4a by slapperwan.
the class PullRequestFilesFragment method loadFiles.
private void loadFiles(boolean force) {
final PullRequestService service = ServiceFactory.get(PullRequestService.class, force);
ApiHelpers.PageIterator.toSingle(page -> service.getPullRequestFiles(mRepoOwner, mRepoName, mPullRequestNumber, page)).compose(makeLoaderSingle(ID_LOADER_FILES, force)).subscribe(result -> {
mFiles = result;
populateUiIfReady();
}, this::handleLoadFailure);
}
use of com.meisolsson.githubsdk.service.pull_request.PullRequestService in project gh4a by slapperwan.
the class ReviewFragment method onCreateDataSingle.
@Override
protected Single<List<TimelineItem>> onCreateDataSingle(boolean bypassCache) {
final PullRequestService prService = ServiceFactory.get(PullRequestService.class, bypassCache);
final PullRequestReviewService reviewService = ServiceFactory.get(PullRequestReviewService.class, bypassCache);
final PullRequestReviewCommentService commentService = ServiceFactory.get(PullRequestReviewCommentService.class, bypassCache);
Single<TimelineItem.TimelineReview> reviewItemSingle = reviewService.getReview(mRepoOwner, mRepoName, mIssueNumber, mReview.id()).map(ApiHelpers::throwOnFailure).map(TimelineItem.TimelineReview::new);
Single<List<ReviewComment>> reviewCommentsSingle = ApiHelpers.PageIterator.toSingle(page -> reviewService.getReviewComments(mRepoOwner, mRepoName, mIssueNumber, mReview.id())).compose(RxUtils.sortList(ApiHelpers.COMMENT_COMPARATOR)).cache();
Single<Boolean> hasCommentsSingle = reviewCommentsSingle.map(comments -> !comments.isEmpty());
Single<Optional<List<GitHubFile>>> filesSingle = hasCommentsSingle.flatMap(hasComments -> {
if (!hasComments) {
return Single.just(Optional.absent());
}
return ApiHelpers.PageIterator.toSingle(page -> prService.getPullRequestFiles(mRepoOwner, mRepoName, mIssueNumber, page)).map(Optional::of);
});
Single<Optional<List<ReviewComment>>> commentsSingle = hasCommentsSingle.flatMap(hasComments -> {
if (!hasComments) {
return Single.just(Optional.absent());
}
return ApiHelpers.PageIterator.toSingle(page -> commentService.getPullRequestComments(mRepoOwner, mRepoName, mIssueNumber, page)).compose(RxUtils.sortList(ApiHelpers.COMMENT_COMPARATOR)).map(Optional::of);
});
return Single.zip(reviewItemSingle, reviewCommentsSingle, filesSingle, commentsSingle, (reviewItem, reviewComments, filesOpt, commentsOpt) -> {
if (!reviewComments.isEmpty()) {
HashMap<String, GitHubFile> filesByName = new HashMap<>();
if (filesOpt.isPresent()) {
for (GitHubFile file : filesOpt.get()) {
filesByName.put(file.filename(), file);
}
}
// Add all of the review comments to the review item creating necessary diff hunks
for (ReviewComment reviewComment : reviewComments) {
GitHubFile file = filesByName.get(reviewComment.path());
reviewItem.addComment(reviewComment, file, true);
}
if (commentsOpt.isPresent()) {
for (ReviewComment commitComment : commentsOpt.get()) {
if (reviewComments.contains(commitComment)) {
continue;
}
// Rest of the comments should be added only if they are under the same
// diff hunks as the original review comments.
GitHubFile file = filesByName.get(commitComment.path());
reviewItem.addComment(commitComment, file, false);
}
}
}
List<TimelineItem> items = new ArrayList<>();
items.add(reviewItem);
List<TimelineItem.Diff> diffHunks = new ArrayList<>(reviewItem.getDiffHunks());
Collections.sort(diffHunks);
for (TimelineItem.Diff diffHunk : diffHunks) {
items.add(diffHunk);
items.addAll(diffHunk.comments);
if (!diffHunk.isReply()) {
items.add(new TimelineItem.Reply(diffHunk.getInitialTimelineComment()));
}
}
return items;
});
}
use of com.meisolsson.githubsdk.service.pull_request.PullRequestService in project gh4a by slapperwan.
the class PullRequestFragment method onCreateDataSingle.
@Override
protected Single<List<TimelineItem>> onCreateDataSingle(boolean bypassCache) {
final int issueNumber = mIssue.number();
final IssueEventService eventService = ServiceFactory.get(IssueEventService.class, bypassCache);
final IssueCommentService commentService = ServiceFactory.get(IssueCommentService.class, bypassCache);
final PullRequestService prService = ServiceFactory.get(PullRequestService.class, bypassCache);
final PullRequestReviewService reviewService = ServiceFactory.get(PullRequestReviewService.class, bypassCache);
final PullRequestReviewCommentService prCommentService = ServiceFactory.get(PullRequestReviewCommentService.class, bypassCache);
Single<List<TimelineItem>> issueCommentItemSingle = ApiHelpers.PageIterator.toSingle(page -> commentService.getIssueComments(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.mapList(TimelineItem.TimelineComment::new));
Single<List<TimelineItem>> eventItemSingle = ApiHelpers.PageIterator.toSingle(page -> eventService.getIssueEvents(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.filter(event -> INTERESTING_EVENTS.contains(event.event()))).compose((RxUtils.mapList(TimelineItem.TimelineEvent::new)));
Single<Map<String, GitHubFile>> filesByNameSingle = ApiHelpers.PageIterator.toSingle(page -> prService.getPullRequestFiles(mRepoOwner, mRepoName, issueNumber, page)).map(files -> {
Map<String, GitHubFile> filesByName = new HashMap<>();
for (GitHubFile file : files) {
filesByName.put(file.filename(), file);
}
return filesByName;
}).cache();
Single<List<Review>> reviewSingle = ApiHelpers.PageIterator.toSingle(page -> reviewService.getReviews(mRepoOwner, mRepoName, issueNumber, page)).cache();
Single<List<ReviewComment>> prCommentSingle = ApiHelpers.PageIterator.toSingle(page -> prCommentService.getPullRequestComments(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.sortList(ApiHelpers.COMMENT_COMPARATOR)).cache();
Single<LongSparseArray<List<ReviewComment>>> reviewCommentsByIdSingle = reviewSingle.compose(RxUtils.filter(r -> r.state() == ReviewState.Pending)).toObservable().flatMap(reviews -> {
List<Observable<Pair<Long, List<ReviewComment>>>> obsList = new ArrayList<>();
for (Review r : reviews) {
Single<List<ReviewComment>> single = ApiHelpers.PageIterator.toSingle(page -> reviewService.getReviewComments(mRepoOwner, mRepoName, issueNumber, r.id()));
obsList.add(Single.zip(Single.just(r.id()), single, Pair::create).toObservable());
}
return Observable.concat(obsList);
}).toList().map(list -> {
LongSparseArray<List<ReviewComment>> result = new LongSparseArray<>();
for (Pair<Long, List<ReviewComment>> pair : list) {
result.put(pair.first, pair.second);
}
return result;
});
Single<List<TimelineItem.TimelineReview>> reviewTimelineSingle = Single.zip(reviewSingle, filesByNameSingle, prCommentSingle, reviewCommentsByIdSingle, (prReviews, filesByName, commitComments, pendingCommentsById) -> {
LongSparseArray<TimelineItem.TimelineReview> reviewsById = new LongSparseArray<>();
List<TimelineItem.TimelineReview> reviews = new ArrayList<>();
for (Review review : prReviews) {
TimelineItem.TimelineReview timelineReview = new TimelineItem.TimelineReview(review);
reviewsById.put(review.id(), timelineReview);
reviews.add(timelineReview);
if (review.state() == ReviewState.Pending) {
for (ReviewComment pendingComment : pendingCommentsById.get(review.id())) {
GitHubFile commitFile = filesByName.get(pendingComment.path());
timelineReview.addComment(pendingComment, commitFile, true);
}
}
}
Map<String, TimelineItem.TimelineReview> reviewsBySpecialId = new HashMap<>();
for (ReviewComment commitComment : commitComments) {
GitHubFile file = filesByName.get(commitComment.path());
if (commitComment.pullRequestReviewId() != null) {
String id = TimelineItem.Diff.getDiffHunkId(commitComment);
TimelineItem.TimelineReview review = reviewsBySpecialId.get(id);
if (review == null) {
review = reviewsById.get(commitComment.pullRequestReviewId());
reviewsBySpecialId.put(id, review);
}
review.addComment(commitComment, file, true);
}
}
return reviews;
}).compose(RxUtils.filter(item -> {
// noinspection CodeBlock2Expr
return item.review().state() != ReviewState.Commented || !TextUtils.isEmpty(item.review().body()) || !item.getDiffHunks().isEmpty();
}));
Single<List<TimelineItem.TimelineComment>> commitCommentWithoutReviewSingle = Single.zip(prCommentSingle.compose(RxUtils.filter(comment -> comment.pullRequestReviewId() == 0)), filesByNameSingle, (comments, files) -> {
List<TimelineItem.TimelineComment> items = new ArrayList<>();
for (ReviewComment comment : comments) {
items.add(new TimelineItem.TimelineComment(comment, files.get(comment.path())));
}
return items;
});
return Single.zip(issueCommentItemSingle, eventItemSingle, reviewTimelineSingle, commitCommentWithoutReviewSingle, (comments, events, reviewItems, commentsWithoutReview) -> {
ArrayList<TimelineItem> result = new ArrayList<>();
result.addAll(comments);
result.addAll(events);
result.addAll(reviewItems);
result.addAll(commentsWithoutReview);
Collections.sort(result, TimelineItem.COMPARATOR);
return result;
});
}
use of com.meisolsson.githubsdk.service.pull_request.PullRequestService in project gh4a by slapperwan.
the class PullRequestDiffCommentLoadTask method getSingle.
@Override
protected Single<Optional<Intent>> getSingle() {
PullRequestService service = ServiceFactory.get(PullRequestService.class, false);
Single<PullRequest> pullRequestSingle = service.getPullRequest(mRepoOwner, mRepoName, mPullRequestNumber).map(ApiHelpers::throwOnFailure);
final PullRequestReviewCommentService commentService = ServiceFactory.get(PullRequestReviewCommentService.class, false);
Single<List<ReviewComment>> commentsSingle = ApiHelpers.PageIterator.toSingle(page -> commentService.getPullRequestComments(mRepoOwner, mRepoName, mPullRequestNumber, page)).compose(RxUtils.filter(c -> c.position() != null)).cache();
Single<List<GitHubFile>> filesSingle = ApiHelpers.PageIterator.toSingle(page -> service.getPullRequestFiles(mRepoOwner, mRepoName, mPullRequestNumber, page));
return commentsSingle.compose(RxUtils.filterAndMapToFirst(c -> mMarker.matches(c.id(), c.createdAt()))).zipWith(filesSingle, (commentOpt, files) -> commentOpt.map(comment -> {
for (GitHubFile commitFile : files) {
if (commitFile.filename().equals(comment.path())) {
return Pair.create(true, commitFile);
}
}
return Pair.create(comment != null, (GitHubFile) null);
})).flatMap(result -> {
if (result.isPresent()) {
boolean foundComment = result.get().first;
GitHubFile file = result.get().second;
if (foundComment && file != null && !FileUtils.isImage(file.filename())) {
return Single.zip(pullRequestSingle, commentsSingle, (pr, comments) -> {
// noinspection CodeBlock2Expr
return Optional.of(PullRequestDiffViewerActivity.makeIntent(mActivity, mRepoOwner, mRepoName, mPullRequestNumber, pr.head().sha(), file.filename(), file.patch(), comments, -1, -1, -1, false, mMarker));
});
}
if (foundComment && file == null) {
return Single.just(Optional.of(PullRequestActivity.makeIntent(mActivity, mRepoOwner, mRepoName, mPullRequestNumber, mPage, mMarker)));
}
}
return Single.just(Optional.absent());
});
}
Aggregations