public void DeploymentFrequencyFiveSevenDaysTest()
        {
            //Arrange
            DeploymentFrequency metrics = new DeploymentFrequency();
            int numberOfDays            = 7;
            List <KeyValuePair <DateTime, DateTime> > deploymentFrequencyList = new List <KeyValuePair <DateTime, DateTime> >
            {
                new KeyValuePair <DateTime, DateTime>(DateTime.Now, DateTime.Now),
                new KeyValuePair <DateTime, DateTime>(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1)),
                new KeyValuePair <DateTime, DateTime>(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(-2)),
                new KeyValuePair <DateTime, DateTime>(DateTime.Now.AddDays(-3), DateTime.Now.AddDays(-3)),
                new KeyValuePair <DateTime, DateTime>(DateTime.Now.AddDays(-4), DateTime.Now.AddDays(-4)),
                new KeyValuePair <DateTime, DateTime>(DateTime.Now.AddDays(-8), DateTime.Now.AddDays(-8)) //this record should be out of range, as it's older than 7 days
            };

            //Act
            float metric = metrics.ProcessDeploymentFrequency(deploymentFrequencyList, numberOfDays);
            DeploymentFrequencyModel model = new DeploymentFrequencyModel
            {
                DeploymentsPerDayMetric            = metric,
                DeploymentsPerDayMetricDescription = metrics.GetDeploymentFrequencyRating(metric)
            };

            //Assert
            Assert.IsTrue(model != null);
            Assert.AreEqual(0.7143f, model.DeploymentsPerDayMetric);
            Assert.AreEqual("High", model.DeploymentsPerDayMetricDescription);
            Assert.AreEqual(5.0000997f, model.DeploymentsToDisplayMetric);
            Assert.AreEqual("times per week", model.DeploymentsToDisplayUnit);
        }
        public void DeploymentFrequencySingleOneDayTest()
        {
            //Arrange
            DeploymentFrequency metrics = new DeploymentFrequency();
            int numberOfDays            = 1;
            List <KeyValuePair <DateTime, DateTime> > deploymentFrequencyList = new List <KeyValuePair <DateTime, DateTime> >
            {
                new KeyValuePair <DateTime, DateTime>(DateTime.Now, DateTime.Now)
            };

            //Act
            float metric = metrics.ProcessDeploymentFrequency(deploymentFrequencyList, numberOfDays);
            DeploymentFrequencyModel model = new DeploymentFrequencyModel
            {
                DeploymentsPerDayMetric            = metric,
                DeploymentsPerDayMetricDescription = metrics.GetDeploymentFrequencyRating(metric)
            };

            //Assert
            Assert.IsTrue(model != null);
            Assert.AreEqual(1f, model.DeploymentsPerDayMetric);
            Assert.AreEqual("High", model.DeploymentsPerDayMetricDescription);
            Assert.AreEqual(7, model.DeploymentsToDisplayMetric);
            Assert.AreEqual("times per week", model.DeploymentsToDisplayUnit);
        }
        public void DeploymentFrequencyNullOneDayTest()
        {
            //Arrange
            DeploymentFrequency metrics = new DeploymentFrequency();
            int numberOfDays            = 1;
            List <KeyValuePair <DateTime, DateTime> > deploymentFrequencyList = null;

            //Act
            float metric = metrics.ProcessDeploymentFrequency(deploymentFrequencyList, numberOfDays);
            DeploymentFrequencyModel model = new DeploymentFrequencyModel
            {
                DeploymentsPerDayMetric            = metric,
                DeploymentsPerDayMetricDescription = metrics.GetDeploymentFrequencyRating(metric),
                IsProjectView = true,
                ItemOrder     = 1,
                RateLimitHit  = false
            };

            //Assert
            Assert.IsTrue(model != null);
            Assert.AreEqual(0f, model.DeploymentsPerDayMetric);
            Assert.AreEqual("None", model.DeploymentsPerDayMetricDescription);
            Assert.AreEqual(0, model.DeploymentsToDisplayMetric);
            Assert.AreEqual("times per month", model.DeploymentsToDisplayUnit);
            Assert.AreEqual(true, model.IsProjectView);
            Assert.AreEqual(1, model.ItemOrder);
            Assert.AreEqual(false, model.RateLimitHit);
        }
        public async Task <DeploymentFrequencyModel> GetGitHubDeploymentFrequency(bool getSampleData, string clientId, string clientSecret,
                                                                                  string owner, string repo, string branch, string workflowName, string workflowId,
                                                                                  int numberOfDays, int maxNumberOfItems, bool useCache)
        {
            DeploymentFrequencyModel model = new DeploymentFrequencyModel();

            try
            {
                TableStorageAuth      tableStorageAuth = Common.GenerateTableAuthorization(Configuration);
                DeploymentFrequencyDA da = new DeploymentFrequencyDA();
                model = await da.GetGitHubDeploymentFrequency(getSampleData, clientId, clientSecret, tableStorageAuth, owner, repo, branch, workflowName, workflowId, numberOfDays, maxNumberOfItems, useCache);
            }
            catch (Exception ex)
            {
                if (ex.Message == "Response status code does not indicate success: 403 (rate limit exceeded).")
                {
                    model.DeploymentName = workflowName;
                    model.RateLimitHit   = true;
                }
                else
                {
                    throw;
                }
            }
            return(model);
        }
