Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move notifications about Tasks Localization PR from Slack to MS Teams - Part 1 #15917

Merged
merged 7 commits into from
Mar 11, 2022
22 changes: 14 additions & 8 deletions Localize/localize-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,26 @@ stages:
condition: and(succeeded(), or(and(eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule')), eq(variables['build.reason'], 'Manual')))

- powershell: |
$message="Created tasks localization update PR. Someone please approve/merge it. :please-puss-in-boots: $env:PR_LINK"
$titleText = "Azure Pipelines Tasks Localization update PR created - ID $($env:PR_NUMBER)"
$messageText = "Created tasks Localization update PR. Please review and approve/merge [PR $($env:PR_NUMBER)]($($env:PR_LINK)). Related article in [Wiki](https://mseng.visualstudio.com/AzureDevOps/_wiki/wikis/AzureDevOps.wiki/16150/Localization-update)."
$body = [PSCustomObject]@{
text = $message
title = $titleText
text = $messageText
themeColor = "#FFFF00"
} | ConvertTo-Json
Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json'
displayName: 'Send Slack notification about PR opened'
Invoke-RestMethod -Uri $(MSTeamsUri) -Method Post -Body $body -ContentType 'application/json'
displayName: 'Send MS Teams notification about PR opened'
condition: and(succeeded(), eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule'))

- powershell: |
$buildUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)&_a=summary"
$message="Something went wrong while creating tasks localization update PR. Build: $buildUrl"
$titleText = "Azure Pipelines Tasks Localization build failed - ID $($(Build.BuildId))"
$messageText = "Failed to create tasks Localization update PR. Please review the results of failed build [ID $($(Build.BuildId))]($($buildUrl)). Related article in [Wiki](https://mseng.visualstudio.com/AzureDevOps/_wiki/wikis/AzureDevOps.wiki/16150/Localization-update)."
$body = [PSCustomObject]@{
text = $message
title = $titleText
text = $messageText
themeColor = "#FF0000"
} | ConvertTo-Json
Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json'
displayName: 'Send Slack notification about error'
Invoke-RestMethod -Uri $(MSTeamsUri) -Method Post -Body $body -ContentType 'application/json'
displayName: 'Send MS Teams notification about error'
condition: and(failed(), eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule'))
11 changes: 7 additions & 4 deletions ci/open-pullrequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ param(
)

function Get-PullRequest() {
denis-tikhomirov marked this conversation as resolved.
Show resolved Hide resolved
$prInfo = (gh api -X GET repos/:owner/:repo/pulls -F head=":owner:$SourceBranch" -f state=open -f base=master | ConvertFrom-Json)
return $prInfo.html_url
return (gh api -X GET repos/:owner/:repo/pulls -F head=":owner:$SourceBranch" -f state=open -f base=master | ConvertFrom-Json)
}

$openedPR=Get-PullRequest

if ($openedPR.length -ne 0) {
if ($openedPR.html_url.length -ne 0) {
throw "A PR from $SourceBranch to master already exists."
}

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

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

# Getting a number to the opened PR
$PR_NUMBER = (Get-PullRequest).number
Write-Host "##vso[task.setvariable variable=PR_NUMBER]$PR_NUMBER"

# Getting a link to the opened PR
$PR_LINK = Get-PullRequest
$PR_LINK = (Get-PullRequest).html_url
Write-Host "##vso[task.setvariable variable=PR_LINK]$PR_LINK"