Exemple #1
0
        private async Task <EnvironmentDeployment> GenerateDeployment(OctoPlusCore.Models.Environment environment, OctoPlusCore.Models.Environment targetEnvironment, List <Project> projects,
                                                                      List <Project> targetProjects)
        {
            var deploymentOk = false;
            EnvironmentDeployment deployment;

            do
            {
                deployment = InteractivePrompt(environment, targetEnvironment, projects, targetProjects);
                if (deployment == null)
                {
                    return(deployment);
                }

                var result = await this.deployer.CheckDeployment(deployment);

                if (result.Success)
                {
                    deploymentOk = true;
                }
                else
                {
                    System.Console.WriteLine(languageProvider.GetString(LanguageSection.UiStrings, "Error") + result.ErrorMessage);
                }
            } while (!deploymentOk);

            FillRequiredVariables(deployment.ProjectDeployments);

            return(deployment);
        }
Exemple #2
0
        private async Task <List <Project> > ConvertProjectStubsToProjects(List <ProjectStub> projectStubs, string groupRestriction, List <string> groupIds,
                                                                           OctoPlusCore.Models.Environment environment, Channel channel, Channel defaultChannel)
        {
            var projects = new List <Project>();

            foreach (var projectStub in projectStubs)
            {
                progressBar.WriteProgress(projectStubs.IndexOf(projectStub) + 1, projectStubs.Count(),
                                          String.Format(languageProvider.GetString(LanguageSection.UiStrings, "LoadingInfoFor"), projectStub.ProjectName));
                if (!string.IsNullOrEmpty(groupRestriction))
                {
                    if (!groupIds.Contains(projectStub.ProjectGroupId))
                    {
                        continue;
                    }
                }

                var project = await octoHelper.ConvertProject(projectStub, environment.Id, channel.VersionRange, channel.VersionTag);

                var currentPackages = project.CurrentRelease.SelectedPackages;
                project.Checked = false;
                if (project.SelectedPackageStubs != null)
                {
                    foreach (var package in project.AvailablePackages)
                    {
                        var stub = package.SelectedPackage;
                        if (stub == null)
                        {
                            if (defaultChannel != null)
                            {
                                project = await octoHelper.ConvertProject(projectStub, environment.Id, defaultChannel.VersionRange, defaultChannel.VersionTag);

                                stub = project.AvailablePackages.FirstOrDefault(p => p.StepId == package.StepId).SelectedPackage;
                            }
                        }
                        var matchingCurrent = currentPackages.FirstOrDefault(p => p.StepId == package.StepId);
                        if (matchingCurrent != null && stub != null)
                        {
                            project.Checked = matchingCurrent.Version != stub.Version;
                            break;
                        }
                        else
                        {
                            if (stub == null)
                            {
                                project.Checked = false;
                            }
                            project.Checked = true;
                            break;
                        }
                    }
                }

                projects.Add(project);
            }

            return(projects);
        }
Exemple #3
0
        private EnvironmentDeployment InteractivePrompt(OctoPlusCore.Models.Environment environment, OctoPlusCore.Models.Environment targetEnvironment, IList <Project> projects, IList <Project> targetProjects)
        {
            InteractiveRunner runner = PopulateRunner(String.Format(languageProvider.GetString(LanguageSection.UiStrings, "PromotingTo"), environment.Name, targetEnvironment.Name), projects, targetProjects);
            var indexes = runner.GetSelectedIndexes();

            if (!indexes.Any())
            {
                System.Console.WriteLine(languageProvider.GetString(LanguageSection.UiStrings, "NothingSelected"));
                return(null);
            }

            var deployment = new EnvironmentDeployment
            {
                ChannelName     = string.Empty,
                DeployAsync     = true,
                EnvironmentId   = targetEnvironment.Id,
                EnvironmentName = targetEnvironment.Name
            };

            foreach (var index in indexes)
            {
                var current       = projects[index];
                var currentTarget = targetProjects[index];

                if (current.CurrentRelease != null)
                {
                    deployment.ProjectDeployments.Add(new ProjectDeployment
                    {
                        ProjectId   = currentTarget.ProjectId,
                        ProjectName = currentTarget.ProjectName,
                        LifeCycleId = currentTarget.LifeCycleId,
                        ReleaseId   = current.CurrentRelease.Id
                    });
                }
            }

            return(deployment);
        }
