Пример #1
0
        public async Task <IActionResult> DeploymentFrequency()
        {
            //TODO: Move variables to a configuration file or database
            int    maxNumberOfItems = 20;
            int    numberOfDays     = 60;
            bool   getSampleData    = false;
            bool   useCache         = true;
            string patToken         = Configuration["AppSettings:AzureDevOpsPatToken"];
            string clientId         = Configuration["AppSettings:GitHubClientId"];
            string clientSecret     = Configuration["AppSettings:GitHubClientSecret"];

            ServiceApiClient serviceApiClient     = new ServiceApiClient(Configuration);
            List <DeploymentFrequencyModel> items = new List <DeploymentFrequencyModel>();

            //Get a list of settings
            List <AzureDevOpsSettings> azureDevOpsSettings = await serviceApiClient.GetAzureDevOpsSettings();

            List <GitHubSettings> githubSettings = await serviceApiClient.GetGitHubSettings();

            //Create deployment frequency models from each setting object
            foreach (AzureDevOpsSettings item in azureDevOpsSettings)
            {
                DeploymentFrequencyModel newDeploymentFrequencyModel = await serviceApiClient.GetAzureDevOpsDeploymentFrequency(getSampleData, patToken,
                                                                                                                                item.Organization, item.Project, item.Branch, item.BuildName, item.BuildId,
                                                                                                                                numberOfDays, maxNumberOfItems, useCache);

                newDeploymentFrequencyModel.ItemOrder = item.ItemOrder;
                if (newDeploymentFrequencyModel != null)
                {
                    items.Add(newDeploymentFrequencyModel);
                }
            }
            foreach (GitHubSettings item in githubSettings)
            {
                DeploymentFrequencyModel newDeploymentFrequencyModel = await serviceApiClient.GetGitHubDeploymentFrequency(getSampleData, clientId, clientSecret,
                                                                                                                           item.Owner, item.Repo, item.Branch, item.WorkflowName, item.WorkflowId,
                                                                                                                           numberOfDays, maxNumberOfItems, useCache);

                newDeploymentFrequencyModel.ItemOrder = item.ItemOrder;
                if (newDeploymentFrequencyModel != null)
                {
                    items.Add(newDeploymentFrequencyModel);
                }
            }

            //sort the list
            items = items.OrderBy(o => o.ItemOrder).ToList();
            return(View(items));
        }
