From 50b01a8dd44907af0367de2c3eacd2dcae024cef Mon Sep 17 00:00:00 2001 From: slewis74 Date: Tue, 9 Mar 2021 09:32:25 +1000 Subject: [PATCH 1/3] new logging infra --- source/Server.Tests/Server.Tests.csproj | 2 +- source/Server.Tests/WorkItemLinkMapperScenarios.cs | 10 +++++----- source/Server/Configuration/DatabaseInitializer.cs | 4 ++-- .../Server/Configuration/GitHubConfigureCommands.cs | 12 ++++++------ source/Server/Server.csproj | 6 +++--- source/Server/WorkItems/WorkItemLinkMapper.cs | 11 +++++------ 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/source/Server.Tests/Server.Tests.csproj b/source/Server.Tests/Server.Tests.csproj index 8c8bcf5..e818fc0 100644 --- a/source/Server.Tests/Server.Tests.csproj +++ b/source/Server.Tests/Server.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/source/Server.Tests/WorkItemLinkMapperScenarios.cs b/source/Server.Tests/WorkItemLinkMapperScenarios.cs index e34ef48..4b5b829 100644 --- a/source/Server.Tests/WorkItemLinkMapperScenarios.cs +++ b/source/Server.Tests/WorkItemLinkMapperScenarios.cs @@ -51,7 +51,7 @@ public string GetWorkItemDescription(string vcsRoot, string issueNumber, string new IssueComment(0, null, null, null, releaseNoteComment, DateTimeOffset.Now, null, null, null) }); - return new WorkItemLinkMapper(store, new CommentParser(), githubClientLazy, Substitute.For()).GetReleaseNote(vcsRoot, issueNumber, linkData, releaseNotePrefix); + return new WorkItemLinkMapper(Substitute.For(), store, new CommentParser(), githubClientLazy).GetReleaseNote(vcsRoot, issueNumber, linkData, releaseNotePrefix); } [TestCase("https://github.com", "https://github.com/UserX/RepoY", "#1234", ExpectedResult = "https://github.com/UserX/RepoY/issues/1234")] @@ -78,7 +78,7 @@ public void DuplicatesGetIgnored() githubClient.Issue.Get(Arg.Is("UserX"), Arg.Is("RepoY"), Arg.Is(workItemNumber)) .Returns(new Issue("url", "htmlUrl", "commentUrl", "eventsUrl", workItemNumber, ItemState.Open, "Test title", "test body", null, null, new List(), null, new List(), null, 0, null, null, DateTimeOffset.Now, null, workItemNumber, "node", false, null, null)); - var mapper = new WorkItemLinkMapper(store, new CommentParser(), githubClientLazy, Substitute.For()); + var mapper = new WorkItemLinkMapper(Substitute.For(), store, new CommentParser(), githubClientLazy); var workItems = mapper.Map(new OctopusBuildInformation { @@ -108,7 +108,7 @@ public void SourceGetsSet() githubClient.Issue.Get(Arg.Is("UserX"), Arg.Is("RepoY"), Arg.Is(workItemNumber)) .Returns(new Issue("url", "htmlUrl", "commentUrl", "eventsUrl", workItemNumber, ItemState.Open, "Test title", "test body", null, null, new List(), null, new List(), null, 0, null, null, DateTimeOffset.Now, null, workItemNumber, "node", false, null, null)); - var mapper = new WorkItemLinkMapper(store, new CommentParser(), githubClientLazy, Substitute.For()); + var mapper = new WorkItemLinkMapper(Substitute.For(), store, new CommentParser(), githubClientLazy); var workItems = mapper.Map(new OctopusBuildInformation { @@ -132,9 +132,9 @@ public void AzureDevOpsGitCommentsGetIgnored() store.GetBaseUrl().Returns("https://github.com"); store.GetIsEnabled().Returns(true); - var log = Substitute.For(); + var log = Substitute.For(); - var mapper = new WorkItemLinkMapper(store, new CommentParser(), githubClientLazy, log); + var mapper = new WorkItemLinkMapper(log, store, new CommentParser(), githubClientLazy); var workItems = mapper.Map(new OctopusBuildInformation { diff --git a/source/Server/Configuration/DatabaseInitializer.cs b/source/Server/Configuration/DatabaseInitializer.cs index 7e1464c..4788e45 100644 --- a/source/Server/Configuration/DatabaseInitializer.cs +++ b/source/Server/Configuration/DatabaseInitializer.cs @@ -6,10 +6,10 @@ namespace Octopus.Server.Extensibility.IssueTracker.GitHub.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/Configuration/GitHubConfigureCommands.cs b/source/Server/Configuration/GitHubConfigureCommands.cs index 3ed109b..f60a5fd 100644 --- a/source/Server/Configuration/GitHubConfigureCommands.cs +++ b/source/Server/Configuration/GitHubConfigureCommands.cs @@ -7,15 +7,15 @@ namespace Octopus.Server.Extensibility.IssueTracker.GitHub.Configuration { class GitHubConfigureCommands : IContributeToConfigureCommand { - readonly ILog log; - readonly Lazy GitHubConfiguration; + readonly ISystemLog log; + readonly Lazy gitHubConfiguration; public GitHubConfigureCommands( - ILog log, + ISystemLog log, Lazy gitHubConfiguration) { this.log = log; - this.GitHubConfiguration = gitHubConfiguration; + this.gitHubConfiguration = gitHubConfiguration; } public IEnumerable GetOptions() @@ -23,12 +23,12 @@ public IEnumerable GetOptions() yield return new ConfigureCommandOption("GitHubIsEnabled=", "Set whether GitHub issue tracker integration is enabled.", v => { var isEnabled = bool.Parse(v); - GitHubConfiguration.Value.SetIsEnabled(isEnabled); + gitHubConfiguration.Value.SetIsEnabled(isEnabled); log.Info($"GitHub Issue Tracker integration IsEnabled set to: {isEnabled}"); }); yield return new ConfigureCommandOption("GitHubBaseUrl=", GitHubConfigurationResource.GitHubBaseUrlDescription, v => { - GitHubConfiguration.Value.SetBaseUrl(v); + gitHubConfiguration.Value.SetBaseUrl(v); log.Info($"GitHub Issue Tracker integration base Url set to: {v}"); }); } diff --git a/source/Server/Server.csproj b/source/Server/Server.csproj index 36b2817..fac2885 100644 --- a/source/Server/Server.csproj +++ b/source/Server/Server.csproj @@ -14,8 +14,8 @@ - - - + + + \ No newline at end of file diff --git a/source/Server/WorkItems/WorkItemLinkMapper.cs b/source/Server/WorkItems/WorkItemLinkMapper.cs index a80ba24..1a2de68 100644 --- a/source/Server/WorkItems/WorkItemLinkMapper.cs +++ b/source/Server/WorkItems/WorkItemLinkMapper.cs @@ -14,22 +14,21 @@ namespace Octopus.Server.Extensibility.IssueTracker.GitHub.WorkItems { class WorkItemLinkMapper : IWorkItemLinkMapper { + private readonly ISystemLog log; private readonly IGitHubConfigurationStore store; private readonly CommentParser commentParser; private readonly Lazy githubClient; - private readonly ILog log; private readonly Regex ownerRepoRegex = new Regex("(?:https?://)?(?:[^?/\\s]+[?/])(.*)", RegexOptions.Compiled | RegexOptions.IgnoreCase); - - public WorkItemLinkMapper(IGitHubConfigurationStore store, + public WorkItemLinkMapper(ISystemLog log, + IGitHubConfigurationStore store, CommentParser commentParser, - Lazy githubClient, - ILog log) + Lazy githubClient) { + this.log = log; this.store = store; this.commentParser = commentParser; this.githubClient = githubClient; - this.log = log; } public string CommentParser => GitHubConfigurationStore.CommentParser; From 022a5c3078870aac29648017aa658abfc48e8194 Mon Sep 17 00:00:00 2001 From: slewis74 Date: Thu, 11 Mar 2021 09:58:34 +1000 Subject: [PATCH 2/3] variable renames for consistency --- source/Server/Configuration/DatabaseInitializer.cs | 8 ++++---- source/Server/Configuration/GitHubConfigureCommands.cs | 10 +++++----- source/Server/WorkItems/WorkItemLinkMapper.cs | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/source/Server/Configuration/DatabaseInitializer.cs b/source/Server/Configuration/DatabaseInitializer.cs index 4788e45..e02284b 100644 --- a/source/Server/Configuration/DatabaseInitializer.cs +++ b/source/Server/Configuration/DatabaseInitializer.cs @@ -6,12 +6,12 @@ namespace Octopus.Server.Extensibility.IssueTracker.GitHub.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 GitHub integration settings"); + systemLog.Info("Initializing GitHub integration settings"); doc = new GitHubConfiguration(); configurationStore.Create(doc); } diff --git a/source/Server/Configuration/GitHubConfigureCommands.cs b/source/Server/Configuration/GitHubConfigureCommands.cs index f60a5fd..8e8f2be 100644 --- a/source/Server/Configuration/GitHubConfigureCommands.cs +++ b/source/Server/Configuration/GitHubConfigureCommands.cs @@ -7,14 +7,14 @@ namespace Octopus.Server.Extensibility.IssueTracker.GitHub.Configuration { class GitHubConfigureCommands : IContributeToConfigureCommand { - readonly ISystemLog log; + readonly ISystemLog systemLog; readonly Lazy gitHubConfiguration; public GitHubConfigureCommands( - ISystemLog log, + ISystemLog systemLog, Lazy gitHubConfiguration) { - this.log = log; + this.systemLog = systemLog; this.gitHubConfiguration = gitHubConfiguration; } @@ -24,12 +24,12 @@ public IEnumerable GetOptions() { var isEnabled = bool.Parse(v); gitHubConfiguration.Value.SetIsEnabled(isEnabled); - log.Info($"GitHub Issue Tracker integration IsEnabled set to: {isEnabled}"); + systemLog.Info($"GitHub Issue Tracker integration IsEnabled set to: {isEnabled}"); }); yield return new ConfigureCommandOption("GitHubBaseUrl=", GitHubConfigurationResource.GitHubBaseUrlDescription, v => { gitHubConfiguration.Value.SetBaseUrl(v); - log.Info($"GitHub Issue Tracker integration base Url set to: {v}"); + systemLog.Info($"GitHub Issue Tracker integration base Url set to: {v}"); }); } } diff --git a/source/Server/WorkItems/WorkItemLinkMapper.cs b/source/Server/WorkItems/WorkItemLinkMapper.cs index 1a2de68..9af9e0f 100644 --- a/source/Server/WorkItems/WorkItemLinkMapper.cs +++ b/source/Server/WorkItems/WorkItemLinkMapper.cs @@ -14,18 +14,18 @@ namespace Octopus.Server.Extensibility.IssueTracker.GitHub.WorkItems { class WorkItemLinkMapper : IWorkItemLinkMapper { - private readonly ISystemLog log; + private readonly ISystemLog systemLog; private readonly IGitHubConfigurationStore store; private readonly CommentParser commentParser; private readonly Lazy githubClient; private readonly Regex ownerRepoRegex = new Regex("(?:https?://)?(?:[^?/\\s]+[?/])(.*)", RegexOptions.Compiled | RegexOptions.IgnoreCase); - public WorkItemLinkMapper(ISystemLog log, + public WorkItemLinkMapper(ISystemLog systemLog, IGitHubConfigurationStore store, CommentParser commentParser, Lazy githubClient) { - this.log = log; + this.systemLog = systemLog; this.store = store; this.commentParser = commentParser; this.githubClient = githubClient; @@ -48,7 +48,7 @@ public IResultFromExtension Map(OctopusBuildInformation buildInf const string pathComponentIndicatingAzureDevOpsVcs = @"/_git/"; if (buildInformation.VcsRoot.Contains(pathComponentIndicatingAzureDevOpsVcs)) { - log.WarnFormat("The VCS Root '{0}' indicates this build information is Azure DevOps related so GitHub comment references will be ignored", buildInformation.VcsRoot); + systemLog.WarnFormat("The VCS Root '{0}' indicates this build information is Azure DevOps related so GitHub comment references will be ignored", buildInformation.VcsRoot); return ResultFromExtension.Success(new WorkItemLink[0]); } From b00e2169d1cedf9b2ea17cde64afc50d53aa2e20 Mon Sep 17 00:00:00 2001 From: slewis74 Date: Thu, 18 Mar 2021 09:43:28 +1000 Subject: [PATCH 3/3] package updates --- source/Server.Tests/Server.Tests.csproj | 2 +- source/Server.Tests/WorkItemLinkMapperScenarios.cs | 2 +- source/Server/Server.csproj | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/Server.Tests/Server.Tests.csproj b/source/Server.Tests/Server.Tests.csproj index e818fc0..21f9227 100644 --- a/source/Server.Tests/Server.Tests.csproj +++ b/source/Server.Tests/Server.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/source/Server.Tests/WorkItemLinkMapperScenarios.cs b/source/Server.Tests/WorkItemLinkMapperScenarios.cs index 4b5b829..1ff0670 100644 --- a/source/Server.Tests/WorkItemLinkMapperScenarios.cs +++ b/source/Server.Tests/WorkItemLinkMapperScenarios.cs @@ -147,7 +147,7 @@ public void AzureDevOpsGitCommentsGetIgnored() }); var success = workItems as ISuccessResult; Assert.IsNotNull(success, "AzureDevOps VCS root should not be a failure"); - Assert.IsEmpty(success.Value, "AzureDevOps VCS root should return an empty list of links"); + Assert.IsEmpty(success!.Value, "AzureDevOps VCS root should return an empty list of links"); log.Received(1).WarnFormat("The VCS Root '{0}' indicates this build information is Azure DevOps related so GitHub comment references will be ignored", "https://something.com/_git/ProjectX"); } } diff --git a/source/Server/Server.csproj b/source/Server/Server.csproj index fac2885..856b401 100644 --- a/source/Server/Server.csproj +++ b/source/Server/Server.csproj @@ -15,7 +15,7 @@ - - + + \ No newline at end of file