Exemple #4
0
        private async Task <EnvironmentDeployment> PrepareEnvironmentDeployment(Channel channel, Channel defaultChannel, OctoPlusCore.Models.Environment environment, IList <Project> projects, IEnumerable <int> indexes = null, bool all = false)
        {
            var deployment = new EnvironmentDeployment
            {
                ChannelName     = channel.Name,
                DeployAsync     = true,
                EnvironmentId   = environment.Id,
                EnvironmentName = environment.Name
            };

            if (all)
            {
                foreach (var project in projects)
                {
                    if (project.AvailablePackages.Any())
                    {
                        deployment.ProjectDeployments.Add(await GenerateProjectDeployment(channel, defaultChannel, project));
                    }
                }
            }
            else
            {
                foreach (var index in indexes)
                {
                    var current = projects[index];

                    if (current.AvailablePackages.Any())
                    {
                        deployment.ProjectDeployments.Add(await GenerateProjectDeployment(channel, defaultChannel, current));
                    }
                }
            }

            return(deployment);
        }
Exemple #5
0
        private async Task <EnvironmentDeployment> InteractivePrompt(Channel channel, Channel defaultChannel, OctoPlusCore.Models.Environment environment, IList <Project> projects)
        {
            InteractiveRunner runner = PopulateRunner(String.Format(languageProvider.GetString(LanguageSection.UiStrings, "DeployingTo"), channel.Name, environment.Name), languageProvider.GetString(LanguageSection.UiStrings, "PackageNotSelectable"), projects);
            var indexes = runner.GetSelectedIndexes();

            if (!indexes.Any())
            {
                System.Console.WriteLine(languageProvider.GetString(LanguageSection.UiStrings, "NothingSelected"));
                return(null);
            }

            var deployment = await PrepareEnvironmentDeployment(channel, defaultChannel, environment, projects, indexes);

            return(deployment);
        }
Exemple #6
0
        private async Task <EnvironmentDeployment> GenerateDeployment(Channel channel, Channel defaultChannel, OctoPlusCore.Models.Environment environment, List <Project> projects, bool fallbackToDefaultChannel)
        {
            EnvironmentDeployment deployment;

            if (this.InInteractiveMode)
            {
                bool deploymentOk;
                do
                {
                    deployment = await InteractivePrompt(channel, defaultChannel, environment, projects);

                    deploymentOk = await ValidateDeployment(deployment, deployer);
                } while (!deploymentOk);
            }
            else
            {
                deployment = await PrepareEnvironmentDeployment(channel, defaultChannel, environment, projects, all : true);

                if (!await ValidateDeployment(deployment, deployer))
                {
                    return(null);
                }
            }

            var releaseName = PromptForReleaseName();

            if (!string.IsNullOrEmpty(releaseName))
            {
                foreach (var project in deployment.ProjectDeployments)
                {
                    project.ReleaseVersion = releaseName;
                }
            }

            FillRequiredVariables(deployment.ProjectDeployments);

            deployment.FallbackToDefaultChannel = fallbackToDefaultChannel;

            return(deployment);
        }
Exemple #7
0
        private async Task <(List <Project> projects, List <Project> targetProjects)> GenerateProjectList(List <ProjectStub> projectStubs, string groupRestriction, List <string> groupIds, OctoPlusCore.Models.Environment environment,
                                                                                                          OctoPlusCore.Models.Environment targetEnvironment)
        {
            var projects       = new List <Project>();
            var targetProjects = new List <Project>();

            foreach (var projectStub in projectStubs)
            {
                progressBar.WriteProgress(projectStubs.IndexOf(projectStub) + 1, projectStubs.Count(),
                                          String.Format(languageProvider.GetString(LanguageSection.UiStrings, "LoadingInfoFor"), projectStub.ProjectName));
                if (!string.IsNullOrEmpty(groupRestriction))
                {
                    if (!groupIds.Contains(projectStub.ProjectGroupId))
                    {
                        continue;
                    }
                }

                var project = await octoHelper.ConvertProject(projectStub, environment.Id, null, null);

                var targetProject = await octoHelper.ConvertProject(projectStub, targetEnvironment.Id, null, null);

                var currentRelease       = project.CurrentRelease;
                var currentTargetRelease = targetProject.CurrentRelease;
                if (currentRelease == null)
                {
                    continue;
                }

                if (currentTargetRelease != null && currentTargetRelease.Id == currentRelease.Id)
                {
                    project.Checked = false;
                }
                else
                {
                    project.Checked = true;
                }

                projects.Add(project);
                targetProjects.Add(targetProject);
            }

            return(projects, targetProjects);
        }