コード例 #1
0
            protected override async Task RunProcess()
            {
                if (mode == DeleteBranchMode.ActualBranchOnly)
                {
                    await AppendProcess(cli.DeleteRemote(deletingBranch)).WaitUntilComplete();

                    await repository.BranchUpdated(deletingBranch, null, await repository.GetBranchRef(deletingBranch).Take(1));
                }
                else
                {
                    var details = await repository.GetBranchDetails(deletingBranch).FirstAsync();

                    using (var unitOfWork = unitOfWorkFactory.CreateUnitOfWork())
                    {
                        settings.DeleteBranchSettings(deletingBranch, unitOfWork);

                        await unitOfWork.CommitAsync();
                    }

                    if (mode != DeleteBranchMode.GroupOnly)
                    {
                        foreach (var branch in details.Branches)
                        {
                            await AppendProcess(cli.DeleteRemote(branch.Name)).WaitUntilComplete();

                            await repository.BranchUpdated(branch.Name, null, await repository.GetBranchRef(branch.Name).Take(1));
                        }
                    }
                }
            }
コード例 #2
0
 public MergeDownstreamActionProcess(IGitCli cli, IGitServiceApi gitServiceApi, IUnitOfWorkFactory workFactory, IRepositoryOrchestration orchestration, IRepositoryMediator repository, IntegrateBranchesOrchestration integrateBranches, IBranchIterationMediator branchIteration, string downstreamBranch, IOptions <GitRepositoryOptions> options, IMergeStrategyManager strategyManager)
 {
     this.cli                   = cli;
     this.gitServiceApi         = gitServiceApi;
     this.integrateBranches     = integrateBranches;
     this.repository            = repository;
     this.orchestration         = orchestration;
     this.branchIteration       = branchIteration;
     this.downstreamBranchGroup = downstreamBranch;
     this.detailsTask           = repository.GetBranchDetails(downstreamBranch).FirstAsync().ToTask();
     this.latestBranchName      = detailsTask.ContinueWith(task => repository.LatestBranchName(task.Result).FirstOrDefaultAsync().ToTask()).Unwrap();
     this.strategyTask          = detailsTask.ContinueWith(task => strategyManager.GetMergeStrategy(task.Result));
     this.isReadOnly            = options.Value.ReadOnly;
     this.workFactory           = workFactory;
 }
コード例 #3
0
            protected override async Task RunProcess()
            {
                var targetBranch = await repository.GetBranchDetails(newBaseBranch).FirstOrDefaultAsync();

                // 1. make sure everything is already merged
                // 2. run consolidate branches SQL
                // 3. delete old branches
                ImmutableList <BranchGroupCompleteData> branchesToRemove = await GetBranchesToRemove(targetBranch);

                if (await MergesInProgress(targetBranch, branchesToRemove))
                {
                    // abort, but queue another attempt
#pragma warning disable CS4014
                    orchestration.EnqueueAction(new ConsolidateMergedAction(sourceBranch: sourceBranch, newBaseBranch: newBaseBranch), skipDuplicateCheck: true);
#pragma warning restore
                    await AppendMessage($"Merges were still in queue, deferring consolidation to {newBaseBranch} from {sourceBranch}.", isError : true);

                    return;
                }
                await AppendMessage($"Consolidating to {newBaseBranch} from {sourceBranch}, removing: {string.Join(", ", branchesToRemove.Select(b => b.GroupName))}.", isError : true);

                // Integration branches remain separate. Even if they have one
                // parent, multiple things could depend on them and you don't
                // want to flatten out those commits too early.
                using (var unitOfWork = workFactory.CreateUnitOfWork())
                {
                    repository.ConsolidateBranches(branchesToRemove.Select(b => b.GroupName), targetBranch.GroupName, unitOfWork);

                    await unitOfWork.CommitAsync();
                }

                // TODO - branches could get deleted here that were ignored in the `ConsolidateBranches` logic.
                await(from branch in branchesToRemove.ToObservable()
                      from actualBranch in branch.Branches
                      from entry in AppendProcess(cli.DeleteRemote(actualBranch.Name)).WaitUntilComplete().ContinueWith <int>((t) => 0)
                      select entry);

                repository.CheckForUpdates();
            }
コード例 #4
0
            protected override async Task RunProcess()
            {
                if (isReadOnly)
                {
                    return;
                }

                // either:
                // 1. create new service line from release candidate
                // 2. merge --ff-only from release candidate to service line

                // if it passes:
                //   collect upstream branches
                //   push service line

                var upstreamLines = await repository.DetectShallowUpstreamServiceLines(releaseCandidateBranch).FirstOrDefaultAsync();

                var disposable = new CompositeDisposable();

                var readyToFinalize = await CreateOrFastForwardServiceLine(releaseCandidateBranch, repository, cli);

                if (!readyToFinalize)
                {
                    await AppendMessage($"{serviceLineBranch} unable to be fast-forwarded from {releaseCandidateBranch}; aborting", isError : true);
                }
                else
                {
                    if (!string.IsNullOrEmpty(tagName))
                    {
                        await AppendProcess(cli.AnnotatedTag(tagName, $"Automated release to service line {serviceLineBranch} from {releaseCandidateBranch}")).WaitUntilComplete();
                    }

                    var serviceLine = await settings.GetBranchBasicDetails(serviceLineBranch).FirstOrDefaultAsync();

                    // possible TODO for the future: give option to add missing upstream lines always
                    if (serviceLine == null)
                    {
                        // We need to set it up as a service line
                        using (var work = unitOfWorkFactory.CreateUnitOfWork())
                        {
                            settings.UpdateBranchSetting(serviceLineBranch, UpstreamMergePolicy.None, BranchGroupType.ServiceLine, work);
                            foreach (var upstreamServiceLine in upstreamLines)
                            {
                                settings.AddBranchPropagation(upstreamServiceLine, serviceLineBranch, work);
                            }

                            await work.CommitAsync();
                        }
                    }

                    if (autoConsolidate)
                    {
                        var consolidating = (await repository.GetBranchDetails(releaseCandidateBranch).FirstOrDefaultAsync()).UpstreamBranchGroups;
                        foreach (var upstreamServiceLine in upstreamLines)
                        {
                            var upstreamDetails = await repository.GetBranchDetails(upstreamServiceLine).FirstOrDefaultAsync();

                            consolidating = consolidating.Except(upstreamDetails.UpstreamBranchGroups).Except(new[] { upstreamServiceLine }).ToImmutableList();
                        }
                        var releasedCandidate = await settings.GetConfiguredBranches().Select(branches => branches.Find(branch => branchIteration.IsBranchIteration(branch.GroupName, releaseCandidateBranch)).GroupName).FirstOrDefaultAsync();

#pragma warning disable CS4014
                        orchestration.EnqueueAction(new ConsolidateMergedAction(releasedCandidate, serviceLineBranch));
#pragma warning restore
                    }

                    if (!string.IsNullOrEmpty(tagName))
                    {
                        await AppendProcess(cli.Push(tagName)).WaitUntilComplete();
                    }

                    await AppendProcess(cli.Push(serviceLineBranch)).WaitUntilComplete();
                }
            }