Example #5
0
        public async Task GHDeploymentFrequencyDAIntegrationTest()
        {
            //Arrange
            bool             getSampleData    = true;
            string           clientId         = Configuration["AppSettings:GitHubClientId"];
            string           clientSecret     = Configuration["AppSettings:GitHubClientSecret"];
            TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration);
            string           owner            = "samsmithnz";
            string           repo             = "DevOpsMetrics";
            string           branch           = "master";
            string           workflowName     = "DevOpsMetrics CI/CD";
            string           workflowId       = "1162561";
            int  numberOfDays     = 30;
            int  maxNumberOfItems = 20;
            bool useCache         = true;

            //Act
            DeploymentFrequencyDA    da    = new DeploymentFrequencyDA();
            DeploymentFrequencyModel model = await da.GetGitHubDeploymentFrequency(getSampleData, clientId, clientSecret, tableStorageAuth, owner, repo, branch, workflowName, workflowId, numberOfDays, maxNumberOfItems, useCache);

            //Assert
            Assert.IsTrue(model.DeploymentsPerDayMetric > 0f);
            Assert.AreEqual(false, string.IsNullOrEmpty(model.DeploymentsPerDayMetricDescription));
            Assert.AreNotEqual("Unknown", model.DeploymentsPerDayMetricDescription);
            Assert.AreEqual(10f, model.DeploymentsToDisplayMetric);
            Assert.AreEqual("per day", model.DeploymentsToDisplayUnit);
            Assert.AreEqual(numberOfDays, model.NumberOfDays);
            Assert.IsTrue(model.MaxNumberOfItems > 0);
            Assert.IsTrue(model.TotalItems > 0);
            Assert.IsTrue(model.IsProjectView == false);
            Assert.IsTrue(model.ItemOrder == 0);
        }
