/// <summary> /// Initializes a new instance of the <see cref="PullRequestReviewCommentViewModel"/> class. /// </summary> /// <param name="session">The pull request session.</param> /// <param name="thread">The thread that the comment is a part of.</param> /// <param name="currentUser">The current user.</param> /// <param name="commentId">The REST ID of the comment.</param> /// <param name="commentNodeId">The GraphQL ID of the comment.</param> /// <param name="body">The comment body.</param> /// <param name="state">The comment edit state.</param> /// <param name="user">The author of the comment.</param> /// <param name="updatedAt">The modified date of the comment.</param> /// <param name="isPending">Whether this is a pending comment.</param> public PullRequestReviewCommentViewModel( IPullRequestSession session, ICommentThreadViewModel thread, IAccount currentUser, int commentId, string commentNodeId, string body, CommentEditState state, IAccount user, DateTimeOffset updatedAt, bool isPending) : base(thread, currentUser, commentId, commentNodeId, body, state, user, updatedAt) { Guard.ArgumentNotNull(session, nameof(session)); this.session = session; IsPending = isPending; canStartReview = session.WhenAnyValue(x => x.HasPendingReview, x => !x) .ToProperty(this, x => x.CanStartReview); commitCaption = session.WhenAnyValue( x => x.HasPendingReview, x => x ? Resources.AddReviewComment : Resources.AddSingleComment) .ToProperty(this, x => x.CommitCaption); StartReview = ReactiveCommand.CreateAsyncTask( CommitEdit.CanExecuteObservable, DoStartReview); AddErrorHandler(StartReview); }
/// <inheritdoc/> public async Task InitializeAsync( IPullRequestSession session, Func <IInlineCommentThreadModel, bool> filter = null) { Guard.ArgumentNotNull(session, nameof(session)); subscriptions?.Dispose(); this.pullRequestSession = session; this.commentFilter = filter; subscriptions = new CompositeDisposable(); subscriptions.Add(session.WhenAnyValue(x => x.IsCheckedOut).Subscribe(isBranchCheckedOut)); var dirs = new Dictionary <string, PullRequestDirectoryNode> { { string.Empty, new PullRequestDirectoryNode(string.Empty) } }; using (var changes = await service.GetTreeChanges(session.LocalRepository, session.PullRequest)) { foreach (var changedFile in session.PullRequest.ChangedFiles) { var node = new PullRequestFileNode( session.LocalRepository.LocalPath, changedFile.FileName, changedFile.Sha, changedFile.Status, GetOldFileName(changedFile, changes)); var file = await session.GetFile(changedFile.FileName); if (file != null) { subscriptions.Add(file.WhenAnyValue(x => x.InlineCommentThreads) .Subscribe(x => node.CommentCount = CountComments(x, filter))); subscriptions.Add(file.WhenAnyValue(x => x.InlineAnnotations) .Subscribe(x => { var noticeCount = x.Count(model => model.AnnotationLevel == CheckAnnotationLevel.Notice); var warningCount = x.Count(model => model.AnnotationLevel == CheckAnnotationLevel.Warning); var failureCount = x.Count(model => model.AnnotationLevel == CheckAnnotationLevel.Failure); node.AnnotationNoticeCount = noticeCount; node.AnnotationWarningCount = warningCount; node.AnnotationFailureCount = failureCount; })); } var dir = GetDirectory(Path.GetDirectoryName(node.RelativePath), dirs); dir.Files.Add(node); } } ChangedFilesCount = session.PullRequest.ChangedFiles.Count; Items = dirs[string.Empty].Children.ToList(); }
/// <summary> /// Initializes a new instance of the <see cref="PullRequestReviewCommentViewModel"/> class. /// </summary> /// <param name="session">The pull request session.</param> /// <param name="commentService">The comment service</param> /// <param name="thread">The thread that the comment is a part of.</param> /// <param name="currentUser">The current user.</param> /// <param name="pullRequestId">The pull request id of the comment.</param> /// <param name="commentId">The GraphQL ID of the comment.</param> /// <param name="databaseId">The database id of the comment.</param> /// <param name="body">The comment body.</param> /// <param name="state">The comment edit state.</param> /// <param name="author">The author of the comment.</param> /// <param name="updatedAt">The modified date of the comment.</param> /// <param name="isPending">Whether this is a pending comment.</param> /// <param name="webUrl"></param> public PullRequestReviewCommentViewModel( IPullRequestSession session, ICommentService commentService, ICommentThreadViewModel thread, IActorViewModel currentUser, int pullRequestId, string commentId, int databaseId, string body, CommentEditState state, IActorViewModel author, DateTimeOffset updatedAt, bool isPending, Uri webUrl) : base(commentService, thread, currentUser, pullRequestId, commentId, databaseId, body, state, author, updatedAt, webUrl) { Guard.ArgumentNotNull(session, nameof(session)); this.session = session; IsPending = isPending; var pendingReviewAndIdObservable = Observable.CombineLatest( session.WhenAnyValue(x => x.HasPendingReview, x => !x), this.WhenAnyValue(model => model.Id).Select(i => i == null), (hasPendingReview, isNewComment) => new { hasPendingReview, isNewComment }); canStartReview = pendingReviewAndIdObservable .Select(arg => arg.hasPendingReview && arg.isNewComment) .ToProperty(this, x => x.CanStartReview); commitCaption = pendingReviewAndIdObservable .Select(arg => !arg.isNewComment ? Resources.UpdateComment : arg.hasPendingReview ? Resources.AddSingleComment : Resources.AddReviewComment) .ToProperty(this, x => x.CommitCaption); StartReview = ReactiveCommand.CreateAsyncTask( CommitEdit.CanExecuteObservable, DoStartReview); AddErrorHandler(StartReview); }