From dd9f5d694e0265a27f3f5340208ba3ce3af2c8d2 Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Tue, 20 Jun 2023 21:53:28 -0400 Subject: [PATCH 1/3] added catch to test --- .../TableStorage/TableStorageCommonDA.cs | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/DevOpsMetrics.Core/DataAccess/TableStorage/TableStorageCommonDA.cs b/src/DevOpsMetrics.Core/DataAccess/TableStorage/TableStorageCommonDA.cs index 5fc4a547..8cb2051a 100644 --- a/src/DevOpsMetrics.Core/DataAccess/TableStorage/TableStorageCommonDA.cs +++ b/src/DevOpsMetrics.Core/DataAccess/TableStorage/TableStorageCommonDA.cs @@ -116,23 +116,26 @@ public async Task SaveItem(AzureStorageTableModel data) public static string EncodePartitionKey(string text) { - //The forward slash(/) character - //The backslash(\) character - //The number sign(#) character - //The question mark (?) character - text = text.Replace("/", "_"); - //text = text.Replace("\\", "_"); - //text = text.Replace("#", "_"); - //text = text.Replace("?", "_"); - - ////Control characters from U+0000 to U+001F, including: - ////The horizontal tab(\t) character - //text = text.Replace("\t", "_"); - ////The linefeed(\n) character - //text = text.Replace("\n", "_"); - ////The carriage return (\r) character - //text = text.Replace("\r", "_"); - ////Control characters from U + 007F to U+009F + if (string.IsNullOrEmpty(text) == false) + { + //The forward slash(/) character + //The backslash(\) character + //The number sign(#) character + //The question mark (?) character + text = text.Replace("/", "_"); + //text = text.Replace("\\", "_"); + //text = text.Replace("#", "_"); + //text = text.Replace("?", "_"); + + ////Control characters from U+0000 to U+001F, including: + ////The horizontal tab(\t) character + //text = text.Replace("\t", "_"); + ////The linefeed(\n) character + //text = text.Replace("\n", "_"); + ////The carriage return (\r) character + //text = text.Replace("\r", "_"); + ////Control characters from U + 007F to U+009F + } return text; } From 323ab3db67d5cff2c2d797bbcf971970fa5b1911 Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Tue, 20 Jun 2023 22:09:54 -0400 Subject: [PATCH 2/3] Fix to bad situation when repo could be nuill --- src/DevOpsMetrics.Core/DataAccess/DORASummaryDA.cs | 2 +- .../Controllers/DORASummaryController.cs | 4 +--- .../Service/DORASummaryControllerTests.cs | 10 ++++------ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/DevOpsMetrics.Core/DataAccess/DORASummaryDA.cs b/src/DevOpsMetrics.Core/DataAccess/DORASummaryDA.cs index 1c81cbff..a5e9a02e 100644 --- a/src/DevOpsMetrics.Core/DataAccess/DORASummaryDA.cs +++ b/src/DevOpsMetrics.Core/DataAccess/DORASummaryDA.cs @@ -27,7 +27,7 @@ public static async Task GetDORASummaryItem(TableStorageConfigu { foreach (DORASummaryItem item in doraItems) { - if ((project != null && item.Project == project) || (item.Repo.ToLower() == repo.ToLower())) + if ((project != null && item.Project == project) || (item.Repo?.ToLower() == repo.ToLower())) { result = item; break; diff --git a/src/DevOpsMetrics.Service/Controllers/DORASummaryController.cs b/src/DevOpsMetrics.Service/Controllers/DORASummaryController.cs index 50c44f95..e48995f7 100644 --- a/src/DevOpsMetrics.Service/Controllers/DORASummaryController.cs +++ b/src/DevOpsMetrics.Service/Controllers/DORASummaryController.cs @@ -6,10 +6,8 @@ using DevOpsMetrics.Core.DataAccess.TableStorage; using DevOpsMetrics.Core.Models.Common; using Microsoft.AspNetCore.Mvc; -using Microsoft.Build.Framework; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; namespace DevOpsMetrics.Service.Controllers { @@ -56,7 +54,7 @@ public async Task UpdateDORASummaryItem( Microsoft.Extensions.Logging.ILogger log = null, bool useCache = true, bool isGitHub = true, - bool useParallelProcessing = false) + bool useParallelProcessing = true) { //Start timer DateTime startTime = DateTime.Now; diff --git a/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs b/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs index e12c06b4..513012c2 100644 --- a/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs +++ b/src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs @@ -1,14 +1,12 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Reflection; using System.Threading.Tasks; using DevOpsMetrics.Core.DataAccess.TableStorage; using DevOpsMetrics.Core.Models.AzureDevOps; using DevOpsMetrics.Core.Models.Common; using DevOpsMetrics.Core.Models.GitHub; using DevOpsMetrics.Service.Controllers; -using Microsoft.AspNetCore.Mvc; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace DevOpsMetrics.Tests.Service @@ -40,10 +38,10 @@ public async Task DORASummaryControllerGitHubUpdateIntegrationTest() { //Arrange string project = null; - string organization = "DeveloperMetrics"; - string repo = "DevOpsMetrics"; - //string organization = "samsmithnz"; - //string repo = "Sams2048"; + //string organization = "DeveloperMetrics"; + //string repo = "DevOpsMetrics"; + string organization = "samsmithnz"; + string repo = "SamsFeatureFlags"; //string organization = "samsmithnz"; //string repo = "CustomQueue"; //string organization = "samsmithnz"; From 56642734ede01d607890e094e4fc880a744f4a0a Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Tue, 20 Jun 2023 22:13:29 -0400 Subject: [PATCH 3/3] code cleanup --- src/DevOpsMetrics.Cmd/ServiceApiClient.cs | 6 +++--- src/DevOpsMetrics.Function/AzureAlertProcessor.cs | 1 - src/DevOpsMetrics.Function/NightlyProcessor.cs | 2 +- src/DevOpsMetrics.Function/ServiceApiClient.cs | 7 +++---- .../Controllers/SettingsController.cs | 2 +- src/DevOpsMetrics.Tests/Service/TableStorageDATests.cs | 2 +- src/DevOpsMetrics.Web/Controllers/HomeController.cs | 3 --- 7 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/DevOpsMetrics.Cmd/ServiceApiClient.cs b/src/DevOpsMetrics.Cmd/ServiceApiClient.cs index e34d691d..f847f08f 100644 --- a/src/DevOpsMetrics.Cmd/ServiceApiClient.cs +++ b/src/DevOpsMetrics.Cmd/ServiceApiClient.cs @@ -35,9 +35,9 @@ public async Task> GetGitHubSettings() } public async Task UpdateDORASummaryItem( - string owner, string project, string repository, - string branch, string workflowName, string workflowId, - string resourceGroup, int numberOfDays, int maxNumberOfItems, + string owner, string project, string repository, + string branch, string workflowName, string workflowId, + string resourceGroup, int numberOfDays, int maxNumberOfItems, bool isGitHub = true) { string url = $"/api/DORASummary/UpdateDORASummaryItem?owner={owner}&project={project}&repository={repository}&branch={branch}&workflowName={workflowName}&workflowId={workflowId}&resourceGroup={resourceGroup}&numberOfDays={numberOfDays}&maxNumberOfItems={maxNumberOfItems}&log=&useCache=true&isGitHub={isGitHub}"; diff --git a/src/DevOpsMetrics.Function/AzureAlertProcessor.cs b/src/DevOpsMetrics.Function/AzureAlertProcessor.cs index b9342447..c0fdd849 100644 --- a/src/DevOpsMetrics.Function/AzureAlertProcessor.cs +++ b/src/DevOpsMetrics.Function/AzureAlertProcessor.cs @@ -1,7 +1,6 @@ using System.IO; using System.Reflection; using System.Threading.Tasks; -using DevOpsMetrics.Core.DataAccess.TableStorage; using DevOpsMetrics.Core.Models.Common; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; diff --git a/src/DevOpsMetrics.Function/NightlyProcessor.cs b/src/DevOpsMetrics.Function/NightlyProcessor.cs index 07c55e8e..dd09ee7b 100644 --- a/src/DevOpsMetrics.Function/NightlyProcessor.cs +++ b/src/DevOpsMetrics.Function/NightlyProcessor.cs @@ -57,7 +57,7 @@ public static async Task Run( { log.LogInformation($"Processing Azure DevOps organization {azSetting.Organization}, project {azSetting.Project}"); ProcessingResult ghResult = await serviceApiClient.UpdateDORASummaryItem( - azSetting.Organization, azSetting.Project, azSetting.Repository, + azSetting.Organization, azSetting.Project, azSetting.Repository, azSetting.Branch, azSetting.BuildName, azSetting.BuildId, azSetting.ProductionResourceGroup, numberOfDays, maxNumberOfItems, false); diff --git a/src/DevOpsMetrics.Function/ServiceApiClient.cs b/src/DevOpsMetrics.Function/ServiceApiClient.cs index 2bea3472..aaac5fbe 100644 --- a/src/DevOpsMetrics.Function/ServiceApiClient.cs +++ b/src/DevOpsMetrics.Function/ServiceApiClient.cs @@ -8,7 +8,6 @@ using DevOpsMetrics.Core.Models.Common; using DevOpsMetrics.Core.Models.GitHub; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; using Newtonsoft.Json; namespace DevOpsMetrics.Function @@ -40,9 +39,9 @@ public async Task> GetGitHubSettings() } public async Task UpdateDORASummaryItem( - string owner, string project, string repository, - string branch, string workflowName, string workflowId, - string resourceGroup, int numberOfDays, int maxNumberOfItems, + string owner, string project, string repository, + string branch, string workflowName, string workflowId, + string resourceGroup, int numberOfDays, int maxNumberOfItems, bool isGitHub = true) { string url = $"/api/DORASummary/UpdateDORASummaryItem?owner={owner}&project={project}&repository={repository}&branch={branch}&workflowName={workflowName}&workflowId={workflowId}&resourceGroup={resourceGroup}&numberOfDays={numberOfDays}&maxNumberOfItems={maxNumberOfItems}&log=&useCache=true&isGitHub={isGitHub}"; diff --git a/src/DevOpsMetrics.Service/Controllers/SettingsController.cs b/src/DevOpsMetrics.Service/Controllers/SettingsController.cs index 7f9cd46d..d4429fb6 100644 --- a/src/DevOpsMetrics.Service/Controllers/SettingsController.cs +++ b/src/DevOpsMetrics.Service/Controllers/SettingsController.cs @@ -119,7 +119,7 @@ public async Task UpdateAzureDevOpsProjectLog(string organization, string } [HttpGet("GetGitHubProjectLog")] - public async Task< List> GetGitHubProjectLog(string owner, string repo) + public async Task> GetGitHubProjectLog(string owner, string repo) { string partitionKey = PartitionKeys.CreateGitHubSettingsPartitionKey(owner, repo); diff --git a/src/DevOpsMetrics.Tests/Service/TableStorageDATests.cs b/src/DevOpsMetrics.Tests/Service/TableStorageDATests.cs index 579a94da..52a6237f 100644 --- a/src/DevOpsMetrics.Tests/Service/TableStorageDATests.cs +++ b/src/DevOpsMetrics.Tests/Service/TableStorageDATests.cs @@ -107,7 +107,7 @@ public async Task AzGetPRCommitsDAIntegrationTest() { AzureDevOpsPR pullRequest = JsonConvert.DeserializeObject(item.ToString()); string pullRequestId = pullRequest.PullRequestId; - JArray list =await da.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableAzureDevOpsPRCommits, PartitionKeys.CreateAzureDevOpsPRCommitPartitionKey(organization, project, pullRequestId)); + JArray list = await da.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableAzureDevOpsPRCommits, PartitionKeys.CreateAzureDevOpsPRCommitPartitionKey(organization, project, pullRequestId)); if (list.Count > 0) { itemsAdded = list.Count; diff --git a/src/DevOpsMetrics.Web/Controllers/HomeController.cs b/src/DevOpsMetrics.Web/Controllers/HomeController.cs index 7ece4295..a1b22869 100644 --- a/src/DevOpsMetrics.Web/Controllers/HomeController.cs +++ b/src/DevOpsMetrics.Web/Controllers/HomeController.cs @@ -7,14 +7,11 @@ using DevOpsMetrics.Core.Models.AzureDevOps; using DevOpsMetrics.Core.Models.Common; using DevOpsMetrics.Core.Models.GitHub; -using DevOpsMetrics.Service.Controllers; using DevOpsMetrics.Web.Models; using DevOpsMetrics.Web.Services; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; -using Microsoft.CodeAnalysis; using Microsoft.Extensions.Configuration; -using NuGet.Protocol; namespace DevOpsMetrics.Web.Controllers {