Example #1
0
        public PullRequestDetailViewModel(
            IPullRequestService pullRequestsService,
            IPullRequestSessionManager sessionManager,
            IModelServiceFactory modelServiceFactory,
            IUsageTracker usageTracker,
            ITeamExplorerContext teamExplorerContext,
            IPullRequestFilesViewModel files,
            ISyncSubmodulesCommand syncSubmodulesCommand,
            IViewViewModelFactory viewViewModelFactory)
        {
            Guard.ArgumentNotNull(pullRequestsService, nameof(pullRequestsService));
            Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));
            Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext));
            Guard.ArgumentNotNull(syncSubmodulesCommand, nameof(syncSubmodulesCommand));
            Guard.ArgumentNotNull(viewViewModelFactory, nameof(viewViewModelFactory));

            this.pullRequestsService   = pullRequestsService;
            this.sessionManager        = sessionManager;
            this.modelServiceFactory   = modelServiceFactory;
            this.usageTracker          = usageTracker;
            this.teamExplorerContext   = teamExplorerContext;
            this.syncSubmodulesCommand = syncSubmodulesCommand;
            this.viewViewModelFactory  = viewViewModelFactory;
            Files = files;

            Checkout = ReactiveCommand.CreateAsyncObservable(
                this.WhenAnyValue(x => x.CheckoutState)
                .Cast <CheckoutCommandState>()
                .Select(x => x != null && x.IsEnabled),
                DoCheckout);
            Checkout.IsExecuting.Subscribe(x => isInCheckout = x);
            SubscribeOperationError(Checkout);

            Pull = ReactiveCommand.CreateAsyncObservable(
                this.WhenAnyValue(x => x.UpdateState)
                .Cast <UpdateCommandState>()
                .Select(x => x != null && x.PullEnabled),
                DoPull);
            SubscribeOperationError(Pull);

            Push = ReactiveCommand.CreateAsyncObservable(
                this.WhenAnyValue(x => x.UpdateState)
                .Cast <UpdateCommandState>()
                .Select(x => x != null && x.PushEnabled),
                DoPush);
            SubscribeOperationError(Push);

            SyncSubmodules = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.UpdateState)
                .Cast <UpdateCommandState>()
                .Select(x => x != null && x.SyncSubmodulesEnabled),
                DoSyncSubmodules);
            SyncSubmodules.Subscribe(_ => Refresh().ToObservable());
            SubscribeOperationError(SyncSubmodules);

            OpenOnGitHub = ReactiveCommand.Create();
            ShowReview   = ReactiveCommand.Create().OnExecuteCompleted(DoShowReview);
        }
Example #2
0
        async Task <PullRequestReviewCommentThreadViewModel> CreateTarget(
            IMessageDraftStore draftStore             = null,
            IViewViewModelFactory factory             = null,
            IPullRequestSession session               = null,
            IPullRequestSessionFile file              = null,
            IEnumerable <InlineCommentModel> comments = null,
            bool newThread = false)
        {
            draftStore = draftStore ?? Substitute.For <IMessageDraftStore>();
            factory    = factory ?? CreateFactory();
            session    = session ?? CreateSession();
            file       = file ?? CreateFile();
            comments   = comments ?? CreateComments();

            var result = new PullRequestReviewCommentThreadViewModel(draftStore, factory);

            if (newThread)
            {
                await result.InitializeNewAsync(session, file, 10, DiffSide.Right, true);
            }
            else
            {
                var thread = Substitute.For <IInlineCommentThreadModel>();
                thread.Comments.Returns(comments.ToList());
                thread.LineNumber.Returns(10);

                await result.InitializeAsync(session, file, thread, true);
            }

            return(result);
        }
Example #3
0
 public GitHubDialogWindowViewModel(
     IViewViewModelFactory factory,
     Lazy <IConnectionManager> connectionManager)
 {
     this.factory           = factory;
     this.connectionManager = connectionManager;
 }
