static PullRequestReviewAuthoringViewModel CreateTarget( IPullRequestService pullRequestService = null, IPullRequestEditorService editorService = null, IPullRequestSessionManager sessionManager = null, IMessageDraftStore draftStore = null, IPullRequestFilesViewModel files = null, IScheduler timerScheduler = null, IAutoCompleteAdvisor autoCompleteAdvisor = null ) { editorService = editorService ?? Substitute.For <IPullRequestEditorService>(); sessionManager = sessionManager ?? CreateSessionManager(); draftStore = draftStore ?? Substitute.For <IMessageDraftStore>(); files = files ?? Substitute.For <IPullRequestFilesViewModel>(); autoCompleteAdvisor = autoCompleteAdvisor ?? Substitute.For <IAutoCompleteAdvisor>(); timerScheduler = timerScheduler ?? DefaultScheduler.Instance; return(new PullRequestReviewAuthoringViewModel( pullRequestService, editorService, sessionManager, draftStore, files, autoCompleteAdvisor, timerScheduler)); }
public IssueishCommentViewModel(ICommentService commentService, IAutoCompleteAdvisor autoCompleteAdvisor) : base(commentService, autoCompleteAdvisor) { CloseOrReopen = ReactiveCommand.CreateFromTask( DoCloseOrReopen, this.WhenAnyValue(x => x.CanCloseOrReopen)); AddErrorHandler(CloseOrReopen); }
IssueishCommentViewModel CreateTarget( ICommentService commentService = null, IAutoCompleteAdvisor autoCompleteAdvisor = null) { commentService = commentService ?? Substitute.For <ICommentService>(); autoCompleteAdvisor = autoCompleteAdvisor ?? Substitute.For <IAutoCompleteAdvisor>(); return(new IssueishCommentViewModel(commentService, autoCompleteAdvisor)); }
public PullRequestReviewAuthoringViewModel( IPullRequestService pullRequestService, IPullRequestEditorService editorService, IPullRequestSessionManager sessionManager, IMessageDraftStore draftStore, IPullRequestFilesViewModel files, IAutoCompleteAdvisor autoCompleteAdvisor) : this(pullRequestService, editorService, sessionManager, draftStore, files, autoCompleteAdvisor, DefaultScheduler.Instance) { }
public PullRequestCreationViewModel( IModelServiceFactory modelServiceFactory, IPullRequestService service, INotificationService notifications, IMessageDraftStore draftStore, IGitService gitService, IAutoCompleteAdvisor autoCompleteAdvisor) : this(modelServiceFactory, service, notifications, draftStore, gitService, autoCompleteAdvisor, DefaultScheduler.Instance) { }
public PullRequestReviewCommentViewModel(ICommentService commentService, IAutoCompleteAdvisor autoCompleteAdvisor) : base(commentService, autoCompleteAdvisor) { canStartReview = this.WhenAnyValue( x => x.IsPending, x => x.Id, (isPending, id) => !isPending && id == null) .ToProperty(this, x => x.CanStartReview); StartReview = ReactiveCommand.CreateFromTask(DoStartReview, CommitEdit.CanExecute); AddErrorHandler(StartReview); }
public PullRequestReviewAuthoringViewModel( IPullRequestService pullRequestService, IPullRequestEditorService editorService, IPullRequestSessionManager sessionManager, IMessageDraftStore draftStore, IPullRequestFilesViewModel files, IAutoCompleteAdvisor autoCompleteAdvisor, IScheduler timerScheduler) { Guard.ArgumentNotNull(editorService, nameof(editorService)); Guard.ArgumentNotNull(sessionManager, nameof(sessionManager)); Guard.ArgumentNotNull(draftStore, nameof(draftStore)); Guard.ArgumentNotNull(files, nameof(files)); Guard.ArgumentNotNull(autoCompleteAdvisor, nameof(autoCompleteAdvisor)); Guard.ArgumentNotNull(timerScheduler, nameof(timerScheduler)); this.pullRequestService = pullRequestService; this.editorService = editorService; this.sessionManager = sessionManager; this.draftStore = draftStore; this.timerScheduler = timerScheduler; canApproveRequestChanges = this.WhenAnyValue( x => x.Model, x => x.PullRequestModel, (review, pr) => review != null && pr != null && review.Author.Login != pr.Author.Login) .ToProperty(this, x => x.CanApproveRequestChanges); Files = files; AutoCompleteAdvisor = autoCompleteAdvisor; var hasBodyOrComments = this.WhenAnyValue( x => x.Body, x => x.FileComments.Count, (body, comments) => !string.IsNullOrWhiteSpace(body) || comments > 0); Approve = ReactiveCommand.CreateFromTask(() => DoSubmit(Octokit.PullRequestReviewEvent.Approve)); Comment = ReactiveCommand.CreateFromTask( () => DoSubmit(Octokit.PullRequestReviewEvent.Comment), hasBodyOrComments); RequestChanges = ReactiveCommand.CreateFromTask( () => DoSubmit(Octokit.PullRequestReviewEvent.RequestChanges), hasBodyOrComments); Cancel = ReactiveCommand.CreateFromTask(DoCancel); NavigateToPullRequest = ReactiveCommand.Create(() => NavigateTo(Invariant($"{RemoteRepositoryOwner}/{LocalRepository.Name}/pull/{PullRequestModel.Number}"))); }
public CommentViewModel(ICommentService commentService, IAutoCompleteAdvisor autoCompleteAdvisor) { Guard.ArgumentNotNull(commentService, nameof(commentService)); Guard.ArgumentNotNull(autoCompleteAdvisor, nameof(autoCompleteAdvisor)); AutoCompleteAdvisor = autoCompleteAdvisor; this.commentService = commentService; var canDeleteObservable = this.WhenAnyValue( x => x.EditState, x => x.Author, x => x.CurrentUser, (editState, author, currentUser) => editState == CommentEditState.None && author?.Login == currentUser?.Login); canDelete = canDeleteObservable.ToProperty(this, x => x.CanDelete); Delete = ReactiveCommand.CreateFromTask(DoDelete, canDeleteObservable); var canEdit = this.WhenAnyValue( x => x.EditState, x => x.Author, x => x.CurrentUser, (editState, author, currentUser) => editState == CommentEditState.Placeholder || (editState == CommentEditState.None && author?.Login == currentUser?.Login)); BeginEdit = ReactiveCommand.Create(DoBeginEdit, canEdit); AddErrorHandler(BeginEdit); CommitEdit = ReactiveCommand.CreateFromTask( DoCommitEdit, this.WhenAnyValue( x => x.IsReadOnly, x => x.Body, (ro, body) => !ro && !string.IsNullOrWhiteSpace(body))); AddErrorHandler(CommitEdit); canCancel = this.WhenAnyValue(x => x.Id) .Select(id => id != null) .ToProperty(this, x => x.CanCancel); CancelEdit = ReactiveCommand.Create(DoCancelEdit, CommitEdit.IsExecuting.Select(x => !x)); AddErrorHandler(CancelEdit); OpenOnGitHub = ReactiveCommand.Create( () => { }, this.WhenAnyValue(x => x.Id).Select(x => x != null)); }
static async Task <PullRequestReviewCommentViewModel> CreateTarget( IPullRequestSession session = null, ICommentService commentService = null, ICommentThreadViewModel thread = null, ActorModel currentUser = null, PullRequestReviewModel review = null, PullRequestReviewCommentModel comment = null, IAutoCompleteAdvisor autoCompleteAdvisor = null) { session = session ?? CreateSession(); commentService = commentService ?? Substitute.For <ICommentService>(); autoCompleteAdvisor = autoCompleteAdvisor ?? Substitute.For <IAutoCompleteAdvisor>(); thread = thread ?? CreateThread(); currentUser = currentUser ?? new ActorModel { Login = "******" }; comment = comment ?? new PullRequestReviewCommentModel(); review = review ?? CreateReview(PullRequestReviewState.Approved, comment); var result = new PullRequestReviewCommentViewModel(commentService, autoCompleteAdvisor); await result.InitializeAsync(session, thread, review, comment, CommentEditState.None); return(result); }
public PullRequestCreationViewModel( IModelServiceFactory modelServiceFactory, IPullRequestService service, INotificationService notifications, IMessageDraftStore draftStore, IGitService gitService, IAutoCompleteAdvisor autoCompleteAdvisor, IScheduler timerScheduler) { Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory)); Guard.ArgumentNotNull(service, nameof(service)); Guard.ArgumentNotNull(notifications, nameof(notifications)); Guard.ArgumentNotNull(draftStore, nameof(draftStore)); Guard.ArgumentNotNull(gitService, nameof(gitService)); Guard.ArgumentNotNull(autoCompleteAdvisor, nameof(autoCompleteAdvisor)); Guard.ArgumentNotNull(timerScheduler, nameof(timerScheduler)); this.service = service; this.modelServiceFactory = modelServiceFactory; this.draftStore = draftStore; this.gitService = gitService; this.AutoCompleteAdvisor = autoCompleteAdvisor; this.timerScheduler = timerScheduler; this.WhenAnyValue(x => x.Branches) .WhereNotNull() .Where(_ => TargetBranch != null) .Subscribe(x => { if (!x.Any(t => t.Equals(TargetBranch))) { TargetBranch = GitHubRepository.IsFork ? GitHubRepository.Parent.DefaultBranch : GitHubRepository.DefaultBranch; } }); SetupValidators(); var whenAnyValidationResultChanges = this.WhenAny( x => x.TitleValidator.ValidationResult, x => x.BranchValidator.ValidationResult, x => x.IsBusy, (x, y, z) => (x.Value?.IsValid ?? false) && (y.Value?.IsValid ?? false) && !z.Value); this.WhenAny(x => x.BranchValidator.ValidationResult, x => x.GetValue()) .WhereNotNull() .Where(x => !x.IsValid && x.DisplayValidationError) .Subscribe(x => notifications.ShowError(BranchValidator.ValidationResult.Message)); CreatePullRequest = ReactiveCommand.CreateFromObservable( () => service .CreatePullRequest(modelService, activeLocalRepo, TargetBranch.Repository, SourceBranch, TargetBranch, PRTitle, Description ?? String.Empty) .Catch <IPullRequestModel, Exception>(ex => { log.Error(ex, "Error creating pull request"); //TODO:Will need a uniform solution to HTTP exception message handling var apiException = ex as ApiValidationException; var error = apiException?.ApiError?.Errors?.FirstOrDefault(); notifications.ShowError(error?.Message ?? ex.Message); return(Observable.Empty <IPullRequestModel>()); }), whenAnyValidationResultChanges); CreatePullRequest.Subscribe(pr => { notifications.ShowMessage(String.Format(CultureInfo.CurrentCulture, Resources.PRCreatedUpstream, SourceBranch.DisplayName, TargetBranch.Repository.Owner + "/" + TargetBranch.Repository.Name + "#" + pr.Number, TargetBranch.Repository.CloneUrl.ToRepositoryUrl().Append("pull/" + pr.Number))); NavigateTo("/pulls?refresh=true"); Cancel.Execute(); draftStore.DeleteDraft(GetDraftKey(), string.Empty).Forget(); Close(); }); Cancel = ReactiveCommand.Create(() => { }); Cancel.Subscribe(_ => { Close(); draftStore.DeleteDraft(GetDraftKey(), string.Empty).Forget(); }); isExecuting = CreatePullRequest.IsExecuting.ToProperty(this, x => x.IsExecuting); this.WhenAnyValue(x => x.Initialized, x => x.GitHubRepository, x => x.IsExecuting) .Select(x => !(x.Item1 && x.Item2 != null && !x.Item3)) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => IsBusy = x); }