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); }
public void TimeToRestoreServiceDALiveIntegrationTest() { //Arrange bool getSampleData = false; TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); string resourceGroup = "SamLearnsAzureProd"; DevOpsPlatform targetDevOpsPlatform = DevOpsPlatform.AzureDevOps; int numberOfDays = 30; int maxNumberOfItems = 20; //Act MeanTimeToRestoreDA da = new MeanTimeToRestoreDA(); MeanTimeToRestoreModel model = da.GetAzureMeanTimeToRestore(getSampleData, tableStorageAuth, targetDevOpsPlatform, resourceGroup, numberOfDays, maxNumberOfItems); //Assert Assert.IsTrue(model != null); Assert.IsTrue(model.TargetDevOpsPlatform == targetDevOpsPlatform); Assert.AreEqual(resourceGroup, model.ResourceGroup); Assert.IsTrue(model.MeanTimeToRestoreEvents.Count > 0); Assert.IsTrue(model.MTTRAverageDurationInHours > 0); Assert.IsTrue(model.MTTRAverageDurationDescription != ""); Assert.AreEqual(numberOfDays, model.NumberOfDays); Assert.IsTrue(model.MaxNumberOfItems > 0); Assert.IsTrue(model.TotalItems > 0); }
public async Task <LeadTimeForChangesModel> GetAzureDevOpsLeadTimeForChanges(bool getSampleData, string patToken, string organization, string project, string repositoryId, string branch, string buildName, int numberOfDays, int maxNumberOfItems, bool useCache) { LeadTimeForChangesModel model = new LeadTimeForChangesModel(); try { TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); LeadTimeForChangesDA da = new LeadTimeForChangesDA(); model = await da.GetAzureDevOpsLeadTimesForChanges(getSampleData, patToken, tableStorageAuth, organization, project, repositoryId, branch, buildName, numberOfDays, maxNumberOfItems, useCache); } catch (Exception ex) { if (ex.Message == "Response status code does not indicate success: 403 (rate limit exceeded).") { model.ProjectName = project; model.RateLimitHit = true; } else { throw; } } return(model); }
public async Task <LeadTimeForChangesModel> GetGitHubLeadTimeForChanges(bool getSampleData, string clientId, string clientSecret, string owner, string repo, string branch, string workflowName, string workflowId, int numberOfDays, int maxNumberOfItems, bool useCache) { LeadTimeForChangesModel model = new LeadTimeForChangesModel(); try { TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); LeadTimeForChangesDA da = new LeadTimeForChangesDA(); model = await da.GetGitHubLeadTimesForChanges(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.ProjectName = repo; model.RateLimitHit = true; } else { throw; } } return(model); }
public async Task <int> UpdateAzureDevOpsPullRequests(string patToken, string organization, string project, string repositoryId, int numberOfDays, int maxNumberOfItems) { int numberOfRecordsSaved; try { TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); numberOfRecordsSaved = await AzureTableStorageDA.UpdateAzureDevOpsPullRequests(patToken, tableStorageAuth, organization, project, repositoryId, numberOfDays, maxNumberOfItems); } catch (Exception ex) { if (ex.Message == "Response status code does not indicate success: 403 (rate limit exceeded).") { numberOfRecordsSaved = -1; } else { throw; } } return(numberOfRecordsSaved); }
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); }
public async Task <bool> UpdateAzureDevOpsSetting(string patToken, TableStorageAuth tableStorageAuth, string settingsTable, string organization, string project, string repository, string branch, string buildName, string buildId, string resourceGroupName, int itemOrder) { string partitionKey = "AzureDevOpsSettings"; string rowKey = CreateAzureDevOpsSettingsPartitionKey(organization, project, repository, buildName); AzureDevOpsSettings settings = new AzureDevOpsSettings { RowKey = rowKey, PatToken = patToken, Organization = organization, Project = project, Repository = repository, Branch = branch, BuildName = buildName, BuildId = buildId, ProductionResourceGroup = resourceGroupName, ItemOrder = itemOrder }; string json = JsonConvert.SerializeObject(settings); AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, json); TableStorageCommonDA tableDA = new TableStorageCommonDA(tableStorageAuth, settingsTable); return(await tableDA.SaveItem(newItem)); }
public async Task <int> UpdateAzureDevOpsPullRequestCommits(string patToken, TableStorageAuth tableStorageAuth, string organization, string project, string repositoryId, string pullRequestId, int numberOfDays, int maxNumberOfItems) { AzureDevOpsAPIAccess api = new AzureDevOpsAPIAccess(); JArray items = await api.GetAzureDevOpsPullRequestCommitsJArray(patToken, organization, project, repositoryId, pullRequestId); int itemsAdded = 0; TableStorageCommonDA tableDA = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableAzureDevOpsPRCommits); //Check each build to see if it's in storage, adding the items not in storage foreach (JToken item in items) { AzureDevOpsPRCommit pullRequestCommit = JsonConvert.DeserializeObject <AzureDevOpsPRCommit>(item.ToString()); string partitionKey = CreateAzureDevOpsPRCommitPartitionKey(organization, project, pullRequestId); string rowKey = pullRequestCommit.commitId; AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, item.ToString()); if (await tableDA.AddItem(newItem) == true) { itemsAdded++; } } return(itemsAdded); }
public async Task <AzureDevOpsPR> GetAzureDevOpsPullRequest(string patToken, TableStorageAuth tableStorageAuth, string organization, string project, string repositoryId, string branch, bool useCache) { List <AzureDevOpsPR> prs = new List <AzureDevOpsPR>(); Newtonsoft.Json.Linq.JArray list; if (useCache == true) { //Get the pull requests from Azure storage AzureTableStorageDA daTableStorage = new AzureTableStorageDA(); list = daTableStorage.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableAzureDevOpsPRs, daTableStorage.CreateGitHubPRPartitionKey(organization, project)); } else { //Get the pull requests from the Azure DevOps API AzureDevOpsAPIAccess api = new AzureDevOpsAPIAccess(); list = await api.GetAzureDevOpsPullRequestsJArray(patToken, organization, project, repositoryId); } if (list != null) { prs = JsonConvert.DeserializeObject <List <AzureDevOpsPR> >(list.ToString()); } //Find the PR id AzureDevOpsPR pr = null; foreach (AzureDevOpsPR item in prs) { if (item.sourceRefName == branch) { pr = item; break; } } return(pr); }
public void GHChangeFailureRateDAIntegrationTest() { //Arrange bool getSampleData = true; TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); string owner = "samsmithnz"; string repo = "DevOpsMetrics"; string branch = "master"; string workflowName = "DevOpsMetrics CI/CD"; DevOpsPlatform targetDevOpsPlatform = DevOpsPlatform.GitHub; int numberOfDays = 30; int maxNumberOfItems = 20; //Act ChangeFailureRateDA da = new ChangeFailureRateDA(); ChangeFailureRateModel model = da.GetChangeFailureRate(getSampleData, tableStorageAuth, targetDevOpsPlatform, owner, repo, branch, workflowName, numberOfDays, maxNumberOfItems); //Assert Assert.IsTrue(model != null); Assert.IsTrue(model.TargetDevOpsPlatform == targetDevOpsPlatform); Assert.IsTrue(model.DeploymentName != ""); Assert.IsTrue(model.ChangeFailureRateMetric > 0f); Assert.IsTrue(model.ChangeFailureRateBuildList.Count <= 20f); Assert.AreEqual(false, string.IsNullOrEmpty(model.ChangeFailureRateMetricDescription)); Assert.AreNotEqual("Elite", model.ChangeFailureRateMetricDescription); Assert.AreEqual(numberOfDays, model.NumberOfDays); Assert.IsTrue(model.MaxNumberOfItems > 0); Assert.IsTrue(model.TotalItems > 0); }
public void AzChangeFailureRateDAIntegrationTest() { //Arrange bool getSampleData = true; TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); string organization = "samsmithnz"; string project = "SamLearnsAzure"; string branch = "refs/heads/master"; string buildName = "SamLearnsAzure.CI"; DevOpsPlatform targetDevOpsPlatform = DevOpsPlatform.AzureDevOps; int numberOfDays = 30; int maxNumberOfItems = 20; //Act ChangeFailureRateDA da = new ChangeFailureRateDA(); ChangeFailureRateModel model = da.GetChangeFailureRate(getSampleData, tableStorageAuth, targetDevOpsPlatform, organization, project, branch, buildName, numberOfDays, maxNumberOfItems); //Assert Assert.IsTrue(model != null); Assert.IsTrue(model.TargetDevOpsPlatform == DevOpsPlatform.AzureDevOps); Assert.IsTrue(model.DeploymentName != ""); Assert.IsTrue(model.ChangeFailureRateMetric > 0f); Assert.IsTrue(model.ChangeFailureRateBuildList.Count <= 20f); Assert.AreEqual(false, string.IsNullOrEmpty(model.ChangeFailureRateMetricDescription)); Assert.AreNotEqual("Elite", model.ChangeFailureRateMetricDescription); Assert.AreEqual(numberOfDays, model.NumberOfDays); Assert.IsTrue(model.MaxNumberOfItems > 0); Assert.IsTrue(model.TotalItems > 0); }
public void AzGetPRCommitsDAIntegrationTest() { //Arrange TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); string organization = "samsmithnz"; string project = "SamLearnsAzure"; //Act AzureTableStorageDA da = new AzureTableStorageDA(); JArray prList = da.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableAzureDevOpsPRs, da.CreateAzureDevOpsPRPartitionKey(organization, project)); int itemsAdded = 0; foreach (JToken item in prList) { AzureDevOpsPR pullRequest = JsonConvert.DeserializeObject <AzureDevOpsPR>(item.ToString()); string pullRequestId = pullRequest.PullRequestId; JArray list = da.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableAzureDevOpsPRCommits, da.CreateAzureDevOpsPRCommitPartitionKey(organization, project, pullRequestId)); if (list.Count > 0) { itemsAdded = list.Count; break; } } //Assert Assert.IsTrue(itemsAdded >= 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 List <GitHubSettings> GetGitHubSettings() { TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); List <GitHubSettings> settings = AzureTableStorageDA.GetGitHubSettings(tableStorageAuth, tableStorageAuth.TableGitHubSettings); return(settings); }
public async Task <int> UpdateGitHubActionRuns(string clientId, string clientSecret, string owner, string repo, string branch, string workflowName, string workflowId, int numberOfDays, int maxNumberOfItems) { int numberOfRecordsSaved; try { TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); numberOfRecordsSaved = await AzureTableStorageDA.UpdateGitHubActionRuns(clientId, clientSecret, tableStorageAuth, owner, repo, branch, workflowName, workflowId, numberOfDays, maxNumberOfItems); } catch (Exception ex) { if (ex.Message == "Response status code does not indicate success: 403 (rate limit exceeded).") { numberOfRecordsSaved = -1; } else { throw; } } return(numberOfRecordsSaved); }
public async Task <bool> UpdateGitHubSetting(string clientId, string clientSecret, string owner, string repo, string branch, string workflowName, string workflowId, string resourceGroup, int itemOrder) { TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); return(await AzureTableStorageDA.UpdateGitHubSetting(clientId, clientSecret, tableStorageAuth, tableStorageAuth.TableGitHubSettings, owner, repo, branch, workflowName, workflowId, resourceGroup, itemOrder)); }
public async Task <bool> UpdateAzureDevOpsSetting(string patToken, string organization, string project, string repository, string branch, string buildName, string buildId, string resourceGroup, int itemOrder) { TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); return(await AzureTableStorageDA.UpdateAzureDevOpsSetting(patToken, tableStorageAuth, tableStorageAuth.TableAzureDevOpsSettings, organization, project, repository, branch, buildName, buildId, resourceGroup, itemOrder)); }
public async Task <bool> UpdateChangeFailureRate(string organization_owner, string project_repo, string buildName_workflowName, int percentComplete, int numberOfDays) { TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); ChangeFailureRateDA da = new ChangeFailureRateDA(); return(await da.UpdateChangeFailureRate(tableStorageAuth, organization_owner, project_repo, buildName_workflowName, percentComplete, numberOfDays)); }
public async Task AzureMonitorProcessingTest() { //Arrange TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); MonitoringEvent monitoringEvent = new MonitoringEvent(@" { ""schemaId"": ""AzureMonitorMetricAlert"", ""data"": { ""version"": ""2.0"", ""properties"": null, ""status"": ""Activated"", ""context"": { ""timestamp"": ""2020-05-25T00:11:28.7763615Z"", ""id"": ""/subscriptions/07db7d0b-a6cb-4e58-b07e-e1d541c39f5b/resourceGroups/SamLearnsAzureFeatureFlags/providers/microsoft.insights/metricAlerts/ServerErrors%20featureflags-data-eu-service"", ""name"": ""ServerErrors featureflags-data-eu-service"", ""description"": """", ""conditionType"": ""SingleResourceMultipleMetricCriteria"", ""severity"": ""3"", ""condition"": { ""windowSize"": ""PT5M"", ""allOf"": [ { ""metricName"": ""Http5xx"", ""metricNamespace"": ""Microsoft.Web/sites"", ""operator"": ""GreaterThan"", ""threshold"": ""10"", ""timeAggregation"": ""Total"", ""dimensions"": [ { ""name"": ""ResourceId"", ""value"": ""featureflags-data-eu-service.azurewebsites.net"" } ], ""metricValue"": 11.0, ""webTestName"": null } ] }, ""subscriptionId"": ""07db7d0b-a6cb-4e58-b07e-e1d541c39f5b"", ""resourceGroupName"": ""SamLearnsAzureTest"", ""resourceName"": ""featureflags-data-eu-service"", ""resourceType"": ""Microsoft.Web/sites"", ""resourceId"": ""/subscriptions/07db7d0b-a6cb-4e58-b07e-e1d541c39f5b/resourceGroups/SamLearnsAzureFeatureFlags/providers/Microsoft.Web/sites/featureflags-data-eu-service"", ""portalLink"": ""https://portal.azure.com/#resource/subscriptions/07db7d0b-a6cb-4e58-b07e-e1d541c39f5b/resourceGroups/SamLearnsAzureFeatureFlags/providers/Microsoft.Web/sites/featureflags-data-eu-service"" } } } "); //Act AzureTableStorageDA da = new AzureTableStorageDA(); bool result = await da.UpdateDevOpsMonitoringEvent(tableStorageAuth, monitoringEvent); //Assert Assert.IsTrue(result == true); }
public async Task <bool> UpdateDevOpsMonitoringEvent(TableStorageAuth tableStorageAuth, MonitoringEvent monitoringEvent) { string partitionKey = monitoringEvent.PartitionKey; string rowKey = monitoringEvent.RowKey; string json = monitoringEvent.RequestBody; AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, json); TableStorageCommonDA tableDA = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableMTTR); return(await tableDA.SaveItem(newItem)); }
public List <GitHubSettings> GetGitHubSettings(TableStorageAuth tableStorageAuth, string settingsTable) { List <GitHubSettings> settings = null; string partitionKey = "GitHubSettings"; JArray list = GetTableStorageItems(tableStorageAuth, settingsTable, partitionKey); if (list != null) { settings = JsonConvert.DeserializeObject <List <GitHubSettings> >(list.ToString()); } return(settings); }
public MeanTimeToRestoreModel GetAzureMeanTimeToRestore(bool getSampleData, DevOpsPlatform targetDevOpsPlatform, string resourceGroup, int numberOfDays, int maxNumberOfItems) { TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); MeanTimeToRestoreDA da = new MeanTimeToRestoreDA(); MeanTimeToRestoreModel model = da.GetAzureMeanTimeToRestore(getSampleData, tableStorageAuth, targetDevOpsPlatform, resourceGroup, numberOfDays, maxNumberOfItems); return(model); }
//Note that this can't be async due to performance issues with Azure Storage when you retrieve items public JArray GetTableStorageItems(TableStorageAuth tableStorageAuth, string tableName, string partitionKey) { TableStorageCommonDA tableDA = new TableStorageCommonDA(tableStorageAuth, tableName); List <AzureStorageTableModel> items = tableDA.GetItems(partitionKey); JArray list = new JArray(); foreach (AzureStorageTableModel item in items) { list.Add(JToken.Parse(item.Data)); } return(list); }
public ChangeFailureRateModel GetChangeFailureRate(bool getSampleData, DevOpsPlatform targetDevOpsPlatform, string organization_owner, string project_repo, string branch, string buildName_workflowName, int numberOfDays, int maxNumberOfItems) { TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); ChangeFailureRateDA da = new ChangeFailureRateDA(); ChangeFailureRateModel model = da.GetChangeFailureRate(getSampleData, tableStorageAuth, targetDevOpsPlatform, organization_owner, project_repo, branch, buildName_workflowName, numberOfDays, maxNumberOfItems); return(model); }
public void GHGetSamLearnsAzureSettingDAIntegrationTest() { //Arrange TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); //Act AzureTableStorageDA da = new AzureTableStorageDA(); List <GitHubSettings> results = da.GetGitHubSettings(tableStorageAuth, tableStorageAuth.TableGitHubSettings); //Assert Assert.IsTrue(results.Count > 0); }
public void GHGetPRsDAIntegrationTest() { //Arrange TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); string owner = "samsmithnz"; string repo = "DevOpsMetrics"; //Act AzureTableStorageDA da = new AzureTableStorageDA(); JArray list = da.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableGitHubPRs, da.CreateGitHubPRPartitionKey(owner, repo)); //Assert Assert.IsTrue(list.Count >= 0); }
public async Task <bool> UpdateChangeFailureRate(TableStorageAuth tableStorageAuth, string organization_owner, string project_repo, string buildName_workflowName, int percentComplete, int numberOfDays) { //Gets a list of change failure rate builds AzureTableStorageDA daTableStorage = new AzureTableStorageDA(); string partitionKey = daTableStorage.CreateBuildWorkflowPartitionKey(organization_owner, project_repo, buildName_workflowName); Newtonsoft.Json.Linq.JArray list = daTableStorage.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableChangeFailureRate, partitionKey); List <ChangeFailureRateBuild> initialBuilds = JsonConvert.DeserializeObject <List <ChangeFailureRateBuild> >(list.ToString()); //Get the list of items we are going to process, within the date/day range List <ChangeFailureRateBuild> builds = new List <ChangeFailureRateBuild>(); foreach (ChangeFailureRateBuild item in initialBuilds) { if (item.StartTime > DateTime.Now.AddDays(-numberOfDays)) { builds.Add(item); } } //Using the percent, convert it to a fraction FractionConverter converter = new FractionConverter(); FractionModel fracationModel = converter.ConvertToFraction(percentComplete); int numerator = fracationModel.Numerator; int denominator = fracationModel.Denominator; //Get builds for positive (builds we will set DeploymentWasSuccessful=true) and negative (builds we will set to DeploymentWasSuccessful=false) Console.WriteLine($"numerator {numerator} / denominator {denominator}"); //TODO: remember how this (x, numerator) syntax works so it can be documented. oooof. List <ChangeFailureRateBuild> postiveBuilds = builds.Where((x, numerator) => numerator % denominator != 0).ToList(); List <ChangeFailureRateBuild> negativeBuilds = builds.Where((x, numerator) => numerator % denominator == 0).ToList(); //Make the updates TableStorageCommonDA tableChangeFailureRateDA = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableChangeFailureRate); foreach (ChangeFailureRateBuild item in postiveBuilds) { item.DeploymentWasSuccessful = true; await daTableStorage.UpdateChangeFailureRate(tableChangeFailureRateDA, item, partitionKey, true); } foreach (ChangeFailureRateBuild item in negativeBuilds) { item.DeploymentWasSuccessful = false; await daTableStorage.UpdateChangeFailureRate(tableChangeFailureRateDA, item, partitionKey, true); } return(true); }
public void AzGetPRsDAIntegrationTest() { //Arrange TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); string organization = "samsmithnz"; string project = "SamLearnsAzure"; //Act AzureTableStorageDA da = new AzureTableStorageDA(); JArray list = da.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableAzureDevOpsBuilds, da.CreateAzureDevOpsPRPartitionKey(organization, project)); //Assert Assert.IsTrue(list.Count >= 0); }
public async Task GHLeadTimeForChangesDAIntegrationTest() { //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 masterBranch = "master"; string workflowName = "DevOpsMetrics.CI"; string workflowId = "1162561"; int numberOfDays = 7; int maxNumberOfItems = 20; bool useCache = false; //Act LeadTimeForChangesDA da = new LeadTimeForChangesDA(); LeadTimeForChangesModel model = await da.GetGitHubLeadTimesForChanges(getSampleData, clientId, clientSecret, tableStorageAuth, owner, repo, masterBranch, workflowName, workflowId, numberOfDays, maxNumberOfItems, useCache); //Assert Assert.IsTrue(model != null); Assert.AreEqual(repo, model.ProjectName); Assert.IsTrue(model.PullRequests.Count > 0); Assert.IsTrue(model.PullRequests.Count <= 20); Assert.AreEqual("123", model.PullRequests[0].PullRequestId); Assert.AreEqual("branch1", model.PullRequests[0].Branch); Assert.AreEqual(1, model.PullRequests[0].BuildCount); Assert.IsTrue(model.PullRequests[0].Commits.Count > 0); Assert.AreEqual("abc", model.PullRequests[0].Commits[0].commitId); Assert.IsTrue(model.PullRequests[0].Commits[0].date >= DateTime.MinValue); Assert.AreEqual("name1", model.PullRequests[0].Commits[0].name); Assert.AreEqual(60, Math.Round(model.PullRequests[0].Duration.TotalMinutes, 0)); Assert.AreEqual(33f, model.PullRequests[0].DurationPercent); Assert.IsTrue(model.PullRequests[0].StartDateTime >= DateTime.MinValue); Assert.IsTrue(model.PullRequests[0].EndDateTime >= DateTime.MinValue); Assert.AreEqual(1f, model.AverageBuildHours); Assert.AreEqual(20.33f, model.AveragePullRequestHours); Assert.AreEqual(21.33f, model.LeadTimeForChangesMetric); Assert.AreEqual("Elite", model.LeadTimeForChangesMetricDescription); Assert.AreEqual(numberOfDays, model.NumberOfDays); Assert.IsTrue(model.MaxNumberOfItems > 0); Assert.IsTrue(model.TotalItems > 0); }
public async Task <int> UpdateAzureDevOpsBuilds(string patToken, TableStorageAuth tableStorageAuth, string organization, string project, string branch, string buildName, string buildId, int numberOfDays, int maxNumberOfItems) { AzureDevOpsAPIAccess api = new AzureDevOpsAPIAccess(); JArray items = await api.GetAzureDevOpsBuildsJArray(patToken, organization, project); int itemsAdded = 0; TableStorageCommonDA tableBuildsDA = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableAzureDevOpsBuilds); TableStorageCommonDA tableChangeFailureRateDA = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableChangeFailureRate); //Check each build to see if it's in storage, adding the items not in storage foreach (JToken item in items) { AzureDevOpsBuild build = JsonConvert.DeserializeObject <AzureDevOpsBuild>(item.ToString()); //Save the build information for builds if (build.status == "completed") { string partitionKey = CreateBuildWorkflowPartitionKey(organization, project, buildName); string rowKey = build.buildNumber; AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, item.ToString()); if (await tableBuildsDA.AddItem(newItem) == true) { itemsAdded++; } //Save the build information for change failure rate ChangeFailureRateBuild newBuild = new ChangeFailureRateBuild { Id = build.id, Branch = build.sourceBranch, BuildNumber = build.buildNumber, StartTime = build.queueTime, EndTime = build.finishTime, BuildDurationPercent = build.buildDurationPercent, Status = build.status, Url = build.url }; itemsAdded += await UpdateChangeFailureRate(tableChangeFailureRateDA, newBuild, CreateBuildWorkflowPartitionKey(organization, project, buildName)); } } return(itemsAdded); }