Example #4
0
        public PullRequestPageViewModel(
            IViewViewModelFactory factory,
            IPullRequestService service,
            IPullRequestSessionManager sessionManager,
            ITeamExplorerServices teServices,
            IVisualStudioBrowser visualStudioBrowser,
            IUsageTracker usageTracker)
        {
            Guard.ArgumentNotNull(factory, nameof(factory));
            Guard.ArgumentNotNull(service, nameof(service));
            Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
            Guard.ArgumentNotNull(visualStudioBrowser, nameof(visualStudioBrowser));
            Guard.ArgumentNotNull(teServices, nameof(teServices));

            this.factory             = factory;
            this.service             = service;
            this.sessionManager      = sessionManager;
            this.teServices          = teServices;
            this.visualStudioBrowser = visualStudioBrowser;
            this.usageTracker        = usageTracker;

            timeline.ItemsRemoved.Subscribe(TimelineItemRemoved);

            ShowCommit   = ReactiveCommand.CreateFromTask <string>(DoShowCommit);
            OpenOnGitHub = ReactiveCommand.Create(DoOpenOnGitHub);
        }
    static GitHubPaneViewModel CreateTarget(
        IViewViewModelFactory viewModelFactory   = null,
        ISimpleApiClientFactory apiClientFactory = null,
        IConnectionManager connectionManager     = null,
        ITeamExplorerContext teamExplorerContext = null,
        IVisualStudioBrowser browser             = null,
        IUsageTracker usageTracker     = null,
        INavigationViewModel navigator = null,
        ILoggedOutViewModel loggedOut  = null,
        INotAGitHubRepositoryViewModel notAGitHubRepository = null,
        INotAGitRepositoryViewModel notAGitRepository       = null,
        ILoginFailedViewModel loginFailed = null)
    {
        viewModelFactory     = viewModelFactory ?? Substitute.For <IViewViewModelFactory>();
        connectionManager    = connectionManager ?? Substitute.For <IConnectionManager>();
        teamExplorerContext  = teamExplorerContext ?? CreateTeamExplorerContext(ValidGitHubRepo);
        browser              = browser ?? Substitute.For <IVisualStudioBrowser>();
        usageTracker         = usageTracker ?? Substitute.For <IUsageTracker>();
        loggedOut            = loggedOut ?? Substitute.For <ILoggedOutViewModel>();
        notAGitHubRepository = notAGitHubRepository ?? Substitute.For <INotAGitHubRepositoryViewModel>();
        notAGitRepository    = notAGitRepository ?? Substitute.For <INotAGitRepositoryViewModel>();
        loginFailed          = loginFailed ?? Substitute.For <ILoginFailedViewModel>();

        if (navigator == null)
        {
            navigator = CreateNavigator();
            navigator.Content.Returns((IPanePageViewModel)null);
        }

        if (apiClientFactory == null)
        {
            var validGitHubRepoClient     = Substitute.For <ISimpleApiClient>();
            var validEnterpriseRepoClient = Substitute.For <ISimpleApiClient>();
            var invalidRepoClient         = Substitute.For <ISimpleApiClient>();

            validGitHubRepoClient.GetRepository().Returns(new Octokit.Repository(1));
            validEnterpriseRepoClient.GetRepository().Returns(new Octokit.Repository(1));
            validEnterpriseRepoClient.IsEnterprise().Returns(true);

            apiClientFactory = Substitute.For <ISimpleApiClientFactory>();
            apiClientFactory.Create(null).ReturnsForAnyArgs(invalidRepoClient);
            apiClientFactory.Create(ValidGitHubRepo).Returns(validGitHubRepoClient);
            apiClientFactory.Create(ValidEnterpriseRepo).Returns(validEnterpriseRepoClient);
        }

        return(new GitHubPaneViewModel(
                   viewModelFactory,
                   apiClientFactory,
                   connectionManager,
                   teamExplorerContext,
                   browser,
                   usageTracker,
                   navigator,
                   loggedOut,
                   notAGitHubRepository,
                   notAGitRepository,
                   loginFailed));
    }
Example #6
0
        public DialogService(
            IViewViewModelFactory factory,
            IShowDialogService showDialog)
        {
            Guard.ArgumentNotNull(factory, nameof(factory));
            Guard.ArgumentNotNull(showDialog, nameof(showDialog));

            this.factory    = factory;
            this.showDialog = showDialog;
        }
Example #7
0
        public IssueishPaneViewModel(
            IViewViewModelFactory factory,
            IPullRequestSessionManager sessionManager)
        {
            Guard.ArgumentNotNull(factory, nameof(factory));
            Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));

            this.factory        = factory;
            this.sessionManager = sessionManager;
        }
