Exemple #1
0
        private async Task <ReleaseDefinitions> GetReleaseDefinitionsAsync()
        {
            var jsonText = await ExecuteJsonAsync(String.Format("https://vsrm.dev.azure.com/{0}/{1}/_apis/release/definitions", _config.GetValue <string>("AzureDevOps:Organisation"), _config.GetValue <string>("AzureDevOps:ProjectName")));

            ReleaseDefinitions rDef = JsonConvert.DeserializeObject <ReleaseDefinitions>(jsonText);

            return(rDef);
        }
Exemple #2
0
        public static async Task <ReleaseDefinitions> GetReleaseDefinitionsAsync()
        {
            try
            {
                var jsonText = await ExecuteJsonAsync(String.Format("https://vsrm.dev.azure.com/{0}/{1}/_apis/release/definitions", Properties.Settings.Default.Organisation, Properties.Settings.Default.ProjectName));

                ReleaseDefinitions rDef = JsonConvert.DeserializeObject <ReleaseDefinitions>(jsonText);
                return(rDef);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw;
            }
        }
Exemple #3
0
        private async Task <List <string> > ReleasesThatUseVariableGroupAsync(int variableGroupId)
        {
            List <string> releases = new List <string>();

            ReleaseDefinitions releaseDefinitions = await GetReleaseDefinitionsAsync();

            foreach (var releaseDefinition in releaseDefinitions.value)
            {
                Release release = await GetRelease(releaseDefinition.id);

                if (release.variableGroups != null)
                {
                    foreach (var variablegroupId in release.variableGroups)
                    {
                        if (variablegroupId == variableGroupId)
                        {
                            releases.Add(release.name);
                            break;
                        }
                    }
                }

                foreach (VariableGroupUsage.Models.Environment environment in release.environments)
                {
                    foreach (int variableGroup in environment.variableGroups)
                    {
                        if (variableGroup == variableGroupId)
                        {
                            releases.Add(String.Format("{0} ({1})", release.name, environment.name));
                            break;
                        }
                    }
                }
            }

            if (releases.Count > 0)
            {
                return(releases);
            }
            else
            {
                return(null);
            }
        }
Exemple #4
0
        public static void Main(string[] args)
        {
            string PAT         = string.Empty;
            string accountName = string.Empty;
            string projectName = string.Empty;

            Console.WriteLine("Please enter Account Name");
            accountName = Console.ReadLine();

            Console.WriteLine("Please enter Personal access token");
            PAT = Console.ReadLine();

            Console.WriteLine("Please enter project name");
            projectName = Console.ReadLine();

            Configuration sourceconfig = new Configuration()
            {
                UriString = "https://" + accountName + ".visualstudio.com:", PersonalAccessToken = PAT, Project = projectName
            };

            VstsRestAPI.Configuration vstsAPIConfiguration = new VstsRestAPI.Configuration()
            {
                UriString = "https://" + accountName + ".visualstudio.com:", PersonalAccessToken = PAT, Project = projectName
            };

            ValidateLogin objLogin       = new ValidateLogin(vstsAPIConfiguration);
            bool          isValidAccount = objLogin.isValidAccount();

            if (isValidAccount)
            {
                Console.WriteLine("Generating templates....");
                Console.WriteLine();

                ExportQueries objQuery = new ExportQueries(vstsAPIConfiguration);
                //queryList = objQuery.GetQueries(projectName);
                objQuery.GetQueriesByPath(projectName, string.Empty);

                ExportDashboards objWidgetAndCharts = new ExportDashboards(vstsAPIConfiguration);
                objWidgetAndCharts.GetDashboard(projectName);
                Console.WriteLine("Queries and Dashboard JSONs are saved into Template folder");
                Console.WriteLine("");

                Teams objTeam = new Teams(vstsAPIConfiguration);
                objTeam.ExportTeams(projectName);
                Console.WriteLine("Teams JSON is saved into Template folder");
                Console.WriteLine("");

                SourceCode objSourceCode = new SourceCode(vstsAPIConfiguration);
                objSourceCode.ExportSourceCode(projectName);
                Console.WriteLine("ImportSourceCode JSON is saved into Template folder");
                Console.WriteLine("");

                BoardColumns objColumn = new BoardColumns(vstsAPIConfiguration);
                objColumn.ExportBoardColumns(projectName);
                Console.WriteLine("BoardColumn JSON file is saved into Template folder");
                Console.WriteLine("");

                GenerateWIFromSource wiql = new GenerateWIFromSource(sourceconfig, accountName);
                wiql.UpdateWorkItem();
                Console.WriteLine("Work item JSON files are saved into Templates folder");
                Console.WriteLine("");

                BuildDefinitions   objBuild   = new BuildDefinitions(vstsAPIConfiguration, accountName);
                ReleaseDefinitions objRelease = new ReleaseDefinitions(vstsAPIConfiguration, accountName);
                objBuild.ExportBuildDefinitions(projectName);
                objRelease.ExportReleaseDefinitions(projectName);
                Console.WriteLine("Build and Release Definitions are saved into Templates folder");
                Console.WriteLine("");

                CardFieldsAndCardStyles objCards = new CardFieldsAndCardStyles(vstsAPIConfiguration);
                objCards.GetCardFields(projectName);
                objCards.GetCardStyles(projectName);
                Console.WriteLine("CardField and CardStyle JSON files are saved into Templates folder");
                Console.WriteLine("");

                PullRequests objPullRequest = new PullRequests(vstsAPIConfiguration);
                objPullRequest.ExportPullRequests(projectName);
                Console.WriteLine("PullReqests and comments JSON files are saved into Templates folder");
                Console.WriteLine("");

                Console.WriteLine("Completed generating templates from " + projectName);
                var wait = Console.ReadLine();
            }
            else
            {
                Console.WriteLine("");
                Console.WriteLine("Invalid Account name or PAT, re-run the application and try again!");
                var wait = Console.ReadLine();
            }
        }
