-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pipeline yml for syncing fabricbot.json aliases (#20772)
* add pipeline yml for syncing fabricbot.json aliases * change git user name and email in script * change inline script to GetWiki2Json.ps1 file * remove unnecessary code * change wrong dir * change to my personal repo for test * change the usage of token * change CreatePR.ps1 for test * correct ParseWiki2Json.ps1 * remove unnecessary output * remove quote * finish test, change back to Azure repo * change branch name * change some names * remove the use of magic number * change commit message * remove redundant git pull * change the way of getting wiki content * change space to - * add md * set current dir * use space * use - * still use ADOToken * use a better wiki url * test purpose * test2 * test oauth * test3 * finish test * test again * test * finish test * test cron * test double pr * solve double pr * test * test * test * finish test * test * finish test * test restapi * te * finish test * test * finish test * filter pr * test * test * test * test * finish test --------- Co-authored-by: Hongtu Zhang (FA Talent) <v-hongtzhang@microsoft.com>
- Loading branch information
1 parent
ebe9037
commit 64c1955
Showing
3 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Variable 'ADOToken' and 'BotAccessToken' was defined in the Variables tab | ||
schedules: | ||
- cron: "50 15 * * *" | ||
displayName: 11:50 PM (UTC + 8:00) China Daily Run | ||
branches: | ||
include: | ||
- main | ||
|
||
jobs: | ||
- job: UpdateJson | ||
displayName: Update fabricbot.json | ||
steps: | ||
- pwsh: | | ||
./tools/Github/ParseWiki2Json.ps1 -ADOToken $(ADOToken) | ||
displayName: Update fabricbot.json file locally | ||
- task: PowerShell@2 | ||
displayName: Git commit and push | ||
inputs: | ||
targetType: inline | ||
script: | | ||
git config --global user.email "65331932+azure-powershell-bot@users.noreply.github.com" | ||
git config --global user.name "azure-powershell-bot" | ||
git checkout -b "internal/sync-fabricbot-json" | ||
git add . | ||
git commit -m "Sync fabricbot.json" | ||
git remote set-url origin https://$(BotAccessToken)@github.com/Azure/azure-powershell.git; | ||
git push origin internal/sync-fabricbot-json --force | ||
- pwsh: | | ||
$Title = "Sync fabricbot.json According To ADO Wiki Page" | ||
$HeadBranch = "internal/sync-fabricbot-json" | ||
$BaseBranch = "main" | ||
$Description = "This PR sync taskType: scheduledAndTrigger part of fabricbot.json from table of Service-Team-Label-and-Contact-List in ADO wiki page" | ||
./tools/Github/CreatePR.ps1 -Title $Title -HeadBranch $HeadBranch -BaseBranch $BaseBranch -BotAccessToken $(BotAccessToken) -Description $Description | ||
displayName: Create PR to main branch | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# ---------------------------------------------------------------------------------- | ||
# | ||
# Copyright Microsoft Corporation | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ---------------------------------------------------------------------------------- | ||
|
||
<# | ||
.SYNOPSIS | ||
Sync ADO wiki aliases content to fabricbot.json. | ||
#> | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[string]$ADOToken | ||
) | ||
|
||
# get wiki content | ||
$username = "" | ||
$password = $ADOToken | ||
$pair = "{0}:{1}" -f ($username, $password) | ||
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair) | ||
$token = [System.Convert]::ToBase64String($bytes) | ||
$headers = @{ | ||
Authorization = "Basic {0}" -f ($token) | ||
} | ||
|
||
$response = Invoke-RestMethod 'https://dev.azure.com/azure-sdk/internal/_apis/wiki/wikis/internal.wiki/pages?path=/Engineering%20System/GitHub%20Repos/Issue%20Management/Service%20Team%20Label%20and%20Contact%20List&includeContent=True' -Headers $headers | ||
$rows = ($response.content -split "\n") | Where-Object { $_ -like '|*' } | Select-Object -Skip 2 | ||
$aliases = [System.Collections.SortedList]::new() | ||
|
||
foreach ($item in $rows) { | ||
$list = $item -split "\|" | ||
if ($list.Count -eq 1) { continue } | ||
if ($list[1].Trim().Length -gt 0) { | ||
if ($list.Count -gt 3) { | ||
$aliases.Add($list[1].Trim(), $list[3].Trim()) | ||
} | ||
else { | ||
$aliases.Add($list[1].Trim(), "") | ||
} | ||
} | ||
} | ||
|
||
# change json file | ||
$WholeJson = Get-Content -Raw -Path .github/fabricbot.json | ConvertFrom-Json | ||
|
||
$WholeJson.tasks | ForEach-Object { | ||
if ($_.taskType -eq 'scheduledAndTrigger') { | ||
$labelsAndMentionsArrayList = New-Object System.Collections.ArrayList | ||
foreach ($entry in $aliases.GetEnumerator()) { | ||
if ($entry.Value -eq "") { | ||
continue | ||
} | ||
$labels = @("Service Attention", $entry.Key) | ||
$mentionees = @($entry.Value -split "," | ForEach-Object { $_.Trim() }) | ||
$item = [PSCustomObject]@{ | ||
labels = $labels | ||
mentionees = $mentionees | ||
} | ||
[void]$labelsAndMentionsArrayList.Add($item) | ||
} | ||
$_.config.labelsAndMentions = $labelsAndMentionsArrayList.ToArray() | ||
} | ||
} | ||
|
||
($WholeJson | ConvertTo-Json -Depth 32) | Out-File -FilePath .github/fabricbot.json |