Example #6
0
        public async Task AzDeploymentsSampleControllerIntegrationTest()
        {
            //Arrange
            bool   getSampleData    = true;
            string patToken         = Configuration["AppSettings:AzureDevOpsPatToken"];
            string organization     = "samsmithnz";
            string project          = "SamLearnsAzure";
            string branch           = "refs/heads/master";
            string buildName        = "SamLearnsAzure.CI";
            int    numberOfDays     = 7;
            int    maxNumberOfItems = 20;
            bool   useCache         = false;
            DeploymentFrequencyController controller = new DeploymentFrequencyController(Configuration);

            //Act
            DeploymentFrequencyModel model = await controller.GetAzureDevOpsDeploymentFrequency(getSampleData, patToken, organization, project, branch, buildName, numberOfDays, maxNumberOfItems, useCache);

            //Assert
            Assert.AreEqual(DevOpsPlatform.AzureDevOps, model.TargetDevOpsPlatform);
            Assert.AreEqual(buildName, model.DeploymentName);
            Assert.AreEqual(10f, model.DeploymentsPerDayMetric);
            Assert.AreEqual("Elite", model.DeploymentsPerDayMetricDescription);
            Assert.AreEqual(10, model.BuildList.Count);
            Assert.AreEqual(70, model.BuildList[0].BuildDurationPercent);
            Assert.AreEqual("1", model.BuildList[0].BuildNumber);
            Assert.AreEqual("master", model.BuildList[0].Branch);
            Assert.AreEqual("completed", model.BuildList[0].Status);
            Assert.AreEqual("https://dev.azure.com/samsmithnz/samlearnsazure/1", model.BuildList[0].Url);
            Assert.IsTrue(model.BuildList[0].StartTime > DateTime.MinValue);
            Assert.IsTrue(model.BuildList[0].EndTime > DateTime.MinValue);
        }
Example #7
0
        public async Task AzDeploymentFrequencyDAIntegrationTest()
        {
            //Arrange
            bool             getSampleData    = true;
            string           patToken         = Configuration["AppSettings:AzureDevOpsPatToken"];
            TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration);
            string           organization     = "samsmithnz";
            string           project          = "SamLearnsAzure";
            string           branch           = "refs/heads/master";
            string           buildName        = "SamLearnsAzure.CI";
            int  numberOfDays     = 30;
            int  maxNumberOfItems = 20;
            bool useCache         = true;

            //Act
            DeploymentFrequencyDA    da    = new DeploymentFrequencyDA();
            DeploymentFrequencyModel model = await da.GetAzureDevOpsDeploymentFrequency(getSampleData, patToken, tableStorageAuth, organization, project, branch, buildName, numberOfDays, maxNumberOfItems, useCache);

            //Assert
            Assert.IsTrue(model.DeploymentsPerDayMetric > 0f);
            Assert.AreEqual(false, string.IsNullOrEmpty(model.DeploymentsPerDayMetricDescription));
            Assert.AreNotEqual("Unknown", model.DeploymentsPerDayMetricDescription);
            Assert.AreEqual(10f, model.DeploymentsToDisplayMetric);
            Assert.AreEqual("per day", model.DeploymentsToDisplayUnit);
            Assert.AreEqual(numberOfDays, model.NumberOfDays);
            Assert.IsTrue(model.MaxNumberOfItems > 0);
            Assert.IsTrue(model.TotalItems > 0);
            Assert.IsTrue(model.IsProjectView == false);
            Assert.IsTrue(model.ItemOrder == 0);
        }
        public async Task <DeploymentFrequencyModel> GetAzureDevOpsDeploymentFrequency(bool getSampleData, string patToken,
                                                                                       string organization, string project, string branch, string buildName,
                                                                                       int numberOfDays, int maxNumberOfItems, bool useCache)
        {
            DeploymentFrequencyModel model = new DeploymentFrequencyModel();

            try
            {
                TableStorageAuth      tableStorageAuth = Common.GenerateTableAuthorization(Configuration);
                DeploymentFrequencyDA da = new DeploymentFrequencyDA();
                model = await da.GetAzureDevOpsDeploymentFrequency(getSampleData, patToken, tableStorageAuth, organization, project, branch, buildName, numberOfDays, maxNumberOfItems, useCache);
            }
            catch (Exception ex)
            {
                if (ex.Message == "Response status code does not indicate success: 403 (rate limit exceeded).")
                {
                    model.DeploymentName = buildName;
                    model.RateLimitHit   = true;
                }
                else
                {
                    throw;
                }
            }
            return(model);
        }
Example #9
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));
        }
