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

add pipeline yml for syncing fabricbot.json aliases #20772

Merged
merged 53 commits into from
Feb 9, 2023
Merged
Changes from 2 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2e9c6d2
add pipeline yml for syncing fabricbot.json aliases
Jan 30, 2023
f77bd21
change git user name and email in script
Jan 30, 2023
38b1f70
change inline script to GetWiki2Json.ps1 file
Feb 1, 2023
2e5c08a
remove unnecessary code
Feb 1, 2023
80aa187
change wrong dir
Feb 1, 2023
2831172
change to my personal repo for test
Feb 1, 2023
74313ff
change the usage of token
Feb 1, 2023
d25175c
change CreatePR.ps1 for test
Feb 1, 2023
c91b484
correct ParseWiki2Json.ps1
Feb 1, 2023
59a49c5
remove unnecessary output
Feb 1, 2023
d5e453e
remove quote
Feb 1, 2023
cf4bc10
finish test, change back to Azure repo
Feb 1, 2023
17b5be6
change branch name
Feb 1, 2023
11eccd6
change some names
Feb 1, 2023
bb4d892
remove the use of magic number
Feb 2, 2023
5b248b3
change commit message
Feb 2, 2023
91438f7
remove redundant git pull
Feb 2, 2023
dc0e489
change the way of getting wiki content
Feb 2, 2023
b5e6f7e
change space to -
Feb 2, 2023
0d2bbff
add md
Feb 2, 2023
affdb10
set current dir
Feb 2, 2023
ab482d1
use space
Feb 2, 2023
59d5cd6
use -
Feb 2, 2023
5d90c4b
still use ADOToken
Feb 2, 2023
635afa3
use a better wiki url
Feb 2, 2023
bcec48e
test purpose
Feb 2, 2023
0eef6bb
test2
Feb 2, 2023
fabc2b9
test oauth
Feb 2, 2023
60c55cb
test3
Feb 2, 2023
d796b9d
finish test
Feb 2, 2023
fdf250c
test again
Feb 5, 2023
198f2b0
test
Feb 6, 2023
51fffc1
finish test
Feb 6, 2023
ed35c0e
test cron
Feb 6, 2023
0f4ae7c
test double pr
Feb 6, 2023
b1924f2
solve double pr
Feb 6, 2023
d323d0d
test
Feb 7, 2023
d5ac369
test
Feb 7, 2023
e663991
test
Feb 7, 2023
95ff796
finish test
Feb 7, 2023
2d350cb
test
Feb 7, 2023
9bc5aab
finish test
Feb 7, 2023
2c5648d
test restapi
Feb 8, 2023
e829d30
te
Feb 8, 2023
e603ebb
finish test
Feb 8, 2023
878e781
test
Feb 8, 2023
077a711
finish test
Feb 8, 2023
9681afb
filter pr
Feb 8, 2023
40f8997
test
Feb 8, 2023
1b3634a
test
Feb 8, 2023
734537a
test
Feb 8, 2023
72f6684
test
Feb 8, 2023
1c4b9f3
finish test
Feb 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .azure-pipelines/sync-aliases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
resources:
repositories:
- repository: self
type: git
ref: main

trigger: none
isra-fel marked this conversation as resolved.
Show resolved Hide resolved

variables:
GithubToken: $(GITHUB_TOKEN)

jobs:
- job: UpdateJson
displayName: Update Json
greathongtu marked this conversation as resolved.
Show resolved Hide resolved
steps:
- checkout: self
isra-fel marked this conversation as resolved.
Show resolved Hide resolved
persistCredentials: true
- task: PowerShell@2
displayName: Update json file
inputs:
targetType: inline
script: |
greathongtu marked this conversation as resolved.
Show resolved Hide resolved
$username="v-hongtzhang"
$password='$(AZURE-PASS)'
$pair="{0}:{1}" -f ($username,$password)
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$token = [System.Convert]::ToBase64String($bytes)
isra-fel marked this conversation as resolved.
Show resolved Hide resolved
$headers = @{
Authorization = "Basic {0}" -f ($token)
}
$response = Invoke-RestMethod 'https://dev.azure.com/azure-sdk/internal/_apis/wiki/wikis/internal.wiki/pages?api-version=7.1-preview.1&path=/Engineering%20System/GitHub%20Repos/Issue%20Management/Service%20Team%20Label%20and%20Contact%20List&includeContent=True' -Headers $headers

$rows = ($response.content -split "\n") | Select-Object -Skip 6
$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(), "")
}
}
}
$whole_json = Get-Content -Raw -Path .github/fabricbot.json | ConvertFrom-Json

$whole_json.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()

}
}
($whole_json | ConvertTo-Json -Depth 32) | Out-File -FilePath .github/fabricbot.json
pwsh: true

- task: PowerShell@2
displayName: Commit and Push
inputs:
targetType: inline
script: |
git pull origin main
greathongtu marked this conversation as resolved.
Show resolved Hide resolved
git config --global user.email "azurepowershell@ms.com"
git config --global user.name "azurepowershell"
git config --global credential.helper store
git checkout -b "Will_change_fabricbot"

git add .
git commit -m "pipeline to change fabricbot22.json"

git remote set-url origin "https://$(GITHUB_TOKEN)@github.com/Azure/azure-powershell.git"
git push origin Will_change_fabricbot --force

- pwsh: |
$Title = "Change Fabricbot.json According To Wiki Page"
greathongtu marked this conversation as resolved.
Show resolved Hide resolved
$HeadBranch = "Will_change_fabricbot"
$BaseBranch = "main"
$Description = "Use powershell to sort taskType: scheduledAndTrigger part of fabricbot.json according to table of Service-Team-Label-and-Contact-List in wiki page"
greathongtu marked this conversation as resolved.
Show resolved Hide resolved
./tools/Github/CreatePR.ps1 -Title $Title -HeadBranch $HeadBranch -BaseBranch $BaseBranch -BotAccessToken $(GITHUB_TOKEN) -Description $Description
displayName: Create PR to main branch