Exemple #5
0
        public static async Task GetUnusedVariableGroups()
        {
            VariableGroups vGroups = await GetVariableGroupsAsync();

            ReleaseDefinitions releaseDefinitions = await GetReleaseDefinitionsAsync();

            List <VariableGroupsValue> groups = vGroups.value;
            List <int> usedGroups             = new List <int>();

            foreach (ReleaseDefinition rDef in releaseDefinitions.value)
            {
                Release release = await GetRelease(rDef.id);

                foreach (int variablegroupId in release.variableGroups)
                {
                    var g = groups.Find(x => x.id == variablegroupId);
                    if (g == null)
                    {
                        Console.WriteLine(string.Format("{0} is referencing a deleted variable group (id-{1})", rDef.name, variablegroupId));
                    }
                    else
                    {
                        usedGroups.Add(variablegroupId);
                    }
                }
                foreach (Environment environment in release.environments)
                {
                    foreach (int variablegroupId in environment.variableGroups)
                    {
                        var g = groups.Find(x => x.id == variablegroupId);
                        if (g == null)
                        {
                            Console.WriteLine(string.Format("{0} is referencing a deleted variable group (id-{1})", rDef.name, variablegroupId));
                        }
                        else
                        {
                            usedGroups.Add(variablegroupId);
                        }
                    }
                }
            }

            BuildDefinitions buildDefinitions = await GetBuildDefinitionsAsync();

            foreach (var buildDefinition in buildDefinitions.value)
            {
                Build build = await GetBuild(buildDefinition.id);

                if (build.variableGroups != null)
                {
                    foreach (VariableGroup variablegroup in build.variableGroups)
                    {
                        var g = groups.Find(x => x.id == variablegroup.id);
                        if (g == null)
                        {
                            Console.WriteLine(string.Format("{0} is referencing a deleted variable group (id-{1})", buildDefinition.name, variablegroup.id));
                        }
                        else
                        {
                            usedGroups.Add(variablegroup.id);
                        }
                    }
                }
            }

            bool used;

            foreach (var variableGroup in vGroups.value)
            {
                used = false;
                foreach (var usedGroup in usedGroups)
                {
                    if (variableGroup.id == usedGroup)
                    {
                        used = true;
                    }
                }
                if (used == false)
                {
                    Console.WriteLine(String.Format("'{0}' is not used - id {1}", variableGroup.name, variableGroup.id));
                }
            }
        }
