|
| 1 | +# ---------------------------------------------------------------------------------- |
| 2 | +# |
| 3 | +# Copyright Microsoft Corporation |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | +# ---------------------------------------------------------------------------------- |
| 14 | + |
| 15 | +<# |
| 16 | +.SYNOPSIS |
| 17 | + Sync ADO wiki aliases content to fabricbot.json. |
| 18 | +
|
| 19 | +#> |
| 20 | +param( |
| 21 | + [Parameter(Mandatory = $true)] |
| 22 | + [string]$ADOToken |
| 23 | +) |
| 24 | + |
| 25 | +# get wiki content |
| 26 | +$username = "" |
| 27 | +$password = $ADOToken |
| 28 | +$pair = "{0}:{1}" -f ($username, $password) |
| 29 | +$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair) |
| 30 | +$token = [System.Convert]::ToBase64String($bytes) |
| 31 | +$headers = @{ |
| 32 | + Authorization = "Basic {0}" -f ($token) |
| 33 | +} |
| 34 | + |
| 35 | +$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 |
| 36 | +$rows = ($response.content -split "\n") | Where-Object { $_ -like '|*' } | Select-Object -Skip 2 |
| 37 | +$aliases = [System.Collections.SortedList]::new() |
| 38 | + |
| 39 | +foreach ($item in $rows) { |
| 40 | + $list = $item -split "\|" |
| 41 | + if ($list.Count -eq 1) { continue } |
| 42 | + if ($list[1].Trim().Length -gt 0) { |
| 43 | + if ($list.Count -gt 3) { |
| 44 | + $aliases.Add($list[1].Trim(), $list[3].Trim()) |
| 45 | + } |
| 46 | + else { |
| 47 | + $aliases.Add($list[1].Trim(), "") |
| 48 | + } |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +# change json file |
| 53 | +$WholeJson = Get-Content -Raw -Path .github/fabricbot.json | ConvertFrom-Json |
| 54 | + |
| 55 | +$WholeJson.tasks | ForEach-Object { |
| 56 | + if ($_.taskType -eq 'scheduledAndTrigger') { |
| 57 | + $labelsAndMentionsArrayList = New-Object System.Collections.ArrayList |
| 58 | + foreach ($entry in $aliases.GetEnumerator()) { |
| 59 | + if ($entry.Value -eq "") { |
| 60 | + continue |
| 61 | + } |
| 62 | + $labels = @("Service Attention", $entry.Key) |
| 63 | + $mentionees = @($entry.Value -split "," | ForEach-Object { $_.Trim() }) |
| 64 | + $item = [PSCustomObject]@{ |
| 65 | + labels = $labels |
| 66 | + mentionees = $mentionees |
| 67 | + } |
| 68 | + [void]$labelsAndMentionsArrayList.Add($item) |
| 69 | + } |
| 70 | + $_.config.labelsAndMentions = $labelsAndMentionsArrayList.ToArray() |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +($WholeJson | ConvertTo-Json -Depth 32) | Out-File -FilePath .github/fabricbot.json |
0 commit comments