Пример #2
0
        public async Task <IActionResult> Project(string rowKey, int numberOfDays = 30)
        {
            int              maxNumberOfItems = 20;
            bool             getSampleData    = false;
            bool             useCache         = true;
            string           patToken         = Configuration["AppSettings:AzureDevOpsPatToken"];
            string           clientId         = Configuration["AppSettings:GitHubClientId"];
            string           clientSecret     = Configuration["AppSettings:GitHubClientSecret"];
            ProjectViewModel model            = new ProjectViewModel();

            //Find the right project to load
            ServiceApiClient           serviceApiClient    = new ServiceApiClient(Configuration);
            List <AzureDevOpsSettings> azureDevOpsSettings = await serviceApiClient.GetAzureDevOpsSettings();

            List <GitHubSettings> githubSettings = await serviceApiClient.GetGitHubSettings();

            //Create the days to view dropdown
            List <NumberOfDaysItem> numberOfDaysList = new List <NumberOfDaysItem>
            {
                new NumberOfDaysItem {
                    NumberOfDays = 7
                },
                new NumberOfDaysItem {
                    NumberOfDays = 14
                },
                new NumberOfDaysItem {
                    NumberOfDays = 21
                },
                new NumberOfDaysItem {
                    NumberOfDays = 30
                },
                new NumberOfDaysItem {
                    NumberOfDays = 60
                },
                new NumberOfDaysItem {
                    NumberOfDays = 90
                }
            };

            //Get Azure DevOps project details
            AzureDevOpsSettings azureDevOpsSetting;

            foreach (AzureDevOpsSettings item in azureDevOpsSettings)
            {
                if (item.RowKey == rowKey)
                {
                    azureDevOpsSetting = item;

                    DeploymentFrequencyModel deploymentFrequencyModel = await serviceApiClient.GetAzureDevOpsDeploymentFrequency(getSampleData, patToken,
                                                                                                                                 item.Organization, item.Project, item.Branch, item.BuildName, item.BuildId,
                                                                                                                                 numberOfDays, maxNumberOfItems, useCache);

                    LeadTimeForChangesModel leadTimeForChangesModel = await serviceApiClient.GetAzureDevOpsLeadTimeForChanges(getSampleData, patToken,
                                                                                                                              item.Organization, item.Project, item.Repository, item.Branch, item.BuildName, item.BuildId,
                                                                                                                              numberOfDays, maxNumberOfItems, useCache);

                    MeanTimeToRestoreModel meanTimeToRestoreModel = await serviceApiClient.GetAzureMeanTimeToRestore(getSampleData,
                                                                                                                     DevOpsPlatform.AzureDevOps, item.ProductionResourceGroup, numberOfDays, maxNumberOfItems);

                    ChangeFailureRateModel changeFailureRateModel = await serviceApiClient.GetChangeFailureRate(getSampleData,
                                                                                                                DevOpsPlatform.AzureDevOps, item.Organization, item.Project, item.Branch, item.BuildName,
                                                                                                                numberOfDays, maxNumberOfItems);

                    deploymentFrequencyModel.IsProjectView = true;
                    leadTimeForChangesModel.IsProjectView  = true;
                    meanTimeToRestoreModel.IsProjectView   = true;
                    changeFailureRateModel.IsProjectView   = true;
                    model = new ProjectViewModel
                    {
                        RowKey               = item.RowKey,
                        ProjectName          = item.Project,
                        TargetDevOpsPlatform = DevOpsPlatform.AzureDevOps,
                        DeploymentFrequency  = deploymentFrequencyModel,
                        LeadTimeForChanges   = leadTimeForChangesModel,
                        MeanTimeToRestore    = meanTimeToRestoreModel,
                        ChangeFailureRate    = changeFailureRateModel,
                        NumberOfDays         = new SelectList(numberOfDaysList, "NumberOfDays", "NumberOfDays"),
                        NumberOfDaysSelected = numberOfDays
                    };
                }
            }
            //Get GitHub project details
            GitHubSettings githubSetting;

            foreach (GitHubSettings item in githubSettings)
            {
                if (item.RowKey == rowKey)
                {
                    githubSetting = item;

                    DeploymentFrequencyModel deploymentFrequencyModel = await serviceApiClient.GetGitHubDeploymentFrequency(getSampleData, clientId, clientSecret,
                                                                                                                            item.Owner, item.Repo, item.Branch, item.WorkflowName, item.WorkflowId,
                                                                                                                            numberOfDays, maxNumberOfItems, useCache);

                    LeadTimeForChangesModel leadTimeForChangesModel = await serviceApiClient.GetGitHubLeadTimeForChanges(getSampleData, clientId, clientSecret,
                                                                                                                         item.Owner, item.Repo, item.Branch, item.WorkflowName, item.WorkflowId,
                                                                                                                         numberOfDays, maxNumberOfItems, useCache);

                    MeanTimeToRestoreModel meanTimeToRestoreModel = await serviceApiClient.GetAzureMeanTimeToRestore(getSampleData,
                                                                                                                     DevOpsPlatform.GitHub, item.ProductionResourceGroup, numberOfDays, maxNumberOfItems);

                    ChangeFailureRateModel changeFailureRateModel = await serviceApiClient.GetChangeFailureRate(getSampleData,
                                                                                                                DevOpsPlatform.GitHub, item.Owner, item.Repo, item.Branch, item.WorkflowName,
                                                                                                                numberOfDays, maxNumberOfItems);

                    deploymentFrequencyModel.IsProjectView = true;
                    leadTimeForChangesModel.IsProjectView  = true;
                    meanTimeToRestoreModel.IsProjectView   = true;
                    changeFailureRateModel.IsProjectView   = true;
                    model = new ProjectViewModel
                    {
                        RowKey               = item.RowKey,
                        ProjectName          = item.Repo,
                        TargetDevOpsPlatform = DevOpsPlatform.GitHub,
                        DeploymentFrequency  = deploymentFrequencyModel,
                        LeadTimeForChanges   = leadTimeForChangesModel,
                        MeanTimeToRestore    = meanTimeToRestoreModel,
                        ChangeFailureRate    = changeFailureRateModel,
                        NumberOfDays         = new SelectList(numberOfDaysList, "NumberOfDays", "NumberOfDays"),
                        NumberOfDaysSelected = numberOfDays
                    };
                }
            }

            return(View(model));
        }
