Example #1
0
        IObservable <Unit> DoCheckout()
        {
            OperationError = null;

            return(Observable.Defer(async() =>
            {
                var localBranches = await pullRequestsService.GetLocalBranches(LocalRepository, Model).ToList();

                if (localBranches.Count > 0)
                {
                    return pullRequestsService.SwitchToBranch(LocalRepository, Model);
                }
                else
                {
                    return pullRequestsService
                    .GetDefaultLocalBranchName(LocalRepository, Model.Number, Model.Title)
                    .SelectMany(x => pullRequestsService.Checkout(LocalRepository, Model, x));
                }
            }).Do(_ =>
            {
                if (IsFromFork)
                {
                    usageTracker.IncrementCounter(x => x.NumberOfForkPullRequestsCheckedOut).Forget();
                }
                else
                {
                    usageTracker.IncrementCounter(x => x.NumberOfLocalPullRequestsCheckedOut).Forget();
                }
            }));
        }
Example #2
0
        IObservable <Unit> DoCheckout(object unused)
        {
            IObservable <Unit> operation = null;

            switch (CheckoutMode)
            {
            case CheckoutMode.NeedsPull:
                operation = pullRequestsService.Pull(repository);
                break;

            case CheckoutMode.Fetch:
                operation = pullRequestsService
                            .GetDefaultLocalBranchName(repository, Model.Number, Model.Title)
                            .SelectMany(x => pullRequestsService.FetchAndCheckout(repository, Model.Number, x));
                break;

            case CheckoutMode.Switch:
                operation = pullRequestsService.SwitchToBranch(repository, Model);
                break;

            case CheckoutMode.InvalidState:
                operation = pullRequestsService
                            .UnmarkLocalBranch(repository)
                            .SelectMany(_ => pullRequestsService.GetDefaultLocalBranchName(repository, Model.Number, Model.Title))
                            .SelectMany(x => pullRequestsService.FetchAndCheckout(repository, Model.Number, x));
                break;

            default:
                Debug.Fail("Invalid CheckoutMode in PullRequestDetailViewModel.DoCheckout.");
                operation = Observable.Empty <Unit>();
                break;
            }

            return(operation.Catch <Unit, Exception>(ex =>
            {
                CheckoutError = ex.Message;
                return Observable.Empty <Unit>();
            }));
        }