Example #8
0
 public InlineCommentPeekableItemSource(IInlineCommentPeekService peekService,
                                        IPullRequestSessionManager sessionManager,
                                        INextInlineCommentCommand nextCommentCommand,
                                        IPreviousInlineCommentCommand previousCommentCommand,
                                        IViewViewModelFactory factory)
 {
     this.peekService            = peekService;
     this.sessionManager         = sessionManager;
     this.nextCommentCommand     = nextCommentCommand;
     this.previousCommentCommand = previousCommentCommand;
     this.factory = factory;
 }
        public PullRequestReviewCommentThreadViewModel(IViewViewModelFactory factory)
        {
            Guard.ArgumentNotNull(factory, nameof(factory));

            this.factory = factory;

            needsPush = this.WhenAnyValue(
                x => x.File.CommitSha,
                x => x.IsNewThread,
                (sha, isNew) => isNew && sha == null)
                        .ToProperty(this, x => x.NeedsPush);
        }
Example #10
0
        public DialogService(
            IViewViewModelFactory factory,
            IShowDialogService showDialog,
            IGitHubContextService gitHubContextService)
        {
            Guard.ArgumentNotNull(factory, nameof(factory));
            Guard.ArgumentNotNull(showDialog, nameof(showDialog));
            Guard.ArgumentNotNull(showDialog, nameof(gitHubContextService));

            this.factory              = factory;
            this.showDialog           = showDialog;
            this.gitHubContextService = gitHubContextService;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InlineCommentPeekViewModel"/> class.
        /// </summary>
        public InlineCommentPeekViewModel(IInlineCommentPeekService peekService,
                                          IPeekSession peekSession,
                                          IPullRequestSessionManager sessionManager,
                                          INextInlineCommentCommand nextCommentCommand,
                                          IPreviousInlineCommentCommand previousCommentCommand,
                                          IViewViewModelFactory factory)
        {
            Guard.ArgumentNotNull(peekService, nameof(peekService));
            Guard.ArgumentNotNull(peekSession, nameof(peekSession));
            Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
            Guard.ArgumentNotNull(nextCommentCommand, nameof(nextCommentCommand));
            Guard.ArgumentNotNull(previousCommentCommand, nameof(previousCommentCommand));
            Guard.ArgumentNotNull(factory, nameof(factory));

            this.peekService    = peekService;
            this.peekSession    = peekSession;
            this.sessionManager = sessionManager;
            this.factory        = factory;
            triggerPoint        = peekSession.GetTriggerPoint(peekSession.TextView.TextBuffer);

            peekSession.Dismissed += (s, e) => Dispose();

            Close = this.WhenAnyValue(x => x.Thread)
                    .Where(x => x != null)
                    .SelectMany(x => x.IsNewThread
                    ? x.Comments.Single().CancelEdit.SelectUnit()
                    : Observable.Never <Unit>());

            NextComment = ReactiveCommand.CreateFromTask(
                () => nextCommentCommand.Execute(new InlineCommentNavigationParams
            {
                FromLine = peekService.GetLineNumber(peekSession, triggerPoint).Item1,
            }),
                Observable.Return(nextCommentCommand.Enabled));

            PreviousComment = ReactiveCommand.CreateFromTask(
                () => previousCommentCommand.Execute(new InlineCommentNavigationParams
            {
                FromLine = peekService.GetLineNumber(peekSession, triggerPoint).Item1,
            }),
                Observable.Return(previousCommentCommand.Enabled));
        }
Example #12
0
        async Task <PullRequestReviewCommentThreadViewModel> CreateTarget(
            IViewViewModelFactory factory             = null,
            IPullRequestSession session               = null,
            IPullRequestSessionFile file              = null,
            PullRequestReviewModel review             = null,
            IEnumerable <InlineCommentModel> comments = null)
        {
            factory  = factory ?? CreateFactory();
            session  = session ?? CreateSession();
            file     = file ?? Substitute.For <IPullRequestSessionFile>();
            review   = review ?? new PullRequestReviewModel();
            comments = comments ?? CreateComments();

            var thread = Substitute.For <IInlineCommentThreadModel>();

            thread.Comments.Returns(comments.ToList());

            var result = new PullRequestReviewCommentThreadViewModel(factory);
            await result.InitializeAsync(session, file, review, thread, true);

            return(result);
        }
        public static IEnumerable <IPullRequestCheckViewModel> Build(IViewViewModelFactory viewViewModelFactory, PullRequestDetailModel pullRequest)
        {
            return(pullRequest.Statuses?.Select(model =>
            {
                PullRequestCheckStatus checkStatus;
                switch (model.State)
                {
                case StatusState.Expected:
                case StatusState.Error:
                case StatusState.Failure:
                    checkStatus = PullRequestCheckStatus.Failure;
                    break;

                case StatusState.Pending:
                    checkStatus = PullRequestCheckStatus.Pending;
                    break;

                case StatusState.Success:
                    checkStatus = PullRequestCheckStatus.Success;
                    break;

                default:
                    throw new InvalidOperationException("Unkown PullRequestCheckStatusEnum");
                }

                var pullRequestCheckViewModel = (PullRequestCheckViewModel)viewViewModelFactory.CreateViewModel <IPullRequestCheckViewModel>();
                pullRequestCheckViewModel.Title = model.Context;
                pullRequestCheckViewModel.Description = model.Description;
                pullRequestCheckViewModel.Status = checkStatus;
                pullRequestCheckViewModel.DetailsUrl = new Uri(model.TargetUrl);
                pullRequestCheckViewModel.AvatarUrl = model.AvatarUrl ?? DefaultAvatar;
                pullRequestCheckViewModel.Avatar = model.AvatarUrl != null
                    ? new BitmapImage(new Uri(model.AvatarUrl))
                    : AvatarProvider.CreateBitmapImage(DefaultAvatar);

                return pullRequestCheckViewModel;
            }) ?? new PullRequestCheckViewModel[0]);
        }
Example #14
0
        public PullRequestDetailViewModel(
            IPullRequestService pullRequestsService,
            IPullRequestSessionManager sessionManager,
            IModelServiceFactory modelServiceFactory,
            IUsageTracker usageTracker,
            ITeamExplorerContext teamExplorerContext,
            IPullRequestFilesViewModel files,
            ISyncSubmodulesCommand syncSubmodulesCommand,
            IViewViewModelFactory viewViewModelFactory,
            IGitService gitService,
            IOpenIssueishDocumentCommand openDocumentCommand,
            [Import(AllowDefault = true)] JoinableTaskContext joinableTaskContext)
        {
            Guard.ArgumentNotNull(pullRequestsService, nameof(pullRequestsService));
            Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));
            Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext));
            Guard.ArgumentNotNull(syncSubmodulesCommand, nameof(syncSubmodulesCommand));
            Guard.ArgumentNotNull(viewViewModelFactory, nameof(viewViewModelFactory));
            Guard.ArgumentNotNull(gitService, nameof(gitService));
            Guard.ArgumentNotNull(openDocumentCommand, nameof(openDocumentCommand));

            this.pullRequestsService   = pullRequestsService;
            this.sessionManager        = sessionManager;
            this.modelServiceFactory   = modelServiceFactory;
            this.usageTracker          = usageTracker;
            this.teamExplorerContext   = teamExplorerContext;
            this.syncSubmodulesCommand = syncSubmodulesCommand;
            this.viewViewModelFactory  = viewViewModelFactory;
            this.gitService            = gitService;
            this.openDocumentCommand   = openDocumentCommand;
            JoinableTaskContext        = joinableTaskContext ?? ThreadHelper.JoinableTaskContext;

            Files = files;

            Checkout = ReactiveCommand.CreateFromObservable(
                DoCheckout,
                this.WhenAnyValue(x => x.CheckoutState)
                .Cast <CheckoutCommandState>()
                .Select(x => x != null && x.IsEnabled));
            Checkout.IsExecuting.Subscribe(x => isInCheckout = x);
            SubscribeOperationError(Checkout);

            Pull = ReactiveCommand.CreateFromObservable(
                DoPull,
                this.WhenAnyValue(x => x.UpdateState)
                .Cast <UpdateCommandState>()
                .Select(x => x != null && x.PullEnabled));
            SubscribeOperationError(Pull);

            Push = ReactiveCommand.CreateFromObservable(
                DoPush,
                this.WhenAnyValue(x => x.UpdateState)
                .Cast <UpdateCommandState>()
                .Select(x => x != null && x.PushEnabled));
            SubscribeOperationError(Push);

            SyncSubmodules = ReactiveCommand.CreateFromTask(
                DoSyncSubmodules,
                this.WhenAnyValue(x => x.UpdateState)
                .Cast <UpdateCommandState>()
                .Select(x => x != null && x.SyncSubmodulesEnabled));
            SyncSubmodules.Subscribe(_ => Refresh().ToObservable());
            SubscribeOperationError(SyncSubmodules);

            OpenConversation = ReactiveCommand.Create(DoOpenConversation);

            OpenOnGitHub = ReactiveCommand.Create(DoOpenDetailsUrl);

            ShowReview = ReactiveCommand.Create <IPullRequestReviewSummaryViewModel>(DoShowReview);

            ShowAnnotations = ReactiveCommand.Create <IPullRequestCheckViewModel>(DoShowAnnotations);
        }