Example #10
0
        public async Task GHDeploymentsControllerAPILiveIntegrationTest()
        {
            //Arrange
            bool   getSampleData    = false;
            string clientId         = Configuration["AppSettings:GitHubClientId"];
            string clientSecret     = Configuration["AppSettings:GitHubClientSecret"];
            string owner            = "samsmithnz";
            string repo             = "SamsFeatureFlags";
            string branch           = "master";
            string workflowName     = "SamsFeatureFlags.CI/CD";
            string workflowId       = "108084";
            int    numberOfDays     = 7;
            int    maxNumberOfItems = 20;
            bool   useCache         = false;
            DeploymentFrequencyController controller = new DeploymentFrequencyController(Configuration);

            //Act
            DeploymentFrequencyModel model = await controller.GetGitHubDeploymentFrequency(getSampleData, clientId, clientSecret, owner, repo, branch, workflowName, workflowId, numberOfDays, maxNumberOfItems, useCache);

            //Assert
            Assert.IsTrue(model != null);
            if (model.RateLimitHit == false)
            {
                Assert.AreEqual(DevOpsPlatform.GitHub, model.TargetDevOpsPlatform);
                Assert.AreEqual(workflowName, model.DeploymentName);
                Assert.IsTrue(model.DeploymentsPerDayMetric >= 0f);
                Assert.IsTrue(string.IsNullOrEmpty(model.DeploymentsPerDayMetricDescription) == false);
                Assert.IsTrue(model.BuildList.Count >= 0);
                if (model.BuildList.Count > 0)
                {
                    Assert.IsTrue(model.BuildList[0].BuildDurationPercent >= 0f);
                    Assert.IsTrue(string.IsNullOrEmpty(model.BuildList[0].BuildNumber) == false);
                    Assert.IsTrue(string.IsNullOrEmpty(model.BuildList[0].Branch) == false);
                    Assert.IsTrue(string.IsNullOrEmpty(model.BuildList[0].Status) == false);
                    Assert.IsTrue(string.IsNullOrEmpty(model.BuildList[0].Url) == false);
                    Assert.IsTrue(model.BuildList[0].StartTime > DateTime.MinValue);
                    Assert.IsTrue(model.BuildList[0].EndTime > DateTime.MinValue);
                }
                Assert.AreEqual(numberOfDays, model.NumberOfDays);
                Assert.AreEqual(maxNumberOfItems, model.MaxNumberOfItems);
                Assert.IsTrue(model.TotalItems > 0);
            }
        }
