Skip to content

Commit 703514a

Browse files
Corrected notifications to send them to MS Teams instead of Slack
1 parent 0b384eb commit 703514a

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

Localize/localize-pipeline.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,26 @@ stages:
9393
condition: and(succeeded(), or(and(eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule')), eq(variables['build.reason'], 'Manual')))
9494

9595
- powershell: |
96-
$message="Created tool-lib localization update PR. Someone please approve/merge it. :please-puss-in-boots: $env:PR_LINK"
96+
$titleText = "Azure Pipelines Tool-lib localization update PR $($env:PR_NUMBER) created"
97+
$messageText = "Created tool-lib localization update PR. Please approve/merge PR [$($env:PR_NUMBER)]($($env:PR_LINK))"
9798
$body = [PSCustomObject]@{
98-
text = $message
99+
title = $titleText
100+
text = $messageText
101+
themeColor = "#FFFF00"
99102
} | ConvertTo-Json
100-
101-
Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json'
102-
displayName: 'Send Slack notification about PR opened'
103+
Invoke-RestMethod -Uri $(MSTeamsUri) -Method Post -Body $body -ContentType 'application/json'
104+
displayName: 'Send MS Teams notification about PR opened'
103105
condition: and(succeeded(), eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule'))
104106
105107
- powershell: |
106108
$buildUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)&_a=summary"
107-
$message="Something went wrong while creating tool-lib localization update PR. Build: $buildUrl"
109+
$titleText = "Azure Pipelines Tool-lib localization build $($(Build.BuildId)) failed"
110+
$messageText = "Failed to create Azure Pipelines Tool-lib localization update PR. Please review the results of failed build [$($(Build.BuildId))]($($buildUrl))"
108111
$body = [PSCustomObject]@{
109-
text = $message
112+
title = $titleText
113+
text = $messageText
114+
themeColor = "#FF0000"
110115
} | ConvertTo-Json
111-
112-
Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json'
113-
displayName: 'Send Slack notification about error'
116+
Invoke-RestMethod -Uri $(MSTeamsUri) -Method Post -Body $body -ContentType 'application/json'
117+
displayName: 'Send MS Teams notification about error'
114118
condition: and(failed(), eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule'))

open-pullrequest.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ param(
55
)
66

77
function Get-PullRequest() {
8-
$prInfo = (gh api -X GET repos/:owner/:repo/pulls -F head=":owner:$SourceBranch" -f state=open -f base=master | ConvertFrom-Json)
9-
return $prInfo.html_url
8+
return (gh api -X GET repos/:owner/:repo/pulls -F head=":owner:$SourceBranch" -f state=open -f base=master | ConvertFrom-Json)
109
}
1110

1211
$openedPR = Get-PullRequest
1312

14-
if ($openedPR.length -ne 0) {
13+
if ($openedPR.html_url.length -ne 0) {
1514
throw "A PR from $SourceBranch to master already exists."
1615
}
1716

@@ -20,6 +19,10 @@ $body = "This PR was auto-generated with [the localization pipeline build]($buil
2019

2120
gh pr create --head $SourceBranch --title 'Localization update' --body $body
2221

22+
# Getting a number to the opened PR
23+
$PR_NUMBER = (Get-PullRequest).number
24+
Write-Host "##vso[task.setvariable variable=PR_NUMBER]$PR_NUMBER"
25+
2326
# Getting a link to the opened PR
24-
$PR_LINK = Get-PullRequest
27+
$PR_LINK = (Get-PullRequest).html_url
2528
Write-Host "##vso[task.setvariable variable=PR_LINK]$PR_LINK"

0 commit comments

Comments
 (0)