From bb5ce37f80b847825b3010bfb651e546b4290b66 Mon Sep 17 00:00:00 2001 From: slewis74 Date: Tue, 9 Mar 2021 09:42:53 +1000 Subject: [PATCH 1/3] new logging infra --- source/Server.Tests/AdoApiClientScenarios.cs | 22 +++++++++---------- source/Server.Tests/HtmlConvertScenarios.cs | 2 +- source/Server.Tests/Server.Tests.csproj | 2 +- source/Server/AdoClients/AdoApiClient.cs | 6 ++--- .../AzureDevOpsConfigureCommands.cs | 4 ++-- .../Configuration/DatabaseInitializer.cs | 4 ++-- source/Server/Server.csproj | 6 ++--- source/Server/WorkItems/HtmlConvert.cs | 4 ++-- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/source/Server.Tests/AdoApiClientScenarios.cs b/source/Server.Tests/AdoApiClientScenarios.cs index fb922b8..0670b7d 100644 --- a/source/Server.Tests/AdoApiClientScenarios.cs +++ b/source/Server.Tests/AdoApiClientScenarios.cs @@ -16,8 +16,8 @@ namespace Octopus.Server.Extensibility.IssueTracker.AzureDevOps.Tests [TestFixture] public class AdoApiClientScenarios { - private static readonly HtmlConvert HtmlConvert = new HtmlConvert(Substitute.For()); - private ILog? log; + private static readonly HtmlConvert HtmlConvert = new HtmlConvert(Substitute.For()); + private ISystemLog? log; private static IAzureDevOpsConfigurationStore CreateSubstituteStore() { @@ -31,7 +31,7 @@ private static IAzureDevOpsConfigurationStore CreateSubstituteStore() [SetUp] public void SetUp() { - log = Substitute.For(); + log = Substitute.For(); } [Test] @@ -46,7 +46,7 @@ public void ClientCanRequestAndParseWorkItemsRefsAndLinks() .Returns((HttpStatusCode.OK, JObject.Parse(@"{""id"":2,""fields"":{""System.CommentCount"":0,""System.Title"": ""README has no useful content""}}"))); - var workItemLinks = new AdoApiClient(store, httpJsonClient, HtmlConvert, log!).GetBuildWorkItemLinks( + var workItemLinks = new AdoApiClient(log!, store, httpJsonClient, HtmlConvert).GetBuildWorkItemLinks( AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=24")); var workItemLink = ((ISuccessResult)workItemLinks).Value.Single(); @@ -68,7 +68,7 @@ public void SourceGetsSet() .Returns((HttpStatusCode.OK, JObject.Parse(@"{""id"":2,""fields"":{""System.CommentCount"":0,""System.Title"": ""README has no useful content""}}"))); - var workItemLinks = new AdoApiClient(store, httpJsonClient, HtmlConvert, log!).GetBuildWorkItemLinks( + var workItemLinks = new AdoApiClient(log!, store, httpJsonClient, HtmlConvert).GetBuildWorkItemLinks( AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=24")); var workItemLink = ((ISuccessResult)workItemLinks).Value.Single(); @@ -90,7 +90,7 @@ public void ClientCanRequestAndParseWorkItemsWithReleaseNotes() .Returns((HttpStatusCode.OK, JObject.Parse(@"{""totalCount"":3,""count"":3,""comments"":[{""text"":""= Changelog = N/A""}," + @"{""text"":""
= Changelog = README riddle now has an answer!
""},{""text"":""See also related issue.""}]}"))); - var workItemLinks = new AdoApiClient(store, httpJsonClient, HtmlConvert, log!).GetBuildWorkItemLinks( + var workItemLinks = new AdoApiClient(log!, store, httpJsonClient, HtmlConvert).GetBuildWorkItemLinks( AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=28")); var workItemLink = ((ISuccessResult)workItemLinks).Value.Single(); @@ -118,7 +118,7 @@ public void ClientReportsFailuresAndReturnsPartialResults() httpJsonClient.Get("http://redstoneblock/DefaultCollection/Deployable/_apis/wit/workitems/6/comments?api-version=4.1-preview.2", "rumor") .Returns((HttpStatusCode.InternalServerError, null)); - var workItemLinks = new AdoApiClient(store, httpJsonClient, HtmlConvert, log!).GetBuildWorkItemLinks( + var workItemLinks = new AdoApiClient(log!, store, httpJsonClient, HtmlConvert).GetBuildWorkItemLinks( AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=29")); var successResult = ((ISuccessResult)workItemLinks); @@ -146,12 +146,12 @@ public void PersonalAccessTokenIsOnlySentToItsOrigin() }); // Request to other host should not include password - new AdoApiClient(store, httpJsonClient, HtmlConvert, log!) + new AdoApiClient(log!, store, httpJsonClient, HtmlConvert) .GetBuildWorkItemsRefs(AdoBuildUrls.ParseBrowserUrl("http://someotherhost/DefaultCollection/Deployable/_build/results?buildId=24")); Assert.IsNull(passwordSent); // Request to origin should include password - new AdoApiClient(store, httpJsonClient, HtmlConvert, log!) + new AdoApiClient(log!, store, httpJsonClient, HtmlConvert) .GetBuildWorkItemsRefs(AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=24")); Assert.AreEqual("rumor", passwordSent); } @@ -165,7 +165,7 @@ public void AcceptsDeletedBuildAsPermanentEmptySet() .Returns((HttpStatusCode.NotFound, JObject.Parse(@"{""$id"":""1"",""message"":""The requested build 7 could not be found."",""errorCode"":0,""eventId"":3000}"))); - var workItemLinks = new AdoApiClient(store, httpJsonClient, HtmlConvert, log!).GetBuildWorkItemLinks( + var workItemLinks = new AdoApiClient(log!, store, httpJsonClient, HtmlConvert).GetBuildWorkItemLinks( AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=7")); Assert.IsEmpty(((ISuccessResult)workItemLinks).Value); @@ -183,7 +183,7 @@ public void AcceptsDeletedWorkItemAsPermanentMissingTitle() .Returns((HttpStatusCode.NotFound, JObject.Parse(@"{""$id"":""1"",""message"":""TF401232: Work item 999 does not exist."",""errorCode"":0,""eventId"":3200}"))); - var workItemLinks = new AdoApiClient(store, httpJsonClient, HtmlConvert, log!).GetBuildWorkItemLinks( + var workItemLinks = new AdoApiClient(log!, store, httpJsonClient, HtmlConvert).GetBuildWorkItemLinks( AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=8")); var workItemLink = ((ISuccessResult)workItemLinks).Value.Single(); diff --git a/source/Server.Tests/HtmlConvertScenarios.cs b/source/Server.Tests/HtmlConvertScenarios.cs index 4668568..070e3cf 100644 --- a/source/Server.Tests/HtmlConvertScenarios.cs +++ b/source/Server.Tests/HtmlConvertScenarios.cs @@ -12,7 +12,7 @@ public class HtmlConvertScenarios [Test] public void ConvertsEntitiesAndNewlines() { - var plainText = new HtmlConvert(Substitute.For()).ToPlainText(@"one
two three
four
fi<e

six

seven"); + var plainText = new HtmlConvert(Substitute.For()).ToPlainText(@"one
two three
four
fi<e

six

seven"); Assert.AreEqual(string.Join(Environment.NewLine, @"one", "two\u00a0three", "four", "fi - + diff --git a/source/Server/AdoClients/AdoApiClient.cs b/source/Server/AdoClients/AdoApiClient.cs index 61e641a..2d5b2fe 100644 --- a/source/Server/AdoClients/AdoApiClient.cs +++ b/source/Server/AdoClients/AdoApiClient.cs @@ -25,17 +25,17 @@ interface IAdoApiClient class AdoApiClient : IAdoApiClient { + private readonly ISystemLog log; private readonly IAzureDevOpsConfigurationStore store; private readonly IHttpJsonClient client; private readonly HtmlConvert htmlConvert; - private readonly ILog log; - public AdoApiClient(IAzureDevOpsConfigurationStore store, IHttpJsonClient client, HtmlConvert htmlConvert, ILog log) + public AdoApiClient(ISystemLog log, IAzureDevOpsConfigurationStore store, IHttpJsonClient client, HtmlConvert htmlConvert) { + this.log = log; this.store = store; this.client = client; this.htmlConvert = htmlConvert; - this.log = log; } internal string? GetPersonalAccessToken(AdoUrl adoUrl) diff --git a/source/Server/Configuration/AzureDevOpsConfigureCommands.cs b/source/Server/Configuration/AzureDevOpsConfigureCommands.cs index c17fb23..36dd162 100644 --- a/source/Server/Configuration/AzureDevOpsConfigureCommands.cs +++ b/source/Server/Configuration/AzureDevOpsConfigureCommands.cs @@ -8,11 +8,11 @@ namespace Octopus.Server.Extensibility.IssueTracker.AzureDevOps.Configuration { class AzureDevOpsConfigureCommands : IContributeToConfigureCommand { - readonly ILog log; + readonly ISystemLog log; readonly Lazy azureDevOpsConfiguration; public AzureDevOpsConfigureCommands( - ILog log, + ISystemLog log, Lazy azureDevOpsConfiguration) { this.log = log; diff --git a/source/Server/Configuration/DatabaseInitializer.cs b/source/Server/Configuration/DatabaseInitializer.cs index 10b02f3..7c603eb 100644 --- a/source/Server/Configuration/DatabaseInitializer.cs +++ b/source/Server/Configuration/DatabaseInitializer.cs @@ -6,10 +6,10 @@ namespace Octopus.Server.Extensibility.IssueTracker.AzureDevOps.Configuration { class DatabaseInitializer : ExecuteWhenDatabaseInitializes { - readonly ILog log; + readonly ISystemLog log; readonly IConfigurationStore configurationStore; - public DatabaseInitializer(ILog log, IConfigurationStore configurationStore) + public DatabaseInitializer(ISystemLog log, IConfigurationStore configurationStore) { this.log = log; this.configurationStore = configurationStore; diff --git a/source/Server/Server.csproj b/source/Server/Server.csproj index b892458..a5ed029 100644 --- a/source/Server/Server.csproj +++ b/source/Server/Server.csproj @@ -16,9 +16,9 @@ - - - + + + diff --git a/source/Server/WorkItems/HtmlConvert.cs b/source/Server/WorkItems/HtmlConvert.cs index d1d74c6..fe1fb68 100644 --- a/source/Server/WorkItems/HtmlConvert.cs +++ b/source/Server/WorkItems/HtmlConvert.cs @@ -15,9 +15,9 @@ class HtmlConvert .Split(' ') .ToDictionary(n => n, n => true); - private readonly ILog log; + private readonly ISystemLog log; - public HtmlConvert(ILog log) + public HtmlConvert(ISystemLog log) { this.log = log; } From 846dba570e727249a6146fddefa2a0e298bc1a88 Mon Sep 17 00:00:00 2001 From: slewis74 Date: Thu, 11 Mar 2021 09:59:50 +1000 Subject: [PATCH 2/3] variable renames for consistency --- source/Server/AdoClients/AdoApiClient.cs | 8 ++++---- .../Configuration/AzureDevOpsConfigureCommands.cs | 12 ++++++------ source/Server/Configuration/DatabaseInitializer.cs | 8 ++++---- source/Server/WorkItems/HtmlConvert.cs | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/source/Server/AdoClients/AdoApiClient.cs b/source/Server/AdoClients/AdoApiClient.cs index 2d5b2fe..19ce91a 100644 --- a/source/Server/AdoClients/AdoApiClient.cs +++ b/source/Server/AdoClients/AdoApiClient.cs @@ -25,14 +25,14 @@ interface IAdoApiClient class AdoApiClient : IAdoApiClient { - private readonly ISystemLog log; + private readonly ISystemLog systemLog; private readonly IAzureDevOpsConfigurationStore store; private readonly IHttpJsonClient client; private readonly HtmlConvert htmlConvert; - public AdoApiClient(ISystemLog log, IAzureDevOpsConfigurationStore store, IHttpJsonClient client, HtmlConvert htmlConvert) + public AdoApiClient(ISystemLog systemLog, IAzureDevOpsConfigurationStore store, IHttpJsonClient client, HtmlConvert htmlConvert) { - this.log = log; + this.systemLog = systemLog; this.store = store; this.client = client; this.htmlConvert = htmlConvert; @@ -170,7 +170,7 @@ string BuildWorkItemBrowserUrl(AdoProjectUrls adoProjectUrls, int workItemId) if (comments is FailureResult failure) { // if we can't retrieve the comments then move on without - log.WarnFormat("Error retrieving Azure DevOps comments for work item {0}. Error: {1}", workItemId, failure.ErrorString); + systemLog.WarnFormat("Error retrieving Azure DevOps comments for work item {0}. Error: {1}", workItemId, failure.ErrorString); return null; } diff --git a/source/Server/Configuration/AzureDevOpsConfigureCommands.cs b/source/Server/Configuration/AzureDevOpsConfigureCommands.cs index 36dd162..6c72fd5 100644 --- a/source/Server/Configuration/AzureDevOpsConfigureCommands.cs +++ b/source/Server/Configuration/AzureDevOpsConfigureCommands.cs @@ -8,14 +8,14 @@ namespace Octopus.Server.Extensibility.IssueTracker.AzureDevOps.Configuration { class AzureDevOpsConfigureCommands : IContributeToConfigureCommand { - readonly ISystemLog log; + readonly ISystemLog systemLog; readonly Lazy azureDevOpsConfiguration; public AzureDevOpsConfigureCommands( - ISystemLog log, + ISystemLog systemLog, Lazy azureDevOpsConfiguration) { - this.log = log; + this.systemLog = systemLog; this.azureDevOpsConfiguration = azureDevOpsConfiguration; } @@ -26,19 +26,19 @@ public IEnumerable GetOptions() { var isEnabled = bool.Parse(v); azureDevOpsConfiguration.Value.SetIsEnabled(isEnabled); - log.Info($"Azure DevOps Issue Tracker integration IsEnabled set to: {isEnabled}"); + systemLog.Info($"Azure DevOps Issue Tracker integration IsEnabled set to: {isEnabled}"); }); yield return new ConfigureCommandOption("AzureDevOpsBaseUrl=", AzureDevOpsConfigurationResource.BaseUrlDescription, v => { azureDevOpsConfiguration.Value.SetBaseUrl(v); - log.Info($"Azure DevOps Issue Tracker integration base Url set to: {v}"); + systemLog.Info($"Azure DevOps Issue Tracker integration base Url set to: {v}"); }); yield return new ConfigureCommandOption("AzureDevOpsPersonalAccessToken=", AzureDevOpsConfigurationResource.PersonalAccessTokenDescription, v => { azureDevOpsConfiguration.Value.SetPersonalAccessToken(v.ToSensitiveString()); - log.Info($"Azure DevOps Issue Tracker integration personal access token set to: {v}"); + systemLog.Info($"Azure DevOps Issue Tracker integration personal access token set to: {v}"); }); } } diff --git a/source/Server/Configuration/DatabaseInitializer.cs b/source/Server/Configuration/DatabaseInitializer.cs index 7c603eb..074bd31 100644 --- a/source/Server/Configuration/DatabaseInitializer.cs +++ b/source/Server/Configuration/DatabaseInitializer.cs @@ -6,12 +6,12 @@ namespace Octopus.Server.Extensibility.IssueTracker.AzureDevOps.Configuration { class DatabaseInitializer : ExecuteWhenDatabaseInitializes { - readonly ISystemLog log; + readonly ISystemLog systemLog; readonly IConfigurationStore configurationStore; - public DatabaseInitializer(ISystemLog log, IConfigurationStore configurationStore) + public DatabaseInitializer(ISystemLog systemLog, IConfigurationStore configurationStore) { - this.log = log; + this.systemLog = systemLog; this.configurationStore = configurationStore; } @@ -21,7 +21,7 @@ public override void Execute() if (doc != null) return; - log.Info("Initializing Azure DevOps integration settings"); + systemLog.Info("Initializing Azure DevOps integration settings"); doc = new AzureDevOpsConfiguration(); configurationStore.Create(doc); } diff --git a/source/Server/WorkItems/HtmlConvert.cs b/source/Server/WorkItems/HtmlConvert.cs index fe1fb68..aa70646 100644 --- a/source/Server/WorkItems/HtmlConvert.cs +++ b/source/Server/WorkItems/HtmlConvert.cs @@ -15,11 +15,11 @@ class HtmlConvert .Split(' ') .ToDictionary(n => n, n => true); - private readonly ISystemLog log; + private readonly ISystemLog systemLog; - public HtmlConvert(ISystemLog log) + public HtmlConvert(ISystemLog systemLog) { - this.log = log; + this.systemLog = systemLog; } public string ToPlainText(string html) @@ -35,7 +35,7 @@ public string ToPlainText(string html) } catch (Exception ex) { - log.Info(ex, "Unable to convert Azure DevOps work item comment HTML to plain text."); + systemLog.Info(ex, "Unable to convert Azure DevOps work item comment HTML to plain text."); return html; } } From e8502d8994073d333b213eb09660cc7e331942a1 Mon Sep 17 00:00:00 2001 From: slewis74 Date: Thu, 18 Mar 2021 09:41:15 +1000 Subject: [PATCH 3/3] package updates --- source/Server.Tests/Server.Tests.csproj | 2 +- source/Server/Server.csproj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/Server.Tests/Server.Tests.csproj b/source/Server.Tests/Server.Tests.csproj index 3eaa909..416085d 100644 --- a/source/Server.Tests/Server.Tests.csproj +++ b/source/Server.Tests/Server.Tests.csproj @@ -14,7 +14,7 @@ - + diff --git a/source/Server/Server.csproj b/source/Server/Server.csproj index a5ed029..6cc0fc7 100644 --- a/source/Server/Server.csproj +++ b/source/Server/Server.csproj @@ -17,8 +17,8 @@ - - + +