Files

73 lines
1.9 KiB
PowerShell
Raw Permalink Normal View History

2020-07-02 17:05:38 +03:00
<#
.SYNOPSIS
Sending messages using Incoming Webhooks
.PARAMETER Url
Required parameter. Incoming Webhook URL to post a message
.PARAMETER ToolName
Required parameter. The name of tool
.PARAMETER ToolVersion
Optional parameter. Specifies the version of tool
2020-07-02 17:05:38 +03:00
.PARAMETER PipelineUrl
Optional parameter. The pipeline URL
2020-07-02 17:05:38 +03:00
.PARAMETER ImageUrl
Optional parameter. The image URL
.PARAMETER Text
Optional parameter. The message to post
.PARAMETER AddToToolsetFlag
Optional parameter. Flag to alternate message text for adding new version of a tool to toolset notification
2020-07-02 17:05:38 +03:00
#>
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[System.Uri]$Url,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[System.String]$ToolName,
[System.String]$ToolVersion,
[System.String]$PipelineUrl,
[System.String]$ImageUrl = 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png',
[System.String]$Text,
[Switch]$AddToToolsetFlag
2020-07-02 17:05:38 +03:00
)
# Import helpers module
2020-07-03 13:53:05 +03:00
Import-Module $PSScriptRoot/helpers.psm1 -DisableNameChecking
2020-07-02 17:05:38 +03:00
# Create JSON body
if ([string]::IsNullOrWhiteSpace($Text)) {
if ($AddToToolsetFlag) {
$Text = "The following versions of '$toolName' are available, consider adding them to toolset: $toolVersion"
} else {
$Text = "The following versions of '$toolName' are available to upload: $toolVersion"
}
2020-12-09 11:48:13 +03:00
}
if (-not ([string]::IsNullOrWhiteSpace($PipelineUrl))) {
$Text += "\nLink to the pipeline: $pipelineUrl"
}
2020-07-02 17:05:38 +03:00
$jsonBodyMessage = @"
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "$Text"
2020-07-02 17:05:38 +03:00
},
"accessory": {
"type": "image",
"image_url": "$imageUrl",
"alt_text": "$toolName"
}
}
]
}
"@
# Send Slack message
$null = Send-SlackPostMessageIncomingWebHook -Uri $url -Body $jsonBodyMessage