use of com.meisolsson.githubsdk.model.ReviewComment 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.model.ReviewComment in project gh4a by slapperwan.
the class PullRequestFragment method editComment.
@Override
public void editComment(GitHubCommentBase comment) {
@AttrRes final int highlightColorAttr = mPullRequest.merged() ? R.attr.colorPullRequestMerged : mPullRequest.state() == IssueState.Closed ? R.attr.colorIssueClosed : R.attr.colorIssueOpen;
Intent intent = comment instanceof ReviewComment ? EditPullRequestCommentActivity.makeIntent(getActivity(), mRepoOwner, mRepoName, mPullRequest.number(), comment.id(), 0L, comment.body(), highlightColorAttr) : EditIssueCommentActivity.makeIntent(getActivity(), mRepoOwner, mRepoName, mIssue.number(), comment.id(), comment.body(), highlightColorAttr);
startActivityForResult(intent, REQUEST_EDIT);
}
use of com.meisolsson.githubsdk.model.ReviewComment in project gh4a by slapperwan.
the class EventListFragment method onItemClick.
@Override
public void onItemClick(GitHubEvent event) {
if (EventAdapter.hasInvalidPayload(event)) {
return;
}
GitHubEvent.RepoIdentifier eventRepo = event.repo();
String repoOwner = "";
String repoName = "";
Intent intent = null;
Single<Optional<Intent>> intentSingle = null;
if (eventRepo != null) {
String[] repoNamePart = eventRepo.repoWithUserName().split("/");
if (repoNamePart.length == 2) {
repoOwner = repoNamePart[0];
repoName = repoNamePart[1];
}
}
if (Arrays.binarySearch(REPO_EVENTS, event.type()) >= 0 && eventRepo == null) {
Toast.makeText(getActivity(), R.string.repo_not_found_toast, Toast.LENGTH_LONG).show();
return;
}
switch(event.type()) {
case CommitCommentEvent:
{
CommitCommentPayload payload = (CommitCommentPayload) event.payload();
GitComment comment = payload.comment();
if (comment != null) {
intentSingle = CommitCommentLoadTask.load(getActivity(), repoOwner, repoName, comment.commitId(), new IntentUtils.InitialCommentMarker(comment.id()));
}
break;
}
case CreateEvent:
{
CreatePayload payload = (CreatePayload) event.payload();
String ref = null;
if (payload.refType() == ReferenceType.Branch || payload.refType() == ReferenceType.Tag) {
ref = payload.ref();
}
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName, ref);
break;
}
case DeleteEvent:
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
break;
case DownloadEvent:
{
DownloadPayload payload = (DownloadPayload) event.payload();
Download download = payload.download();
UiUtils.enqueueDownloadWithPermissionCheck((BaseActivity) getActivity(), download.htmlUrl(), download.contentType(), download.name(), download.description(), null);
break;
}
case FollowEvent:
{
FollowPayload payload = (FollowPayload) event.payload();
intent = UserActivity.makeIntent(getActivity(), payload.target());
break;
}
case ForkEvent:
{
ForkPayload payload = (ForkPayload) event.payload();
Repository forkee = payload.forkee();
if (forkee != null) {
intent = RepositoryActivity.makeIntent(getActivity(), forkee);
} else {
Toast.makeText(getActivity(), R.string.repo_not_found_toast, Toast.LENGTH_LONG).show();
}
break;
}
case ForkApplyEvent:
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
break;
case GistEvent:
{
GistPayload payload = (GistPayload) event.payload();
intent = GistActivity.makeIntent(getActivity(), payload.gist().id());
break;
}
case GollumEvent:
{
GollumPayload payload = (GollumPayload) event.payload();
intent = WikiListActivity.makeIntent(getActivity(), repoOwner, repoName, payload.pages().isEmpty() ? null : payload.pages().get(0));
break;
}
case IssueCommentEvent:
{
IssueCommentPayload payload = (IssueCommentPayload) event.payload();
Issue issue = payload.issue();
PullRequest request = issue != null ? issue.pullRequest() : null;
IntentUtils.InitialCommentMarker initialComment = payload.comment() != null ? new IntentUtils.InitialCommentMarker(payload.comment().id()) : null;
if (request != null && request.htmlUrl() != null) {
intent = PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, issue.number(), initialComment != null ? PullRequestActivity.PAGE_CONVERSATION : -1, initialComment);
} else if (issue != null) {
intent = IssueActivity.makeIntent(getActivity(), repoOwner, repoName, issue.number(), initialComment);
}
break;
}
case IssuesEvent:
{
IssuesPayload payload = (IssuesPayload) event.payload();
startActivity(IssueActivity.makeIntent(getActivity(), repoOwner, repoName, payload.issue().number()));
break;
}
case MemberEvent:
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
break;
case PublicEvent:
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
break;
case PullRequestEvent:
{
PullRequestPayload payload = (PullRequestPayload) event.payload();
intent = PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, payload.number());
break;
}
case PullRequestReviewCommentEvent:
{
PullRequestReviewCommentPayload payload = (PullRequestReviewCommentPayload) event.payload();
PullRequest pr = payload.pullRequest();
ReviewComment comment = payload.comment();
IntentUtils.InitialCommentMarker initialComment = comment != null ? new IntentUtils.InitialCommentMarker(comment.id()) : null;
if (pr != null) {
if (initialComment != null) {
intentSingle = PullRequestReviewCommentLoadTask.load(getActivity(), repoOwner, repoName, pr.number(), initialComment);
} else {
intent = PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, pr.number(), -1, null);
}
} else if (comment != null) {
intent = CommitActivity.makeIntent(getActivity(), repoOwner, repoName, comment.commitId(), initialComment);
}
break;
}
case PushEvent:
{
PushPayload payload = (PushPayload) event.payload();
List<GitCommit> commits = payload.commits();
if (commits != null && !commits.isEmpty()) {
if (commits.size() > 1) {
// if commit > 1, then show compare activity
intent = CompareActivity.makeIntent(getActivity(), repoOwner, repoName, payload.before(), payload.head());
} else {
// only 1 commit, then show the commit details
intent = CommitActivity.makeIntent(getActivity(), repoOwner, repoName, commits.get(0).sha());
}
} else {
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
}
break;
}
case ReleaseEvent:
{
ReleasePayload payload = (ReleasePayload) event.payload();
Release release = payload.release();
if (release != null) {
intent = ReleaseInfoActivity.makeIntent(getActivity(), repoOwner, repoName, release.id());
}
break;
}
case WatchEvent:
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
break;
}
if (intent != null) {
startActivity(intent);
} else if (intentSingle != null) {
intentSingle.compose(RxUtils::doInBackground).compose(RxUtils.wrapWithProgressDialog(getActivity(), R.string.loading_msg)).subscribe(result -> {
if (result.isPresent() && isAdded()) {
startActivity(result.get());
}
}, error -> Log.d(Gh4Application.LOG_TAG, "Loading click intent failed", error));
}
}
use of com.meisolsson.githubsdk.model.ReviewComment 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());
});
}
use of com.meisolsson.githubsdk.model.ReviewComment 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