Example #11
0
        public async Task AzDeploymentsCacheControllerIntegrationTest()
        {
            //https://devopsmetrics-prod-eu-service.azurewebsites.net//api/DeploymentFrequency/GetAzureDevOpsDeploymentFrequency?getSampleData=False&patToken=&organization=samsmithnz&project=SamLearnsAzure&branch=refs/heads/master&buildName=SamLearnsAzure.CI&buildId=3673&numberOfDays=30&maxNumberOfItems=20&useCache=true

            //Arrange
            bool   getSampleData    = false;
            string patToken         = Configuration["AppSettings:AzureDevOpsPatToken"];
            string organization     = "samsmithnz";
            string project          = "SamLearnsAzure";
            string branch           = "refs/heads/master";
            string buildName        = "SamLearnsAzure.CI";
            int    numberOfDays     = 30;
            int    maxNumberOfItems = 20;
            bool   useCache         = true;
            DeploymentFrequencyController controller = new DeploymentFrequencyController(Configuration);

            //Act
            DeploymentFrequencyModel model = await controller.GetAzureDevOpsDeploymentFrequency(getSampleData, patToken, organization, project, branch, buildName, numberOfDays, maxNumberOfItems, useCache);

            //Assert
            Assert.IsTrue(model != null);
            if (model.RateLimitHit == false)
            {
                Assert.AreEqual(DevOpsPlatform.AzureDevOps, model.TargetDevOpsPlatform);
                Assert.AreEqual(buildName, model.DeploymentName);
                Assert.IsTrue(model.DeploymentsPerDayMetric >= 0f);
                Assert.IsTrue(string.IsNullOrEmpty(model.DeploymentsPerDayMetricDescription) == false);
                Assert.IsTrue(model.BuildList.Count >= 0);
                if (model.BuildList.Count > 0)
                {
                    Assert.IsTrue(model.BuildList[0].BuildDurationPercent >= 0f);
                    Assert.IsTrue(string.IsNullOrEmpty(model.BuildList[0].BuildNumber) == false);
                    Assert.IsTrue(string.IsNullOrEmpty(model.BuildList[0].Branch) == false);
                    Assert.IsTrue(string.IsNullOrEmpty(model.BuildList[0].Status) == false);
                    Assert.IsTrue(string.IsNullOrEmpty(model.BuildList[0].Url) == false);
                    Assert.IsTrue(model.BuildList[0].StartTime > DateTime.MinValue);
                    Assert.IsTrue(model.BuildList[0].EndTime > DateTime.MinValue);
                }
                Assert.AreEqual(numberOfDays, model.NumberOfDays);
                Assert.AreEqual(maxNumberOfItems, model.MaxNumberOfItems);
                Assert.IsTrue(model.TotalItems > 0);
            }
        }
        public void DeploymentFrequencyRatingZeroNoneTest()
        {
            //Arrange
            DeploymentFrequency metrics = new DeploymentFrequency();
            float metric = 0f; //None

            //Act
            DeploymentFrequencyModel model = new DeploymentFrequencyModel
            {
                DeploymentsPerDayMetric            = metric,
                DeploymentsPerDayMetricDescription = metrics.GetDeploymentFrequencyRating(metric)
            };

            //Assert
            Assert.IsTrue(model != null);
            Assert.AreEqual(0f, model.DeploymentsPerDayMetric);
            Assert.AreEqual("None", model.DeploymentsPerDayMetricDescription);
            Assert.AreEqual(0, model.DeploymentsToDisplayMetric);
            Assert.AreEqual("times per month", model.DeploymentsToDisplayUnit);
        }
        public void DeploymentFrequencyRatingHighTest()
        {
            //Arrange
            DeploymentFrequency metrics = new DeploymentFrequency();
            float metric = 1f / 7f; //weekly

            //Act
            DeploymentFrequencyModel model = new DeploymentFrequencyModel
            {
                DeploymentsPerDayMetric            = metric,
                DeploymentsPerDayMetricDescription = metrics.GetDeploymentFrequencyRating(metric)
            };

            //Assert
            Assert.IsTrue(model != null);
            Assert.AreEqual(1f / 7f, model.DeploymentsPerDayMetric);
            Assert.AreEqual("High", model.DeploymentsPerDayMetricDescription);
            Assert.AreEqual(1f, model.DeploymentsToDisplayMetric);
            Assert.AreEqual("times per week", model.DeploymentsToDisplayUnit);
        }
        public void DeploymentFrequencyRatingEliteTest()
        {
            //Arrange
            DeploymentFrequency metrics = new DeploymentFrequency();
            float metric = 1.01f; //daily

            //Act
            DeploymentFrequencyModel model = new DeploymentFrequencyModel
            {
                DeploymentsPerDayMetric            = metric,
                DeploymentsPerDayMetricDescription = metrics.GetDeploymentFrequencyRating(metric)
            };

            //Assert
            Assert.IsTrue(model != null);
            Assert.AreEqual(1.01f, model.DeploymentsPerDayMetric);
            Assert.AreEqual("Elite", model.DeploymentsPerDayMetricDescription);
            Assert.AreEqual(1.01f, model.DeploymentsToDisplayMetric);
            Assert.AreEqual("per day", model.DeploymentsToDisplayUnit);
        }
        public void DeploymentFrequencyRatingLowTest()
        {
            //Arrange
            DeploymentFrequency metrics = new DeploymentFrequency();
            float metric = (1f / 30f) - 0.01f; //monthly

            //Act
            DeploymentFrequencyModel model = new DeploymentFrequencyModel
            {
                DeploymentsPerDayMetric            = metric,
                DeploymentsPerDayMetricDescription = metrics.GetDeploymentFrequencyRating(metric)
            };

            //Assert
            Assert.IsTrue(model != null);
            Assert.AreEqual(metric, model.DeploymentsPerDayMetric);
            Assert.AreEqual("Low", model.DeploymentsPerDayMetricDescription);
            Assert.AreEqual(0.70000005f, model.DeploymentsToDisplayMetric);
            Assert.AreEqual("times per month", model.DeploymentsToDisplayUnit);
        }
