public async Task <IMessageHandle> SendDeploymentUpdateNotification( string channel, DeploymentUpdate deploymentUpdate, DeploymentUpdateStatus status ) { if (channel == null) { throw new ArgumentNullException(nameof(channel)); } if (deploymentUpdate == null) { throw new ArgumentNullException(nameof(deploymentUpdate)); } // var channelsResponse = await _actualClient.APIRequestWithTokenAsync<ConversationsListResponse>( // new Tuple<string, string>("exclude_archived", "true"), // new Tuple<string, string>("types", "public_channel,private_channel") // ); // // var channelMetadata = channelsResponse.channels.FirstOrDefault(c => // c.name.Equals(channel, StringComparison.OrdinalIgnoreCase) // ); // // if (channelMetadata == null) // { // throw new Exception($"Could not find channel with name {channel}"); // } return(await PostMessageAsync( channel, BuildDeploymentUpdateMessage(deploymentUpdate, status) )); }
public async Task FinishDeploymentUpdate( DeploymentUpdate deploymentUpdate, DeploymentUpdateStatus finalStatus ) { await ChangeDeploymentUpdateStatus(deploymentUpdate, finalStatus); _applicationService.SetCurrentImageTag(deploymentUpdate.Application, deploymentUpdate.Image, deploymentUpdate.TargetTag); }
public async Task ChangeDeploymentUpdateStatus(DeploymentUpdate deploymentUpdate, DeploymentUpdateStatus status) { _deploymentUpdates[deploymentUpdate] = status; if (_notificationHandles.TryGetValue(deploymentUpdate, out var handle)) { try { _log.LogInformation("Submitting {@DeploymentUpdate} notification change to slack {@MessageHandle}. ", deploymentUpdate, handle); var newHandle = await _slackClient.UpdateDeploymentUpdateNotification(handle, deploymentUpdate, status); _notificationHandles.TryUpdate(deploymentUpdate, newHandle, handle); } catch (Exception e) { _log.LogError(e, "Failed to submit {@DeploymentUpdate} notification {@MessageHandle}", deploymentUpdate, handle); } } }
public async Task <IMessageHandle> UpdateDeploymentUpdateNotification( IMessageHandle handle, DeploymentUpdate deploymentUpdate, DeploymentUpdateStatus status ) { if (handle == null) { throw new ArgumentNullException(nameof(handle)); } if (deploymentUpdate == null) { throw new ArgumentNullException(nameof(deploymentUpdate)); } return(await UpdateMessageAsync( handle as SingleMessageHandle, BuildDeploymentUpdateMessage(deploymentUpdate, status) )); }
private SlackMessage BuildDeploymentUpdateMessage(DeploymentUpdate deploymentUpdate, DeploymentUpdateStatus status) { return(new SlackMessage( $"A new image of *{deploymentUpdate.Image.Repository}* was detected (tag *{deploymentUpdate.TargetTag}*).", new IBlock[] { new SectionBlock() { text = new Text() { type = "mrkdwn", text = $"A new image of *{deploymentUpdate.Image.Repository}* was detected (tag *{deploymentUpdate.TargetTag}*)." } }, new DividerBlock(), new SectionBlock() { fields = new Text[] { new Text() { text = $"*From*\n{deploymentUpdate.CurrentTag}", type = "mrkdwn" }, new Text() { text = $"*To*\n{deploymentUpdate.TargetTag}", type = "mrkdwn" }, } }, new SectionBlock() { fields = new Text[] { new Text() { text = $"*Application*\n{deploymentUpdate.Application}", type = "mrkdwn" }, new Text() { text = $"*Status*\n{status}", type = "mrkdwn" }, } } } )); }