Example #15
0
        public GitHubPaneViewModel(
            IViewViewModelFactory viewModelFactory,
            ISimpleApiClientFactory apiClientFactory,
            IConnectionManager connectionManager,
            ITeamExplorerContext teamExplorerContext,
            IVisualStudioBrowser browser,
            IUsageTracker usageTracker,
            INavigationViewModel navigator,
            ILoggedOutViewModel loggedOut,
            INotAGitHubRepositoryViewModel notAGitHubRepository,
            INotAGitRepositoryViewModel notAGitRepository,
            INoRemoteOriginViewModel noRemoteOrigin,
            ILoginFailedViewModel loginFailed)
        {
            Guard.ArgumentNotNull(viewModelFactory, nameof(viewModelFactory));
            Guard.ArgumentNotNull(apiClientFactory, nameof(apiClientFactory));
            Guard.ArgumentNotNull(connectionManager, nameof(connectionManager));
            Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext));
            Guard.ArgumentNotNull(browser, nameof(browser));
            Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));
            Guard.ArgumentNotNull(navigator, nameof(navigator));
            Guard.ArgumentNotNull(loggedOut, nameof(loggedOut));
            Guard.ArgumentNotNull(notAGitHubRepository, nameof(notAGitHubRepository));
            Guard.ArgumentNotNull(notAGitRepository, nameof(notAGitRepository));
            Guard.ArgumentNotNull(noRemoteOrigin, nameof(noRemoteOrigin));
            Guard.ArgumentNotNull(loginFailed, nameof(loginFailed));

            this.viewModelFactory     = viewModelFactory;
            this.apiClientFactory     = apiClientFactory;
            this.connectionManager    = connectionManager;
            this.teamExplorerContext  = teamExplorerContext;
            this.navigator            = navigator;
            this.loggedOut            = loggedOut;
            this.notAGitHubRepository = notAGitHubRepository;
            this.notAGitRepository    = notAGitRepository;
            this.noRemoteOrigin       = noRemoteOrigin;
            this.loginFailed          = loginFailed;

            var contentAndNavigatorContent = Observable.CombineLatest(
                this.WhenAnyValue(x => x.Content),
                navigator.WhenAnyValue(x => x.Content),
                (c, nc) => new { Content = c, NavigatorContent = nc });

            contentOverride = contentAndNavigatorContent
                              .SelectMany(x =>
            {
                if (x.Content == null)
                {
                    return(Observable.Return(ContentOverride.Spinner));
                }
                else if (x.Content == navigator && x.NavigatorContent != null)
                {
                    return(x.NavigatorContent.WhenAnyValue(
                               y => y.IsLoading,
                               y => y.Error,
                               (l, e) =>
                    {
                        if (l)
                        {
                            return ContentOverride.Spinner;
                        }
                        if (e != null)
                        {
                            return ContentOverride.Error;
                        }
                        else
                        {
                            return ContentOverride.None;
                        }
                    }));
                }
                else
                {
                    return(Observable.Return(ContentOverride.None));
                }
            })
                              .ToProperty(this, x => x.ContentOverride);

            // Returns navigator.Content if Content == navigator, otherwise null.
            var currentPage = contentAndNavigatorContent
                              .Select(x => x.Content == navigator ? x.NavigatorContent : null);

            title = currentPage
                    .SelectMany(x => x?.WhenAnyValue(y => y.Title) ?? Observable.Return <string>(null))
                    .Select(x => x ?? "GitHub")
                    .ToProperty(this, x => x.Title);

            isSearchEnabled = currentPage
                              .Select(x => x is ISearchablePageViewModel)
                              .ToProperty(this, x => x.IsSearchEnabled);

            refresh = ReactiveCommand.CreateFromTask(
                () => navigator.Content.Refresh(),
                currentPage.SelectMany(x => x?.WhenAnyValue(
                                           y => y.IsLoading,
                                           y => y.IsBusy,
                                           (loading, busy) => !loading && !busy)
                                       ?? Observable.Return(false)));
            refresh.ThrownExceptions.Subscribe();

            showPullRequests = ReactiveCommand.CreateFromTask(
                ShowPullRequests,
                this.WhenAny(x => x.Content, x => x.Value == navigator));

            openInBrowser = ReactiveCommand.Create(
                () =>
            {
                var url = ((IOpenInBrowser)navigator.Content).WebUrl;
                if (url != null)
                {
                    browser.OpenUrl(url);
                }
            },
                currentPage.Select(x => x is IOpenInBrowser));

            BrowseRepository = ReactiveCommand.Create(
                () =>
            {
                var url = LocalRepository.CloneUrl.ToRepositoryUrl();
                if (url != null)
                {
                    browser.OpenUrl(url);
                }
            },
                currentPage.Select(x => x is IOpenInBrowser));

            help = ReactiveCommand.Create(() => { });
            help.Subscribe(_ =>
            {
                browser.OpenUrl(new Uri(GitHubUrls.Documentation));
                usageTracker.IncrementCounter(x => x.NumberOfGitHubPaneHelpClicks).Forget();
            });

            navigator.WhenAnyObservable(x => x.Content.NavigationRequested)
            .Subscribe(x => NavigateTo(x).Forget());

            this.WhenAnyValue(x => x.SearchQuery)
            .Where(x => navigator.Content is ISearchablePageViewModel)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x => ((ISearchablePageViewModel)navigator.Content).SearchQuery = x);
        }
        static void InitializeViewLocator(IViewViewModelFactory viewViewModelFactory)
        {
            var factoryProviderFiled = typeof(ViewLocator).GetField("factoryProvider", BindingFlags.Static | BindingFlags.NonPublic);

            factoryProviderFiled.SetValue(null, viewViewModelFactory);
        }
