From 2274ce262e0d8c17326dfa7f5273839e3a065663 Mon Sep 17 00:00:00 2001 From: slewis74 Date: Mon, 11 Jan 2021 08:27:28 +1000 Subject: [PATCH 1/5] new TaskLog handling --- source/Server.Tests/Server.Tests.csproj | 4 +- .../Actions/JiraServiceDeskActionHandler.cs | 17 ++++---- .../Server/Deployments/DeploymentObserver.cs | 2 +- source/Server/Deployments/JiraDeployment.cs | 40 +++++++++---------- .../Integration/JiraConnectAppClient.cs | 11 ++--- source/Server/Server.csproj | 8 ++-- .../JiraConnectAppConnectivityCheckAction.cs | 6 ++- 7 files changed, 42 insertions(+), 46 deletions(-) diff --git a/source/Server.Tests/Server.Tests.csproj b/source/Server.Tests/Server.Tests.csproj index d0c14cd..c359702 100644 --- a/source/Server.Tests/Server.Tests.csproj +++ b/source/Server.Tests/Server.Tests.csproj @@ -13,10 +13,10 @@ - + - + diff --git a/source/Server/Actions/JiraServiceDeskActionHandler.cs b/source/Server/Actions/JiraServiceDeskActionHandler.cs index 095ca54..1d3df8c 100644 --- a/source/Server/Actions/JiraServiceDeskActionHandler.cs +++ b/source/Server/Actions/JiraServiceDeskActionHandler.cs @@ -20,37 +20,34 @@ class JiraServiceDeskActionHandler : IActionHandler public ActionHandlerCategory[] Categories => new[] { ActionHandlerCategory.BuiltInStep, ActionHandlerCategory.Atlassian }; readonly JiraDeployment jiraDeployment; - readonly ILog log; private readonly IDeploymentStore deploymentStore; - + public JiraServiceDeskActionHandler( - ILog log, IDeploymentStore deploymentStore, JiraDeployment jiraDeployment) { - this.log = log; this.jiraDeployment = jiraDeployment; this.deploymentStore = deploymentStore; } - + public IActionHandlerResult Execute(IActionHandlerContext context) { string deploymentId = context.Variables.Get(KnownVariables.Deployment.Id, ""); IDeployment deployment = deploymentStore.Get(deploymentId); - + string jiraServiceDeskChangeRequestId = context.Variables.Get("Octopus.Action.JiraIntegration.ServiceDesk.ServiceId"); - + try { - jiraDeployment.PublishToJira("in_progress", deployment, new JiraServiceDeskApiDeployment(jiraServiceDeskChangeRequestId)); + jiraDeployment.PublishToJira("in_progress", deployment, new JiraServiceDeskApiDeployment(jiraServiceDeskChangeRequestId), context.Log); } catch (JiraDeploymentException exception) { throw new ControlledActionFailedException(exception.Message); } - + return ActionHandlerResult.FromSuccess(); } - + } } \ No newline at end of file diff --git a/source/Server/Deployments/DeploymentObserver.cs b/source/Server/Deployments/DeploymentObserver.cs index 78690a2..c0143d7 100644 --- a/source/Server/Deployments/DeploymentObserver.cs +++ b/source/Server/Deployments/DeploymentObserver.cs @@ -21,7 +21,7 @@ public void Handle(DeploymentEvent domainEvent) pm.WorkItems.All(wi => wi.Source != JiraConfigurationStore.CommentParser)))) return; - jiraDeployment.PublishToJira(StateFromEventType(domainEvent.EventType), domainEvent.Deployment, new JiraIssueTrackerApiDeployment()); + jiraDeployment.PublishToJira(StateFromEventType(domainEvent.EventType), domainEvent.Deployment, new JiraIssueTrackerApiDeployment(), domainEvent.TaskLog); } string StateFromEventType(DeploymentEventType eventType) diff --git a/source/Server/Deployments/JiraDeployment.cs b/source/Server/Deployments/JiraDeployment.cs index 9a49891..8e13467 100644 --- a/source/Server/Deployments/JiraDeployment.cs +++ b/source/Server/Deployments/JiraDeployment.cs @@ -21,7 +21,6 @@ namespace Octopus.Server.Extensibility.JiraIntegration.Deployments { class JiraDeployment { - private readonly ILogWithContext log; private readonly IJiraConfigurationStore store; private readonly JiraConnectAppClient connectAppClient; private readonly IInstallationIdProvider installationIdProvider; @@ -36,9 +35,8 @@ class JiraDeployment private DeploymentEnvironmentSettingsMetadataProvider.JiraDeploymentEnvironmentSettings? environmentSettings; private IDeploymentEnvironment? deploymentEnvironment; - + public JiraDeployment( - ILogWithContext log, IJiraConfigurationStore store, JiraConnectAppClient connectAppClient, IInstallationIdProvider installationIdProvider, @@ -52,7 +50,6 @@ public JiraDeployment( IOctopusHttpClientFactory octopusHttpClientFactory ) { - this.log = log; this.store = store; this.connectAppClient = connectAppClient; this.installationIdProvider = installationIdProvider; @@ -72,7 +69,8 @@ bool JiraIntegrationUnavailable(IDeployment deployment) store.GetJiraInstanceType() == JiraInstanceType.Server; } - public void PublishToJira(string eventType, IDeployment deployment, IJiraApiDeployment jiraApiDeployment) + public void PublishToJira(string eventType, IDeployment deployment, IJiraApiDeployment jiraApiDeployment, + ITaskLog taskLog) { if (JiraIntegrationUnavailable(deployment)) { @@ -84,27 +82,27 @@ public void PublishToJira(string eventType, IDeployment deployment, IJiraApiDepl if (string.IsNullOrWhiteSpace(serverUri)) { - log.Warn("To use Jira integration you must have the Octopus server's external url configured (see the Configuration/Nodes page)"); + taskLog.Warn("To use Jira integration you must have the Octopus server's external url configured (see the Configuration/Nodes page)"); return; } - + if (string.IsNullOrWhiteSpace(store.GetConnectAppUrl()) || string.IsNullOrWhiteSpace(store.GetConnectAppPassword()?.Value)) { - log.Warn("Jira integration is enabled but settings are incomplete, ignoring deployment events"); + taskLog.Warn("Jira integration is enabled but settings are incomplete, ignoring deployment events"); return; } - - using (log.OpenBlock($"Sending Jira state update - {eventType}")) + + using (var taskLogBlock = taskLog.CreateBlock($"Sending Jira state update - {eventType}")) { // get token from connect App - var token = connectAppClient.GetAuthTokenFromConnectApp(); + var token = connectAppClient.GetAuthTokenFromConnectApp(taskLogBlock); if (token is null) { - log.Finish(); + taskLogBlock.Finish(); return; } - + deploymentEnvironment = deploymentEnvironmentStore.Get(deployment.EnvironmentId); environmentSettings = deploymentEnvironmentSettingsProvider @@ -114,17 +112,17 @@ public void PublishToJira(string eventType, IDeployment deployment, IJiraApiDepl var data = PrepareOctopusJiraPayload(eventType, serverUri, deployment, jiraApiDeployment); // Push data to Jira - SendToJira(token, data, deployment); + SendToJira(token, data, deployment, taskLogBlock); - log.Finish(); + taskLogBlock.Finish(); } } OctopusJiraPayloadData PrepareOctopusJiraPayload(string eventType, string serverUri, IDeployment deployment, IJiraApiDeployment jiraApiDeployment) { - + var project = projectStore.Get(deployment.ProjectId); - + var release = releaseStore.Get(deployment.ReleaseId); var serverTask = serverTaskStore.Get(deployment.TaskId); @@ -172,10 +170,10 @@ OctopusJiraPayloadData PrepareOctopusJiraPayload(string eventType, string server } }; } - - void SendToJira(string token, OctopusJiraPayloadData data, IDeployment deployment) + + void SendToJira(string token, OctopusJiraPayloadData data, IDeployment deployment, ITaskLog taskLogBlock) { - log.Info($"Sending deployment data to Jira for deployment {deployment.Id}, to {deploymentEnvironment?.Name}({environmentSettings?.JiraEnvironmentType.ToString()}) with state {data.DeploymentsInfo.Deployments[0].State} for issue keys {string.Join(",", data.DeploymentsInfo.Deployments[0].Associations[0].Values)}"); + taskLogBlock.Info($"Sending deployment data to Jira for deployment {deployment.Id}, to {deploymentEnvironment?.Name}({environmentSettings?.JiraEnvironmentType.ToString()}) with state {data.DeploymentsInfo.Deployments[0].State} for issue keys {string.Join(",", data.DeploymentsInfo.Deployments[0].Associations[0].Values)}"); var json = JsonConvert.SerializeObject(data); @@ -188,7 +186,7 @@ void SendToJira(string token, OctopusJiraPayloadData data, IDeployment deploymen var result = client.PostAsync($"{store.GetConnectAppUrl()}/relay/bulk", httpContent).GetAwaiter().GetResult(); if (!result.IsSuccessStatusCode) - log.ErrorFormat("Unable to publish data to Jira. Response code: {0}, Message: {1}", result.StatusCode, result.Content.ReadAsStringAsync().GetAwaiter().GetResult()); + taskLogBlock.ErrorFormat("Unable to publish data to Jira. Response code: {0}, Message: {1}", result.StatusCode, result.Content.ReadAsStringAsync().GetAwaiter().GetResult()); } } } diff --git a/source/Server/Integration/JiraConnectAppClient.cs b/source/Server/Integration/JiraConnectAppClient.cs index 54a45b4..70c04b3 100644 --- a/source/Server/Integration/JiraConnectAppClient.cs +++ b/source/Server/Integration/JiraConnectAppClient.cs @@ -11,31 +11,28 @@ namespace Octopus.Server.Extensibility.JiraIntegration.Integration { class JiraConnectAppClient { - private readonly ILogWithContext log; private readonly IInstallationIdProvider installationIdProvider; private readonly IJiraConfigurationStore configurationStore; private readonly IOctopusHttpClientFactory octopusHttpClientFactory; public JiraConnectAppClient( - ILogWithContext log, IInstallationIdProvider installationIdProvider, IJiraConfigurationStore configurationStore, IOctopusHttpClientFactory octopusHttpClientFactory) { - this.log = log; this.installationIdProvider = installationIdProvider; this.configurationStore = configurationStore; this.octopusHttpClientFactory = octopusHttpClientFactory; } - public string? GetAuthTokenFromConnectApp() + public string? GetAuthTokenFromConnectApp(ILog log) { var username = installationIdProvider.GetInstallationId().ToString(); var password = configurationStore.GetConnectAppPassword(); - return GetAuthTokenFromConnectApp(username, password?.Value); + return GetAuthTokenFromConnectApp(username, password?.Value, log); } - - public string? GetAuthTokenFromConnectApp(string username, string? password) + + public string? GetAuthTokenFromConnectApp(string username, string? password, ILog log) { using (var client = octopusHttpClientFactory.CreateClient()) { diff --git a/source/Server/Server.csproj b/source/Server/Server.csproj index b52d28e..de22349 100644 --- a/source/Server/Server.csproj +++ b/source/Server/Server.csproj @@ -13,10 +13,10 @@ enable - - - + + + - + \ No newline at end of file diff --git a/source/Server/Web/JiraConnectAppConnectivityCheckAction.cs b/source/Server/Web/JiraConnectAppConnectivityCheckAction.cs index eecf844..85de5df 100644 --- a/source/Server/Web/JiraConnectAppConnectivityCheckAction.cs +++ b/source/Server/Web/JiraConnectAppConnectivityCheckAction.cs @@ -4,6 +4,7 @@ using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; +using Octopus.Diagnostics; using Octopus.Server.Extensibility.Extensions.Infrastructure.Web.Api; using Octopus.Server.Extensibility.HostServices.Licensing; using Octopus.Server.Extensibility.JiraIntegration.Configuration; @@ -17,17 +18,20 @@ class JiraConnectAppConnectivityCheckAction : IAsyncApiAction static readonly RequestBodyRegistration Data = new RequestBodyRegistration(); static readonly OctopusJsonRegistration Result = new OctopusJsonRegistration(); + private readonly ISystemLog systemLog; private readonly IJiraConfigurationStore configurationStore; private readonly IInstallationIdProvider installationIdProvider; private readonly JiraConnectAppClient connectAppClient; private readonly IOctopusHttpClientFactory octopusHttpClientFactory; public JiraConnectAppConnectivityCheckAction( + ISystemLog systemLog, IJiraConfigurationStore configurationStore, IInstallationIdProvider installationIdProvider, JiraConnectAppClient connectAppClient, IOctopusHttpClientFactory octopusHttpClientFactory) { + this.systemLog = systemLog; this.configurationStore = configurationStore; this.installationIdProvider = installationIdProvider; this.connectAppClient = connectAppClient; @@ -53,7 +57,7 @@ public async Task ExecuteAsync(IOctoRequest request) return Result.Response(connectivityCheckResponse); } - var token = connectAppClient.GetAuthTokenFromConnectApp(username, password); + var token = connectAppClient.GetAuthTokenFromConnectApp(username, password, systemLog); if (token is null) { connectivityCheckResponse.AddMessage(ConnectivityCheckMessageCategory.Error, "Failed to get authentication token from Jira Connect App."); From 11472a23cdd2f5f3755fb83825cf2cece7bcc4c5 Mon Sep 17 00:00:00 2001 From: slewis74 Date: Tue, 9 Mar 2021 08:26:06 +1000 Subject: [PATCH 2/5] package updates --- source/Server.Tests/Server.Tests.csproj | 2 +- .../Actions/JiraServiceDeskActionHandler.cs | 15 ++++---- source/Server/Deployments/JiraDeployment.cs | 37 +++++++++---------- source/Server/Server.csproj | 6 +-- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/source/Server.Tests/Server.Tests.csproj b/source/Server.Tests/Server.Tests.csproj index c359702..e38ccf6 100644 --- a/source/Server.Tests/Server.Tests.csproj +++ b/source/Server.Tests/Server.Tests.csproj @@ -13,7 +13,7 @@ - + diff --git a/source/Server/Actions/JiraServiceDeskActionHandler.cs b/source/Server/Actions/JiraServiceDeskActionHandler.cs index 1d3df8c..3b75f7b 100644 --- a/source/Server/Actions/JiraServiceDeskActionHandler.cs +++ b/source/Server/Actions/JiraServiceDeskActionHandler.cs @@ -1,7 +1,6 @@ #nullable enable -using Octopus.Diagnostics; +using Octopus.Server.Extensibility.HostServices.Diagnostics; using Octopus.Server.Extensibility.HostServices.Domain.Projects; -using Octopus.Server.Extensibility.HostServices.Model.Projects; using Octopus.Server.Extensibility.JiraIntegration.Deployments; using Sashimi.Server.Contracts; using Sashimi.Server.Contracts.ActionHandlers; @@ -30,16 +29,18 @@ public JiraServiceDeskActionHandler( this.deploymentStore = deploymentStore; } - public IActionHandlerResult Execute(IActionHandlerContext context) + public IActionHandlerResult Execute(IActionHandlerContext context, ITaskLog taskLog) { - string deploymentId = context.Variables.Get(KnownVariables.Deployment.Id, ""); - IDeployment deployment = deploymentStore.Get(deploymentId); + var deploymentId = context.Variables.Get(KnownVariables.Deployment.Id, ""); + var deployment = deploymentStore.Get(deploymentId); - string jiraServiceDeskChangeRequestId = context.Variables.Get("Octopus.Action.JiraIntegration.ServiceDesk.ServiceId"); + var jiraServiceDeskChangeRequestId = context.Variables.Get("Octopus.Action.JiraIntegration.ServiceDesk.ServiceId"); + if (string.IsNullOrWhiteSpace(jiraServiceDeskChangeRequestId)) + throw new ControlledActionFailedException("ServiceId is not set"); try { - jiraDeployment.PublishToJira("in_progress", deployment, new JiraServiceDeskApiDeployment(jiraServiceDeskChangeRequestId), context.Log); + jiraDeployment.PublishToJira("in_progress", deployment, new JiraServiceDeskApiDeployment(jiraServiceDeskChangeRequestId), taskLog); } catch (JiraDeploymentException exception) { diff --git a/source/Server/Deployments/JiraDeployment.cs b/source/Server/Deployments/JiraDeployment.cs index 8e13467..736d181 100644 --- a/source/Server/Deployments/JiraDeployment.cs +++ b/source/Server/Deployments/JiraDeployment.cs @@ -3,9 +3,9 @@ using System.Net.Http.Headers; using System.Text; using Newtonsoft.Json; -using Octopus.Diagnostics; using Octopus.Server.Extensibility.Extensions.Infrastructure.Web.Api; using Octopus.Server.Extensibility.HostServices.Configuration; +using Octopus.Server.Extensibility.HostServices.Diagnostics; using Octopus.Server.Extensibility.HostServices.Domain.Environments; using Octopus.Server.Extensibility.HostServices.Domain.Projects; using Octopus.Server.Extensibility.HostServices.Domain.ServerTasks; @@ -93,29 +93,28 @@ public void PublishToJira(string eventType, IDeployment deployment, IJiraApiDepl return; } - using (var taskLogBlock = taskLog.CreateBlock($"Sending Jira state update - {eventType}")) + var taskLogBlock = taskLog.CreateBlock($"Sending Jira state update - {eventType}"); + + // get token from connect App + var token = connectAppClient.GetAuthTokenFromConnectApp(taskLogBlock); + if (token is null) { - // get token from connect App - var token = connectAppClient.GetAuthTokenFromConnectApp(taskLogBlock); - if (token is null) - { - taskLogBlock.Finish(); - return; - } + taskLogBlock.Finish(); + return; + } - deploymentEnvironment = deploymentEnvironmentStore.Get(deployment.EnvironmentId); - environmentSettings = - deploymentEnvironmentSettingsProvider - .GetSettings( - JiraConfigurationStore.SingletonId, deployment.EnvironmentId) ?? new DeploymentEnvironmentSettingsMetadataProvider.JiraDeploymentEnvironmentSettings(); + deploymentEnvironment = deploymentEnvironmentStore.Get(deployment.EnvironmentId); + environmentSettings = + deploymentEnvironmentSettingsProvider + .GetSettings( + JiraConfigurationStore.SingletonId, deployment.EnvironmentId) ?? new DeploymentEnvironmentSettingsMetadataProvider.JiraDeploymentEnvironmentSettings(); - var data = PrepareOctopusJiraPayload(eventType, serverUri, deployment, jiraApiDeployment); + var data = PrepareOctopusJiraPayload(eventType, serverUri, deployment, jiraApiDeployment); - // Push data to Jira - SendToJira(token, data, deployment, taskLogBlock); + // Push data to Jira + SendToJira(token, data, deployment, taskLogBlock); - taskLogBlock.Finish(); - } + taskLogBlock.Finish(); } OctopusJiraPayloadData PrepareOctopusJiraPayload(string eventType, string serverUri, IDeployment deployment, IJiraApiDeployment jiraApiDeployment) diff --git a/source/Server/Server.csproj b/source/Server/Server.csproj index de22349..cc0845f 100644 --- a/source/Server/Server.csproj +++ b/source/Server/Server.csproj @@ -13,10 +13,10 @@ enable - + - + - + \ No newline at end of file From 3c697a8b2c8cf0fb0b3cffc5ebe16ae96cda227e Mon Sep 17 00:00:00 2001 From: slewis74 Date: Thu, 11 Mar 2021 09:56:45 +1000 Subject: [PATCH 3/5] missed ctor params that were ILog --- .../Configuration/DatabaseInitializer.cs | 8 ++++---- .../Configuration/JiraConfigureCommands.cs | 12 +++++------ source/Server/Integration/JiraRestClient.cs | 16 +++++++-------- source/Server/JiraIntegrationExtension.cs | 20 +++++++++---------- .../JiraCredentialsConnectivityCheckAction.cs | 10 +++++----- source/Server/WorkItems/WorkItemLinkMapper.cs | 8 ++++---- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/source/Server/Configuration/DatabaseInitializer.cs b/source/Server/Configuration/DatabaseInitializer.cs index 8613e05..fe4090e 100644 --- a/source/Server/Configuration/DatabaseInitializer.cs +++ b/source/Server/Configuration/DatabaseInitializer.cs @@ -6,12 +6,12 @@ namespace Octopus.Server.Extensibility.JiraIntegration.Configuration { class DatabaseInitializer : ExecuteWhenDatabaseInitializes { - readonly ILog log; + readonly ISystemLog systemLog; readonly IConfigurationStore configurationStore; - public DatabaseInitializer(ILog log, IConfigurationStore configurationStore) + public DatabaseInitializer(ISystemLog systemLog, IConfigurationStore configurationStore) { - this.log = log; + this.systemLog = systemLog; this.configurationStore = configurationStore; } @@ -30,7 +30,7 @@ public override void Execute() return; } - log.Info("Initializing Jira integration settings"); + systemLog.Info("Initializing Jira integration settings"); doc = new JiraConfiguration(); configurationStore.Create(doc); } diff --git a/source/Server/Configuration/JiraConfigureCommands.cs b/source/Server/Configuration/JiraConfigureCommands.cs index 8853564..cb773a6 100644 --- a/source/Server/Configuration/JiraConfigureCommands.cs +++ b/source/Server/Configuration/JiraConfigureCommands.cs @@ -7,14 +7,14 @@ namespace Octopus.Server.Extensibility.JiraIntegration.Configuration { class JiraConfigureCommands : IContributeToConfigureCommand { - readonly ILog log; + readonly ISystemLog systemLog; readonly Lazy jiraConfiguration; public JiraConfigureCommands( - ILog log, + ISystemLog systemLog, Lazy jiraConfiguration) { - this.log = log; + this.systemLog = systemLog; this.jiraConfiguration = jiraConfiguration; } @@ -24,17 +24,17 @@ public IEnumerable GetOptions() { var isEnabled = bool.Parse(v); jiraConfiguration.Value.SetIsEnabled(isEnabled); - log.Info($"Jira Integration IsEnabled set to: {isEnabled}"); + systemLog.Info($"Jira Integration IsEnabled set to: {isEnabled}"); }); yield return new ConfigureCommandOption("jiraBaseUrl=", JiraConfigurationResource.JiraBaseUrlDescription, v => { jiraConfiguration.Value.SetBaseUrl(v); - log.Info($"Jira Integration base Url set to: {v}"); + systemLog.Info($"Jira Integration base Url set to: {v}"); }); yield return new ConfigureCommandOption("jiraConnectAppUrl=", "Set the URL for the Jira Connect App", v => { jiraConfiguration.Value.SetConnectAppUrl(v); - log.Info($"Jira Integration ConnectAppUrl set to: {v}"); + systemLog.Info($"Jira Integration ConnectAppUrl set to: {v}"); }, hide: true); } } diff --git a/source/Server/Integration/JiraRestClient.cs b/source/Server/Integration/JiraRestClient.cs index c05acc1..a22a1f6 100644 --- a/source/Server/Integration/JiraRestClient.cs +++ b/source/Server/Integration/JiraRestClient.cs @@ -20,14 +20,14 @@ class JiraRestClient : IJiraRestClient private readonly HttpClient httpClient; private readonly string baseUrl; - private readonly ILog log; + private readonly ISystemLog systemLog; private readonly string baseApiUri = "rest/api/2"; - public JiraRestClient(string baseUrl, string username, string? password, ILog log, + public JiraRestClient(string baseUrl, string username, string? password, ISystemLog systemLog, IOctopusHttpClientFactory octopusHttpClientFactory) { this.baseUrl = baseUrl; - this.log = log; + this.systemLog = systemLog; authorizationHeader = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}"))); httpClient = CreateHttpClient(octopusHttpClientFactory); @@ -77,12 +77,12 @@ public async Task ConnectivityCheck() if (response.IsSuccessStatusCode) { var result = await GetResult(response); - log.Info($"Retrieved Jira Work Item data for work item id {workItemId}"); + systemLog.Info($"Retrieved Jira Work Item data for work item id {workItemId}"); return result; } var msg = $"Failed to retrieve Jira issue '{workItemId}' from {baseUrl}. Response Code: {response.StatusCode}{(!string.IsNullOrEmpty(response.ReasonPhrase) ? $" (Reason: {response.ReasonPhrase})" : "")}"; - log.Warn(msg); + systemLog.Warn(msg); return null; } @@ -95,9 +95,9 @@ public async Task GetIssueComments(string workItemId) var msg = $"Failed to retrieve comments for Jira issue '{workItemId}' from {baseUrl}. Response Code: {response.StatusCode}{(!string.IsNullOrEmpty(response.ReasonPhrase) ? $" (Reason: {response.ReasonPhrase})" : "")}"; if (response.StatusCode == HttpStatusCode.NotFound) - log.Trace(msg); + systemLog.Trace(msg); else - log.Warn(msg); + systemLog.Warn(msg); return new JiraIssueComments(); } @@ -115,7 +115,7 @@ async Task GetResult(HttpResponseMessage response) response.Headers.TryGetValues("Content-Type", out var contentType); var errMsg = $"Error parsing JSON content for type {typeof(TResult)}. Content Type: '{contentType}', content: {content}"; - log.Error(errMsg); + systemLog.Error(errMsg); throw; } } diff --git a/source/Server/JiraIntegrationExtension.cs b/source/Server/JiraIntegrationExtension.cs index 42eef93..aaea4f1 100644 --- a/source/Server/JiraIntegrationExtension.cs +++ b/source/Server/JiraIntegrationExtension.cs @@ -27,7 +27,7 @@ public void Load(ContainerBuilder builder) builder.RegisterType() .As() .InstancePerLifetimeScope(); - + builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType() @@ -42,7 +42,7 @@ public void Load(ContainerBuilder builder) .InstancePerLifetimeScope(); builder.RegisterType().AsSelf().InstancePerDependency(); - + builder.RegisterType() .As() .InstancePerLifetimeScope(); @@ -57,7 +57,7 @@ public void Load(ContainerBuilder builder) builder.RegisterType().AsSelf().InstancePerDependency(); builder.RegisterType().AsSelf().InstancePerDependency(); - + builder.RegisterType().AsSelf().InstancePerDependency(); builder.RegisterType().As().InstancePerDependency(); @@ -67,24 +67,24 @@ public void Load(ContainerBuilder builder) .As() .AsSelf() .InstancePerDependency(); - + builder.Register(c => { var store = c.Resolve(); if (!store.GetIsEnabled()) return null; - + var baseUrl = store.GetBaseUrl(); var username = store.GetJiraUsername(); if (baseUrl == null || username == null) return null; - + var password = store.GetJiraPassword(); return new JiraRestClient( - baseUrl, - username, - password?.Value, - c.Resolve(), + baseUrl, + username, + password?.Value, + c.Resolve(), c.Resolve() ); }).As() diff --git a/source/Server/Web/JiraCredentialsConnectivityCheckAction.cs b/source/Server/Web/JiraCredentialsConnectivityCheckAction.cs index 4c0525c..c2f7ea1 100644 --- a/source/Server/Web/JiraCredentialsConnectivityCheckAction.cs +++ b/source/Server/Web/JiraCredentialsConnectivityCheckAction.cs @@ -15,13 +15,13 @@ class JiraCredentialsConnectivityCheckAction : IAsyncApiAction private readonly IJiraConfigurationStore configurationStore; private readonly IOctopusHttpClientFactory octopusHttpClientFactory; - private readonly ILog log; + private readonly ISystemLog systemLog; - public JiraCredentialsConnectivityCheckAction(IJiraConfigurationStore configurationStore, IOctopusHttpClientFactory octopusHttpClientFactory, ILog log) + public JiraCredentialsConnectivityCheckAction(IJiraConfigurationStore configurationStore, IOctopusHttpClientFactory octopusHttpClientFactory, ISystemLog systemLog) { this.configurationStore = configurationStore; this.octopusHttpClientFactory = octopusHttpClientFactory; - this.log = log; + this.systemLog = systemLog; } public async Task ExecuteAsync(IOctoRequest request) @@ -45,7 +45,7 @@ public async Task ExecuteAsync(IOctoRequest request) return Result.Response(response); } - var jiraRestClient = new JiraRestClient(baseUrl, username, password, log, octopusHttpClientFactory); + var jiraRestClient = new JiraRestClient(baseUrl, username, password, systemLog, octopusHttpClientFactory); var connectivityCheckResponse = await jiraRestClient.ConnectivityCheck(); if (connectivityCheckResponse.Messages.All(m => m.Category != ConnectivityCheckMessageCategory.Error)) { @@ -60,7 +60,7 @@ public async Task ExecuteAsync(IOctoRequest request) return Result.Response(connectivityCheckResponse); } } - + #nullable disable class JiraCredentialsConnectionCheckData { diff --git a/source/Server/WorkItems/WorkItemLinkMapper.cs b/source/Server/WorkItems/WorkItemLinkMapper.cs index e9b4296..ad5d66b 100644 --- a/source/Server/WorkItems/WorkItemLinkMapper.cs +++ b/source/Server/WorkItems/WorkItemLinkMapper.cs @@ -17,17 +17,17 @@ class WorkItemLinkMapper : IWorkItemLinkMapper private readonly IJiraConfigurationStore store; private readonly CommentParser commentParser; private readonly Lazy jira; - private readonly ILog log; + private readonly ISystemLog systemLog; public WorkItemLinkMapper(IJiraConfigurationStore store, CommentParser commentParser, Lazy jira, - ILog log) + ISystemLog systemLog) { this.store = store; this.commentParser = commentParser; this.jira = jira; - this.log = log; + this.systemLog = systemLog; } public string CommentParser => JiraConfigurationStore.CommentParser; @@ -58,7 +58,7 @@ private WorkItemLink[] ConvertWorkItemLinks(IEnumerable workItemIds, str var issue = jira.Value.GetIssue(workItemId).GetAwaiter().GetResult(); if (issue is null) { - log.Warn($"Parsed work item id {workItemId} from commit message but was unable to locate it in Jira"); + systemLog.Warn($"Parsed work item id {workItemId} from commit message but was unable to locate it in Jira"); return null; } From 4ee22ec2ce08ad2565e21bb80d792a52e706d186 Mon Sep 17 00:00:00 2001 From: slewis74 Date: Thu, 11 Mar 2021 09:57:16 +1000 Subject: [PATCH 4/5] missed a test --- source/Server.Tests/WorkItemLinkMapperScenarios.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/Server.Tests/WorkItemLinkMapperScenarios.cs b/source/Server.Tests/WorkItemLinkMapperScenarios.cs index 0750775..db3de3e 100644 --- a/source/Server.Tests/WorkItemLinkMapperScenarios.cs +++ b/source/Server.Tests/WorkItemLinkMapperScenarios.cs @@ -52,7 +52,7 @@ public string GetWorkItemDescription(string linkData, string releaseNotePrefix, Comments = new [] {new JiraIssueComment { Body = releaseNote }} }); - return new WorkItemLinkMapper(store, new CommentParser(), jiraClientLazy, Substitute.For()).GetReleaseNote(jiraIssue, releaseNotePrefix); + return new WorkItemLinkMapper(store, new CommentParser(), jiraClientLazy, Substitute.For()).GetReleaseNote(jiraIssue, releaseNotePrefix); } [Test] @@ -71,7 +71,7 @@ public void DuplicatesGetIgnored() Comments = new [] {new JiraIssueComment { Body = string.Empty }} }); - var mapper = new WorkItemLinkMapper(store, new CommentParser(), jiraClientLazy, Substitute.For()); + var mapper = new WorkItemLinkMapper(store, new CommentParser(), jiraClientLazy, Substitute.For()); var workItems = mapper.Map(new OctopusBuildInformation { @@ -101,7 +101,7 @@ public void SourceGetsSet() Comments = new [] {new JiraIssueComment { Body = string.Empty }} }); - var mapper = new WorkItemLinkMapper(store, new CommentParser(), jiraClientLazy, Substitute.For()); + var mapper = new WorkItemLinkMapper(store, new CommentParser(), jiraClientLazy, Substitute.For()); var workItems = mapper.Map(new OctopusBuildInformation { From c49898521ca099329e5127364a8126c428c198a1 Mon Sep 17 00:00:00 2001 From: slewis74 Date: Thu, 18 Mar 2021 20:16:54 +1000 Subject: [PATCH 5/5] package updates --- source/Server.Tests/Server.Tests.csproj | 2 +- source/Server/Server.csproj | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/Server.Tests/Server.Tests.csproj b/source/Server.Tests/Server.Tests.csproj index e38ccf6..8b8d958 100644 --- a/source/Server.Tests/Server.Tests.csproj +++ b/source/Server.Tests/Server.Tests.csproj @@ -13,7 +13,7 @@ - + diff --git a/source/Server/Server.csproj b/source/Server/Server.csproj index cc0845f..56b72fd 100644 --- a/source/Server/Server.csproj +++ b/source/Server/Server.csproj @@ -13,10 +13,10 @@ enable - + - + - + \ No newline at end of file