Exemple #6
0
        public static void Main(string[] args)
        {
            string PAT         = string.Empty;
            string accountName = string.Empty;
            string projectName = string.Empty;

            Console.WriteLine("Please enter Account Name");
            accountName = Console.ReadLine();

            Console.WriteLine("Please enter Personel access token");
            PAT = Console.ReadLine();

            Console.WriteLine("Please enter project name");
            projectName = Console.ReadLine();


            Configuration sourceconfig = new Configuration()
            {
                UriString = "https://" + accountName + ".visualstudio.com:", PersonalAccessToken = PAT, Project = projectName
            };

            VstsRestAPI.Configuration vstsAPIConfiguration = new VstsRestAPI.Configuration()
            {
                UriString = "https://" + accountName + ".visualstudio.com:", PersonalAccessToken = PAT, Project = projectName
            };

            Console.WriteLine("Generating templates....");
            Console.WriteLine();


            Dictionary <string, string> queryList = new Dictionary <string, string>();
            ExportQueries objQuery = new ExportQueries(vstsAPIConfiguration);

            //queryList = objQuery.GetQueries(projectName);
            queryList = objQuery.GetQueriesByPath(projectName, string.Empty);

            ExportWidgetsAndCharts objWidgetAndCharts = new ExportWidgetsAndCharts(vstsAPIConfiguration);

            objWidgetAndCharts.GetWidgetsAndCharts(projectName, queryList);
            Console.WriteLine("Queries and widget JSONs are saved into Template folder");
            Console.WriteLine("");


            Teams objTeam = new Teams(vstsAPIConfiguration);

            objTeam.ExportTeams(projectName);
            Console.WriteLine("Teams JSON is saved into Template folder");
            Console.WriteLine("");

            ServiceEndpoints objService = new ServiceEndpoints(vstsAPIConfiguration);

            string serviceEndPoint = string.Empty;

            serviceEndPoint = objService.ExportServiceEndPoints(projectName);
            Console.WriteLine("ServiceEndPoint JSONs are saved into Template folder");
            Console.WriteLine("");

            SourceCode objSourceCode = new SourceCode(vstsAPIConfiguration);

            objSourceCode.ExportSourceCode(projectName);
            Console.WriteLine("ImportSourceCode JSON is saved into Template folder");
            Console.WriteLine("");

            BoardColumns objColumn = new BoardColumns(vstsAPIConfiguration);

            objColumn.ExportBoardColumns(projectName);
            Console.WriteLine("BoardColumn JSON file is saved into Template folder");
            Console.WriteLine("");

            GenerateWIFromSource wiql = new GenerateWIFromSource(sourceconfig, accountName);

            wiql.UpdateWorkItem();
            Console.WriteLine("Work item JSON files are saved into Templates folder");
            Console.WriteLine("");

            BuildDefinitions   objBuild   = new BuildDefinitions(vstsAPIConfiguration, accountName);
            ReleaseDefinitions objRelease = new ReleaseDefinitions(vstsAPIConfiguration, accountName);

            objBuild.ExportBuildDefinitions(projectName);
            objRelease.ExportReleaseDefinitions(projectName, serviceEndPoint);
            Console.WriteLine("Build and Release Definitions are saved into Templates folder");
            Console.WriteLine("");

            CardFieldsAndCardStyles objCards = new CardFieldsAndCardStyles(vstsAPIConfiguration);

            objCards.GetCardFields(projectName);
            objCards.GetCardStyles(projectName);
            Console.WriteLine("CardField and CardStyle JSON files are saved into Templates folder");
            Console.WriteLine("");

            Iterations objIterations = new Iterations(vstsAPIConfiguration, accountName);

            objIterations.GetIterations();
            Console.WriteLine("iterations JSON file is saved into Templates folder");
            Console.WriteLine("");

            PullRequests objPullRequest = new PullRequests(vstsAPIConfiguration);

            objPullRequest.ExportPullRequests(projectName);
            Console.WriteLine("PullReqests and comments JSON files are saved into Templates folder");
            Console.WriteLine("");

            Console.WriteLine("Completed generating templates from " + projectName);
            var wait = Console.ReadLine();
        }
Exemple #7
0
        /// <summary>
        /// project new state onto the current instance
        /// </summary>
        /// <param name="newState">new intended state</param>
        /// <param name="environments">list of environments to provision to</param>
        public void Update(Tenant newState, IEnumerable <DeploymentEnvironment> environments)
        {
            if (newState == null)
            {
                return;
            }

            Name       = newState.Name;
            TenantSize = newState.TenantSize;

            var newStateForks = newState.SourceRepos.Select(r => new SourceCodeRepository(r.SourceRepositoryName, Code, r.ProjectType, r.Fork)).ToList();

            //update forks and build definitions (1:1) - additions and removals
            newStateForks
            .Except(SourceRepos, ForkEqComparer)
            .ToList()
            .ForEach(f =>
            {
                f.TenantCode = Code;
                SourceRepos.Add(f);
                var bd = new VstsBuildDefinition(f, Code);
                BuildDefinitions.Add(bd);

                //for canary, no PROD env in non prod release pipeline
                var standardPipeline = new VstsReleaseDefinition(bd, Code, TenantSize, false)
                {
                    SkipEnvironments = !f.Fork ? new[] { DeploymentEnvironment.Prod } : new DeploymentEnvironment[] { }
                };
                ReleaseDefinitions.Add(standardPipeline);

                if (f.Fork)
                {
                    return;
                }

                //also initiate ring pipeline (if not fork)
                var ringPipeline = new VstsReleaseDefinition(bd, Code, TenantSize, true);
                ReleaseDefinitions.Add(ringPipeline);
            });

            SourceRepos
            .Except(newStateForks, ForkEqComparer)
            .ToList()
            .ForEach(f =>
            {
                f.State  = EntityStateEnum.ToBeDeleted;
                var bd   = BuildDefinitions.Single(b => Equals(b.SourceCode, f));
                bd.State = EntityStateEnum.ToBeDeleted;
                bd.ReleaseDefinitions.ForEach(d => d.State = EntityStateEnum.ToBeDeleted);
            });

            var environmentList = environments.ToList();

            if (!ResourceGroups.Any())
            {
                foreach (var environmentName in environmentList)
                {
                    // TODO: validate that the list of resource groups and their names
                    ResourceGroups.Add(new ResourceGroup(Code, environmentName, $"checkout-{Code}-{environmentName}"));
                }
            }

            if (!ManagedIdentities.Any())
            {
                foreach (var environmentName in environmentList)
                {
                    // TODO: validate the list of created managed identities and their names
                    ManagedIdentities.Add(new ManagedIdentity
                    {
                        TenantCode        = Code,
                        Environment       = environmentName,
                        IdentityName      = $"{Code}-{environmentName}",
                        ResourceGroupName = $"checkout-{Code}-{environmentName}",
                    });
                }
            }
        }