Example #17
0
        public static IEnumerable <IPullRequestCheckViewModel> Build(IViewViewModelFactory viewViewModelFactory, PullRequestDetailModel pullRequest)
        {
            var statuses = pullRequest.Statuses?.Select(model =>
            {
                PullRequestCheckStatus checkStatus;
                switch (model.State)
                {
                case StatusState.Expected:
                case StatusState.Error:
                case StatusState.Failure:
                    checkStatus = PullRequestCheckStatus.Failure;
                    break;

                case StatusState.Pending:
                    checkStatus = PullRequestCheckStatus.Pending;
                    break;

                case StatusState.Success:
                    checkStatus = PullRequestCheckStatus.Success;
                    break;

                default:
                    throw new InvalidOperationException("Unkown PullRequestCheckStatusEnum");
                }

                var pullRequestCheckViewModel         = (PullRequestCheckViewModel)viewViewModelFactory.CreateViewModel <IPullRequestCheckViewModel>();
                pullRequestCheckViewModel.CheckType   = PullRequestCheckType.StatusApi;
                pullRequestCheckViewModel.Title       = model.Context;
                pullRequestCheckViewModel.Description = model.Description;
                pullRequestCheckViewModel.Status      = checkStatus;
                pullRequestCheckViewModel.DetailsUrl  = !string.IsNullOrEmpty(model.TargetUrl) ? new Uri(model.TargetUrl) : null;

                return(pullRequestCheckViewModel);
            }) ?? new PullRequestCheckViewModel[0];

            var checks = pullRequest.CheckSuites?.SelectMany(model => model.CheckRuns)
                         .Select(model =>
            {
                PullRequestCheckStatus checkStatus;
                switch (model.Status)
                {
                case CheckStatusState.Requested:
                case CheckStatusState.Queued:
                case CheckStatusState.InProgress:
                    checkStatus = PullRequestCheckStatus.Pending;
                    break;

                case CheckStatusState.Completed:
                    switch (model.Conclusion)
                    {
                    case CheckConclusionState.Success:
                        checkStatus = PullRequestCheckStatus.Success;
                        break;

                    case CheckConclusionState.ActionRequired:
                    case CheckConclusionState.TimedOut:
                    case CheckConclusionState.Cancelled:
                    case CheckConclusionState.Failure:
                    case CheckConclusionState.Neutral:
                        checkStatus = PullRequestCheckStatus.Failure;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                var pullRequestCheckViewModel         = (PullRequestCheckViewModel)viewViewModelFactory.CreateViewModel <IPullRequestCheckViewModel>();
                pullRequestCheckViewModel.CheckType   = PullRequestCheckType.ChecksApi;
                pullRequestCheckViewModel.Title       = model.Name;
                pullRequestCheckViewModel.Description = model.Summary;
                pullRequestCheckViewModel.Status      = checkStatus;
                pullRequestCheckViewModel.DetailsUrl  = new Uri(model.DetailsUrl);

                return(pullRequestCheckViewModel);
            }) ?? new PullRequestCheckViewModel[0];

            return(statuses.Concat(checks).OrderBy(model => model.Title));
        }