Example #16
0
        public async Task GHDeploymentsControllerAPILiveWithCacheIntegrationTest()
        {
            //Arrange
            bool   getSampleData    = true;
            string clientId         = Configuration["AppSettings:GitHubClientId"];
            string clientSecret     = Configuration["AppSettings:GitHubClientSecret"];
            string owner            = "samsmithnz";
            string repo             = "SamsFeatureFlags";
            string branch           = "master";
            string workflowName     = "SamsFeatureFlags.CI/CD";
            string workflowId       = "108084";
            int    numberOfDays     = 7;
            int    maxNumberOfItems = 20;
            bool   useCache         = true;
            DeploymentFrequencyController controller = new DeploymentFrequencyController(Configuration);

            //Act
            DeploymentFrequencyModel model = await controller.GetGitHubDeploymentFrequency(getSampleData, clientId, clientSecret, owner, repo, branch, workflowName, workflowId, numberOfDays, maxNumberOfItems, useCache);

            //Assert
            Assert.AreEqual(DevOpsPlatform.GitHub, model.TargetDevOpsPlatform);
            Assert.AreEqual(workflowName, model.DeploymentName);
            Assert.AreEqual(10f, model.DeploymentsPerDayMetric);
            Assert.AreEqual("Elite", model.DeploymentsPerDayMetricDescription);
            Assert.AreEqual(10, model.BuildList.Count);
            Assert.AreEqual(70, model.BuildList[0].BuildDurationPercent);
            Assert.AreEqual("1", model.BuildList[0].BuildNumber);
            Assert.AreEqual("master", model.BuildList[0].Branch);
            Assert.AreEqual("completed", model.BuildList[0].Status);
            Assert.AreEqual("https://GitHub.com/samsmithnz/devopsmetrics/1", model.BuildList[0].Url);
            Assert.IsTrue(model.BuildList[0].StartTime > DateTime.MinValue);
            Assert.IsTrue(model.BuildList[0].EndTime > DateTime.MinValue);
            Assert.AreEqual(numberOfDays, model.NumberOfDays);
            Assert.IsTrue(model.MaxNumberOfItems > 0);
            Assert.IsTrue(model.TotalItems > 0);
        }
        public async Task <DeploymentFrequencyModel> GetAzureDevOpsDeploymentFrequency(bool getSampleData, string patToken, TableStorageAuth tableStorageAuth,
                                                                                       string organization, string project, string branch, string buildName,
                                                                                       int numberOfDays, int maxNumberOfItems, bool useCache)
        {
            ListUtility <Build> utility             = new ListUtility <Build>();
            DeploymentFrequency deploymentFrequency = new DeploymentFrequency();

            if (getSampleData == false)
            {
                //Get a list of builds
                BuildsDA buildsDA = new BuildsDA();
                List <AzureDevOpsBuild> azureDevOpsBuilds = await buildsDA.GetAzureDevOpsBuilds(patToken, tableStorageAuth, organization, project, buildName, useCache);

                if (azureDevOpsBuilds != null)
                {
                    //Translate the Azure DevOps build to a generic build object
                    List <Build> builds = new List <Build>();
                    foreach (AzureDevOpsBuild item in azureDevOpsBuilds)
                    {
                        //Only return completed builds on the target branch, within the targeted date range
                        if (item.status == "completed" && item.sourceBranch == branch && item.queueTime > DateTime.Now.AddDays(-numberOfDays))
                        {
                            builds.Add(
                                new Build
                            {
                                Id                   = item.id,
                                Branch               = item.sourceBranch,
                                BuildNumber          = item.buildNumber,
                                StartTime            = item.queueTime,
                                EndTime              = item.finishTime,
                                BuildDurationPercent = item.buildDurationPercent,
                                Status               = item.status,
                                Url                  = item.url
                            }
                                );
                        }
                    }

                    //Get the total builds used in the calculation
                    int buildTotal = builds.Count;

                    //then build the calcuation, loading the dates into a date array
                    List <KeyValuePair <DateTime, DateTime> > dateList = new List <KeyValuePair <DateTime, DateTime> >();
                    foreach (Build item in builds)
                    {
                        KeyValuePair <DateTime, DateTime> newItem = new KeyValuePair <DateTime, DateTime>(item.StartTime, item.EndTime);
                        dateList.Add(newItem);
                    }

                    //then build the calcuation, loading the dates into a date array
                    float deploymentsPerDay;
                    deploymentsPerDay = deploymentFrequency.ProcessDeploymentFrequency(dateList, numberOfDays);

                    //Filter the results to return the last n (maxNumberOfItems), to return to the UI
                    builds = utility.GetLastNItems(builds, maxNumberOfItems);
                    //Find the max build duration
                    float maxBuildDuration = 0f;
                    foreach (Build item in builds)
                    {
                        if (item.BuildDuration > maxBuildDuration)
                        {
                            maxBuildDuration = item.BuildDuration;
                        }
                    }
                    //Calculate the percent scaling
                    foreach (Build item in builds)
                    {
                        float interiumResult = ((item.BuildDuration / maxBuildDuration) * 100f);
                        item.BuildDurationPercent = Scaling.ScaleNumberToRange(interiumResult, 0, 100, 20, 100);
                    }

                    //Return the completed model
                    DeploymentFrequencyModel model = new DeploymentFrequencyModel
                    {
                        TargetDevOpsPlatform               = DevOpsPlatform.AzureDevOps,
                        DeploymentName                     = buildName,
                        BuildList                          = builds,
                        DeploymentsPerDayMetric            = deploymentsPerDay,
                        DeploymentsPerDayMetricDescription = deploymentFrequency.GetDeploymentFrequencyRating(deploymentsPerDay),
                        NumberOfDays                       = numberOfDays,
                        MaxNumberOfItems                   = builds.Count,
                        TotalItems                         = buildTotal
                    };
                    return(model);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                //Get sample data
                List <Build>             builds = utility.GetLastNItems(GetSampleAzureDevOpsBuilds(), maxNumberOfItems);
                DeploymentFrequencyModel model  = new DeploymentFrequencyModel
                {
                    TargetDevOpsPlatform               = DevOpsPlatform.AzureDevOps,
                    DeploymentName                     = buildName,
                    BuildList                          = builds,
                    DeploymentsPerDayMetric            = 10f,
                    DeploymentsPerDayMetricDescription = "Elite",
                    NumberOfDays                       = numberOfDays,
                    MaxNumberOfItems                   = builds.Count,
                    TotalItems                         = builds.Count
                };
                return(model);
            }
        }
        public async Task <DeploymentFrequencyModel> GetGitHubDeploymentFrequency(bool getSampleData, string clientId, string clientSecret, TableStorageAuth tableStorageAuth,
                                                                                  string owner, string repo, string branch, string workflowName, string workflowId,
                                                                                  int numberOfDays, int maxNumberOfItems, bool useCache)
        {
            ListUtility <Build> utility             = new ListUtility <Build>();
            DeploymentFrequency deploymentFrequency = new DeploymentFrequency();

            if (getSampleData == false)
            {
                //Get a list of builds
                BuildsDA buildsDA = new BuildsDA();
                List <GitHubActionsRun> gitHubRuns = await buildsDA.GetGitHubActionRuns(clientId, clientSecret, tableStorageAuth, owner, repo, workflowName, workflowId, useCache);

                if (gitHubRuns != null)
                {
                    //Translate the GitHub build to a generic build object
                    List <Build> builds = new List <Build>();
                    foreach (GitHubActionsRun item in gitHubRuns)
                    {
                        //Only return completed builds on the target branch, within the targeted date range
                        if (item.status == "completed" && item.head_branch == branch && item.created_at > DateTime.Now.AddDays(-numberOfDays))
                        {
                            builds.Add(
                                new Build
                            {
                                Id                   = item.run_number,
                                Branch               = item.head_branch,
                                BuildNumber          = item.run_number,
                                StartTime            = item.created_at,
                                EndTime              = item.updated_at,
                                BuildDurationPercent = item.buildDurationPercent,
                                Status               = item.status,
                                Url                  = item.html_url
                            }
                                );
                        }
                    }

                    //Get the total builds used in the calculation
                    int buildTotal = builds.Count;

                    //then build the calcuation, loading the dates into a date array
                    List <KeyValuePair <DateTime, DateTime> > dateList = new List <KeyValuePair <DateTime, DateTime> >();
                    foreach (Build item in builds)
                    {
                        KeyValuePair <DateTime, DateTime> newItem = new KeyValuePair <DateTime, DateTime>(item.StartTime, item.EndTime);
                        dateList.Add(newItem);
                    }

                    //then build the calcuation, loading the dates into a date array
                    float deploymentsPerDay;
                    deploymentsPerDay = deploymentFrequency.ProcessDeploymentFrequency(dateList, numberOfDays);

                    //Filter the results to return the last n (maxNumberOfItems), to return to the UI
                    builds = utility.GetLastNItems(builds, maxNumberOfItems);
                    //Find the max build duration
                    float maxBuildDuration = 0f;
                    foreach (Build item in builds)
                    {
                        if (item.BuildDuration > maxBuildDuration)
                        {
                            maxBuildDuration = item.BuildDuration;
                        }
                    }
                    //Calculate the percent scaling
                    foreach (Build item in builds)
                    {
                        float interiumResult = ((item.BuildDuration / maxBuildDuration) * 100f);
                        item.BuildDurationPercent = Scaling.ScaleNumberToRange(interiumResult, 0, 100, 20, 100);
                    }

                    //Return the completed model
                    DeploymentFrequencyModel model = new DeploymentFrequencyModel
                    {
                        TargetDevOpsPlatform               = DevOpsPlatform.GitHub,
                        DeploymentName                     = workflowName,
                        BuildList                          = builds,
                        DeploymentsPerDayMetric            = deploymentsPerDay,
                        DeploymentsPerDayMetricDescription = deploymentFrequency.GetDeploymentFrequencyRating(deploymentsPerDay),
                        NumberOfDays                       = numberOfDays,
                        MaxNumberOfItems                   = builds.Count,
                        TotalItems                         = buildTotal
                    };
                    return(model);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                List <Build>             builds = utility.GetLastNItems(GetSampleGitHubBuilds(), maxNumberOfItems);
                DeploymentFrequencyModel model  = new DeploymentFrequencyModel
                {
                    TargetDevOpsPlatform               = DevOpsPlatform.GitHub,
                    DeploymentName                     = workflowName,
                    BuildList                          = builds,
                    DeploymentsPerDayMetric            = 10f,
                    DeploymentsPerDayMetricDescription = "Elite",
                    NumberOfDays                       = numberOfDays,
                    MaxNumberOfItems                   = builds.Count,
                    TotalItems                         = builds.Count
                };
                return(model);
            }
        }
Example #19
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));
        }
Example #20
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));
        }