From 390daa8f3329e3935915d89c4f52a1dc3496101a Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Thu, 8 Jun 2023 06:57:28 -0400 Subject: [PATCH 1/3] Fix to null error --- src/DevOpsMetrics.Core/DataAccess/DORASummaryDA.cs | 11 +++++++---- .../Service/DORASummaryControllerTests.cs | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/DevOpsMetrics.Core/DataAccess/DORASummaryDA.cs b/src/DevOpsMetrics.Core/DataAccess/DORASummaryDA.cs index 2e0d4644..6757817b 100644 --- a/src/DevOpsMetrics.Core/DataAccess/DORASummaryDA.cs +++ b/src/DevOpsMetrics.Core/DataAccess/DORASummaryDA.cs @@ -23,12 +23,15 @@ public static async Task GetDORASummaryItem(TableStorageConfigu { DORASummaryItem result = null; List doraItems = await GetDORASummaryItems(tableStorageConfig, owner); - foreach (DORASummaryItem item in doraItems) + if (doraItems != null) { - if (item.Repo.ToLower() == repo.ToLower()) + foreach (DORASummaryItem item in doraItems) { - result = item; - break; + if (item.Repo.ToLower() == repo.ToLower()) + { + result = item; + break; + } } } return result; diff --git a/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs b/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs index 53bd040a..3afeceeb 100644 --- a/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs +++ b/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs @@ -54,10 +54,10 @@ public async Task DORASummaryControllerGitHubUpdateIntegrationTest() { //Arrange string project = null; - string organization = "DeveloperMetrics"; - string repository = "DevOpsMetrics"; - //string organization = "samsmithnz"; - //string repository = "AzurePipelinesToGitHubActionsConverter"; + //string organization = "DeveloperMetrics"; + //string repository = "DevOpsMetrics"; + string organization = "samsmithnz"; + string repository = "TBS"; //string organization = "samsmithnz"; //string repository = "CustomQueue"; //string organization = "samsmithnz"; From b1e3f2a96eb73e2dfcccd29562772497297af683 Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Thu, 8 Jun 2023 07:18:05 -0400 Subject: [PATCH 2/3] Added additional protective coding to handle null lists --- .../APIAccess/AzureDevOpsAPIAccess.cs | 2 +- .../TableStorage/AzureTableStorageDA.cs | 19 ++++++++++++++++--- .../Service/DORASummaryControllerTests.cs | 8 ++++---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/DevOpsMetrics.Core/DataAccess/APIAccess/AzureDevOpsAPIAccess.cs b/src/DevOpsMetrics.Core/DataAccess/APIAccess/AzureDevOpsAPIAccess.cs index d077c2f7..f8495586 100644 --- a/src/DevOpsMetrics.Core/DataAccess/APIAccess/AzureDevOpsAPIAccess.cs +++ b/src/DevOpsMetrics.Core/DataAccess/APIAccess/AzureDevOpsAPIAccess.cs @@ -71,7 +71,7 @@ private async static Task GetAzureDevOpsMessage(string url, string patTo using (HttpResponseMessage response = await client.GetAsync(url)) { //Throw a response exception - response.EnsureSuccessStatusCode(); + //response.EnsureSuccessStatusCode(); if (response.IsSuccessStatusCode) { responseBody = await response.Content.ReadAsStringAsync(); diff --git a/src/DevOpsMetrics.Core/DataAccess/TableStorage/AzureTableStorageDA.cs b/src/DevOpsMetrics.Core/DataAccess/TableStorage/AzureTableStorageDA.cs index 8ac62bc6..7013e9d4 100644 --- a/src/DevOpsMetrics.Core/DataAccess/TableStorage/AzureTableStorageDA.cs +++ b/src/DevOpsMetrics.Core/DataAccess/TableStorage/AzureTableStorageDA.cs @@ -27,6 +27,10 @@ public async Task GetTableStorageItemsFromStorage(TableStorageConfigurat { TableStorageCommonDA tableDA = new(tableStorageConfig.StorageAccountConnectionString, tableName); List items = await tableDA.GetItems(partitionKey); + if (items == null) + { + items = new(); + } JArray list = new(); foreach (AzureStorageTableModel item in items) { @@ -109,7 +113,10 @@ public async Task UpdateAzureDevOpsBuildsInStorage(string patToken, TableSt int numberOfDays, int maxNumberOfItems) { JArray items = await AzureDevOpsAPIAccess.GetAzureDevOpsBuildsJArray(patToken, organization, project); - + if (items == null) + { + items = new(); + } int itemsAdded = 0; TableStorageCommonDA tableBuildsDA = new(tableStorageConfig.StorageAccountConnectionString, tableStorageConfig.TableAzureDevOpsBuilds); TableStorageCommonDA tableChangeFailureRateDA = new(tableStorageConfig.StorageAccountConnectionString, tableStorageConfig.TableChangeFailureRate); @@ -154,7 +161,10 @@ public async Task UpdateAzureDevOpsPullRequestsInStorage(string patToken, T int numberOfDays, int maxNumberOfItems) { JArray items = await AzureDevOpsAPIAccess.GetAzureDevOpsPullRequestsJArray(patToken, organization, project, repository); - + if (items == null) + { + items = new(); + } int itemsAdded = 0; TableStorageCommonDA tableDA = new(tableStorageConfig.StorageAccountConnectionString, tableStorageConfig.TableAzureDevOpsPRs); //Check each build to see if it's in storage, adding the items not in storage @@ -183,7 +193,10 @@ public async Task UpdateAzureDevOpsPullRequestCommitsInStorage(string patTo int numberOfDays, int maxNumberOfItems) { JArray items = await AzureDevOpsAPIAccess.GetAzureDevOpsPullRequestCommitsJArray(patToken, organization, project, repository, pullRequestId); - + if (items == null) + { + items = new(); + } int itemsAdded = 0; TableStorageCommonDA tableDA = new(tableStorageConfig.StorageAccountConnectionString, tableStorageConfig.TableAzureDevOpsPRCommits); //Check each build to see if it's in storage, adding the items not in storage diff --git a/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs b/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs index 3afeceeb..6976d818 100644 --- a/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs +++ b/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs @@ -53,16 +53,16 @@ public async Task DORASummaryControllerGetIntegrationTest2() public async Task DORASummaryControllerGitHubUpdateIntegrationTest() { //Arrange - string project = null; + // string project = null; //string organization = "DeveloperMetrics"; //string repository = "DevOpsMetrics"; string organization = "samsmithnz"; - string repository = "TBS"; + //string repository = "TBS"; //string organization = "samsmithnz"; //string repository = "CustomQueue"; //string organization = "samsmithnz"; - //string project = "SamLearnsAzure"; - //string repository = "SamLearnsAzure"; + string project = "SamLearnsAzure"; + string repository = "SamLearnsAzure"; int numberOfDays = 30; int maxNumberOfItems = 20; DORASummaryController controller = new(base.Configuration); From a49d5bf3edb14eee4a9a12015deb4329b00f35ec Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Thu, 8 Jun 2023 07:25:08 -0400 Subject: [PATCH 3/3] updated tests --- .../Service/DORASummaryControllerTests.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs b/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs index 6976d818..d5f13f56 100644 --- a/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs +++ b/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs @@ -53,16 +53,16 @@ public async Task DORASummaryControllerGetIntegrationTest2() public async Task DORASummaryControllerGitHubUpdateIntegrationTest() { //Arrange - // string project = null; - //string organization = "DeveloperMetrics"; - //string repository = "DevOpsMetrics"; - string organization = "samsmithnz"; + string project = null; + string organization = "DeveloperMetrics"; + string repository = "DevOpsMetrics"; + //string organization = "samsmithnz"; //string repository = "TBS"; //string organization = "samsmithnz"; //string repository = "CustomQueue"; //string organization = "samsmithnz"; - string project = "SamLearnsAzure"; - string repository = "SamLearnsAzure"; + //string project = "SamLearnsAzure"; + //string repository = "SamLearnsAzure"; int numberOfDays = 30; int maxNumberOfItems = 20; DORASummaryController controller = new(base.Configuration);