Пример #3
0
        public async Task <IActionResult> DeploymentFrequency()
        {
            int    maxNumberOfItems = 20;   //20 is the optimium max that looks good with the current UI
            int    numberOfDays     = 60;   //TODO: Move number of days variable to a drop down list on the current UI
            bool   getSampleData    = false;
            bool   useCache         = true; //Use Azure storage instead of hitting the API. Quicker, but data may be up to 4 hours out of date
            string patToken         = Configuration["AppSettings:AzureDevOpsPatToken"];
            string clientId         = Configuration["AppSettings:GitHubClientId"];
            string clientSecret     = Configuration["AppSettings:GitHubClientSecret"];

            ServiceApiClient serviceApiClient     = new ServiceApiClient(Configuration);
            List <DeploymentFrequencyModel> items = new List <DeploymentFrequencyModel>();

            //Get a list of settings
            List <AzureDevOpsSettings> azureDevOpsSettings = await serviceApiClient.GetAzureDevOpsSettings();

            List <GitHubSettings> githubSettings = await serviceApiClient.GetGitHubSettings();

            //Create deployment frequency models from each Azure DevOps settings object
            foreach (AzureDevOpsSettings item in azureDevOpsSettings)
            {
                DeploymentFrequencyModel newDeploymentFrequencyModel = await serviceApiClient.GetAzureDevOpsDeploymentFrequency(getSampleData, patToken,
                                                                                                                                item.Organization, item.Project, item.Branch, item.BuildName, item.BuildId,
                                                                                                                                numberOfDays, maxNumberOfItems, useCache);

                newDeploymentFrequencyModel.ItemOrder = item.ItemOrder;
                if (newDeploymentFrequencyModel != null)
                {
                    items.Add(newDeploymentFrequencyModel);
                }
            }
            //Create deployment frequency models from each GitHub settings object
            foreach (GitHubSettings item in githubSettings)
            {
                DeploymentFrequencyModel newDeploymentFrequencyModel = await serviceApiClient.GetGitHubDeploymentFrequency(getSampleData, clientId, clientSecret,
                                                                                                                           item.Owner, item.Repo, item.Branch, item.WorkflowName, item.WorkflowId,
                                                                                                                           numberOfDays, maxNumberOfItems, useCache);

                newDeploymentFrequencyModel.ItemOrder = item.ItemOrder;
                if (newDeploymentFrequencyModel != null)
                {
                    items.Add(newDeploymentFrequencyModel);
                }
            }

            //Create the days to view dropdown
            List <NumberOfDaysItem> numberOfDaysList = new List <NumberOfDaysItem>
            {
                new NumberOfDaysItem {
                    NumberOfDays = 7
                },
                new NumberOfDaysItem {
                    NumberOfDays = 14
                },
                new NumberOfDaysItem {
                    NumberOfDays = 21
                },
                new NumberOfDaysItem {
                    NumberOfDays = 30
                },
                new NumberOfDaysItem {
                    NumberOfDays = 60
                },
                new NumberOfDaysItem {
                    NumberOfDays = 90
                }
            };

            //sort the final list
            items = items.OrderBy(o => o.ItemOrder).ToList();
            //return View(new ProjectViewModel
            //{
            //    DeploymentFrequency = items[0]
            //}
            //);
            return(View(items));
        }