/// <summary>
        /// Loads the view model from octokit models.
        /// </summary>
        /// <param name="pullRequest">The pull request model.</param>
        /// <param name="files">The pull request's changed files.</param>
        public async Task Load(IPullRequestModel pullRequest)
        {
            Model = pullRequest;
            Title = Resources.PullRequestNavigationItemText + " #" + pullRequest.Number;

            var prFromFork = pullRequestsService.IsPullRequestFromFork(repository, Model);

            SourceBranchDisplayName = GetBranchDisplayName(prFromFork, pullRequest.Head?.Label);
            TargetBranchDisplayName = GetBranchDisplayName(prFromFork, pullRequest.Base.Label);
            Body = !string.IsNullOrWhiteSpace(pullRequest.Body) ? pullRequest.Body : Resources.NoDescriptionProvidedMarkdown;

            ChangedFilesTree.Clear();
            ChangedFilesList.Clear();

            var treeChanges = await pullRequestsService.GetTreeChanges(repository, pullRequest);

            // WPF doesn't support AddRange here so iterate through the changes.
            foreach (var change in CreateChangedFilesList(pullRequest, treeChanges))
            {
                ChangedFilesList.Add(change);
            }

            foreach (var change in CreateChangedFilesTree(ChangedFilesList).Children)
            {
                ChangedFilesTree.Add(change);
            }

            var localBranches = await pullRequestsService.GetLocalBranches(repository, pullRequest).ToList();

            var isCheckedOut = localBranches.Contains(repository.CurrentBranch);

            if (isCheckedOut)
            {
                var divergence = await pullRequestsService.CalculateHistoryDivergence(repository, Model.Number);

                var    pullEnabled = divergence.BehindBy > 0;
                var    pushEnabled = divergence.AheadBy > 0 && !pullEnabled;
                string pullToolTip;
                string pushToolTip;

                if (pullEnabled)
                {
                    pullToolTip = string.Format(
                        Resources.PullRequestDetailsPullToolTip,
                        prFromFork ? Resources.Fork : Resources.Remote,
                        SourceBranchDisplayName);
                }
                else
                {
                    pullToolTip = Resources.NoCommitsToPull;
                }

                if (pushEnabled)
                {
                    pushToolTip = string.Format(
                        Resources.PullRequestDetailsPushToolTip,
                        prFromFork ? Resources.Fork : Resources.Remote,
                        SourceBranchDisplayName);
                }
                else if (divergence.AheadBy == 0)
                {
                    pushToolTip = Resources.NoCommitsToPush;
                }
                else
                {
                    pushToolTip = Resources.MustPullBeforePush;
                }

                UpdateState   = new UpdateCommandState(divergence, pullEnabled, pushEnabled, pullToolTip, pushToolTip);
                CheckoutState = null;
            }
            else
            {
                var caption = localBranches.Count > 0 ?
                              string.Format(Resources.PullRequestDetailsCheckout, localBranches.First().DisplayName) :
                              string.Format(Resources.PullRequestDetailsCheckoutTo, await pullRequestsService.GetDefaultLocalBranchName(repository, Model.Number, Model.Title));
                var clean = await pullRequestsService.IsWorkingDirectoryClean(repository);

                string disabled = null;

                if (pullRequest.Head == null || !pullRequest.Head.RepositoryCloneUrl.IsValidUri)
                {
                    disabled = Resources.SourceRepositoryNoLongerAvailable;
                }
                else if (!clean)
                {
                    disabled = Resources.WorkingDirectoryHasUncommittedCHanges;
                }

                CheckoutState = new CheckoutCommandState(caption, disabled);
                UpdateState   = null;
            }

            IsBusy = false;

            pullRequestsService.RemoveUnusedRemotes(repository).Subscribe(_ => { });
        }
        /// <summary>
        /// Loads the view model from octokit models.
        /// </summary>
        /// <param name="pullRequest">The pull request model.</param>
        /// <param name="files">The pull request's changed files.</param>
        public async Task Load(IPullRequestModel pullRequest)
        {
            Model = pullRequest;
            Title = Resources.PullRequestNavigationItemText + " #" + pullRequest.Number;
            SourceBranchDisplayName = GetBranchDisplayName(pullRequest.Head?.Label);
            TargetBranchDisplayName = GetBranchDisplayName(pullRequest.Base.Label);
            Body = !string.IsNullOrWhiteSpace(pullRequest.Body) ? pullRequest.Body : "*No description provided.*";

            ChangedFilesTree.Clear();
            ChangedFilesList.Clear();

            var treeChanges = await pullRequestsService.GetTreeChanges(repository, pullRequest);

            // WPF doesn't support AddRange here so iterate through the changes.
            foreach (var change in CreateChangedFilesList(pullRequest, treeChanges))
            {
                ChangedFilesList.Add(change);
            }

            foreach (var change in CreateChangedFilesTree(ChangedFilesList).Children)
            {
                ChangedFilesTree.Add(change);
            }

            var localBranches = await pullRequestsService.GetLocalBranches(repository, pullRequest).ToList();

            var isCheckedOut = localBranches.Contains(repository.CurrentBranch);

            if (isCheckedOut)
            {
                var divergence = await pullRequestsService.CalculateHistoryDivergence(repository, Model.Number);

                var pullDisabled = divergence.BehindBy == 0 ? "No commits to pull" : null;
                var pushDisabled = divergence.AheadBy == 0 ?
                                   "No commits to push" :
                                   divergence.BehindBy > 0 ? "You must pull before you can push" : null;

                UpdateState   = new UpdateCommandState(divergence, pullDisabled, pushDisabled);
                CheckoutState = null;
            }
            else
            {
                var caption = localBranches.Count > 0 ?
                              "Checkout " + localBranches.First().DisplayName :
                              "Checkout to " + (await pullRequestsService.GetDefaultLocalBranchName(repository, Model.Number, Model.Title));
                var clean = await pullRequestsService.IsWorkingDirectoryClean(repository);

                string disabled = null;

                if (pullRequest.Head == null || !pullRequest.Head.RepositoryCloneUrl.IsValidUri)
                {
                    disabled = "The source repository is no longer available.";
                }
                else if (!clean)
                {
                    disabled = "Cannot checkout as your working directory has uncommitted changes.";
                }

                CheckoutState = new CheckoutCommandState(caption, disabled);
                UpdateState   = null;
            }

            IsBusy = false;

            pullRequestsService.RemoteUnusedRemotes(repository).Subscribe(_ => { });
        }