@@ -26,28 +26,18 @@ function InitializeRequiredPackages {
26
26
[CmdletBinding ()]
27
27
param ()
28
28
29
- $packagesDirectoryName = " JsonYamlPackages"
30
- $packagesDirectory = Join-Path - Path . - ChildPath $packagesDirectoryName
31
- if (Test-Path - LiteralPath $packagesDirectory ) {
32
- Remove-Item - LiteralPath $packagesDirectory - Recurse - Force
29
+ if (-not (Get-PackageProvider - Name NuGet - ErrorAction SilentlyContinue)) {
30
+ Install-PackageProvider - Name NuGet - Force
33
31
}
34
32
35
- New-Item - Path . - Name $packagesDirectoryName - ItemType Directory - Force
36
-
37
- $requiredPackages = @ (
38
- @ { PackageName = " Newtonsoft.Json" ; PackageVersion = " 13.0.2" ; DllName = " Newtonsoft.Json.dll" },
39
- @ { PackageName = " YamlDotNet" ; PackageVersion = " 13.2.0" ; DllName = " YamlDotNet.dll" }
40
- )
41
-
42
- $requiredPackages | ForEach-Object {
43
- $packageName = $_ [" PackageName" ]
44
- $packageVersion = $_ [" PackageVersion" ]
45
- $packageDll = $_ [" DllName" ]
46
- Install-Package - Name $packageName - RequiredVersion $packageVersion - Source " https://www.nuget.org/api/v2" - Destination $packagesDirectory - SkipDependencies - ExcludeVersion - Force
47
- Add-Type - LiteralPath (Join-Path - Path $packagesDirectory - ChildPath $packageName | Join-Path - ChildPath " lib" | Join-Path - ChildPath " net8.0" | Join-Path - ChildPath $packageDll ) - ErrorAction SilentlyContinue
48
- }
33
+ Install-Package - Name YamlDotNet - RequiredVersion ${env: YamlDotNetVersion} - ProviderName NuGet - Force
34
+ $pkgYaml = Get-Package - Name YamlDotNet | Select-Object - ExpandProperty Source | Split-Path
35
+ $dllYaml = Join-Path - Path $pkgYaml - ChildPath " lib" | Join-Path - ChildPath " netstandard2.0" | Join-Path - ChildPath " YamlDotNet.dll"
36
+ Add-Type - LiteralPath $dllYaml
49
37
}
50
38
39
+ $ErrorActionPreference = " Stop"
40
+
51
41
# get wiki content
52
42
$username = " "
53
43
$password = $AccessToken
@@ -58,89 +48,95 @@ $headers = @{
58
48
Authorization = " Basic {0}" -f ($token )
59
49
}
60
50
61
- $response = Invoke-RestMethod ' https://dev.azure.com/azclitools/internal/_apis/wiki/wikis/internal.wiki/pages?path=/Service%20Contact%20List&includeContent=true' - Headers $headers - ErrorAction Stop
62
- $contactsList = ($response.content -split " \n" ) | Where-Object { $_ -like ' |*' } | Select-Object - Skip 2
63
-
64
- if ($null -ne $contactsList ) {
65
- $idxServiceTeamLabel = 2
66
- $idxPSNotifyGithubHandler = 6
67
- $serviceContacts = [System.Collections.Generic.SortedList [System.String , PSCustomObject ]]::new()
68
-
69
- foreach ($contacts in $contactsList ) {
70
- $items = $contacts -split " \|"
71
- $colServiceTeamLabel = $items [$idxServiceTeamLabel ]
72
- if (! [string ]::IsNullOrWhiteSpace($colServiceTeamLabel )) {
73
- $serviceTeamLabel = $colServiceTeamLabel.Trim ()
74
- $colPSNotifyGithubHandler = $items [$idxPSNotifyGithubHandler ]
75
-
76
- if (! [string ]::IsNullOrWhiteSpace($colPSNotifyGithubHandler )) {
77
- $psNotifyGithubHandler = $colPSNotifyGithubHandler.Trim ()
78
- [array ]$mentionees = $psNotifyGithubHandler.Split (" ," , [StringSplitOptions ]::RemoveEmptyEntries) | ForEach-Object {
79
- $_.Trim ()
80
- }
81
-
82
- $serviceContacts.Add ($serviceTeamLabel , [PSCustomObject ]@ {
83
- if = @ (
84
- [PSCustomObject ]@ {
85
- or = @ (
86
- [PSCustomObject ]@ {
87
- labelAdded = [PSCustomObject ]@ {
88
- label = ' Service Attention'
89
- }
90
- },
91
- [PSCustomObject ]@ {
92
- labelAdded = [PSCustomObject ]@ {
93
- label = $serviceTeamLabel
51
+ try {
52
+ $response = Invoke-RestMethod ${env: ServiceContactsListUrl} - Headers $headers - ErrorAction Stop
53
+ $contactsList = ($response.content -split " \n" ) | Where-Object { $_ -like ' |*' } | Select-Object - Skip 2
54
+
55
+ if ($null -ne $contactsList ) {
56
+ $idxServiceTeamLabel = 2
57
+ $idxPSNotifyGithubHandler = 6
58
+ $serviceContacts = [System.Collections.Generic.SortedList [System.String , PSCustomObject ]]::new()
59
+
60
+ foreach ($contacts in $contactsList ) {
61
+ $items = $contacts -split " \|"
62
+ $colServiceTeamLabel = $items [$idxServiceTeamLabel ]
63
+ if (! [string ]::IsNullOrWhiteSpace($colServiceTeamLabel )) {
64
+ $serviceTeamLabel = $colServiceTeamLabel.Trim ()
65
+ $colPSNotifyGithubHandler = $items [$idxPSNotifyGithubHandler ]
66
+
67
+ if (! [string ]::IsNullOrWhiteSpace($colPSNotifyGithubHandler )) {
68
+ $psNotifyGithubHandler = $colPSNotifyGithubHandler.Trim ()
69
+ [array ]$mentionees = $psNotifyGithubHandler.Split (" ," , [StringSplitOptions ]::RemoveEmptyEntries) | ForEach-Object {
70
+ $_.Trim ()
71
+ }
72
+
73
+ $serviceContacts.Add ($serviceTeamLabel , [PSCustomObject ]@ {
74
+ if = @ (
75
+ [PSCustomObject ]@ {
76
+ or = @ (
77
+ [PSCustomObject ]@ {
78
+ labelAdded = [PSCustomObject ]@ {
79
+ label = ' Service Attention'
80
+ }
81
+ },
82
+ [PSCustomObject ]@ {
83
+ labelAdded = [PSCustomObject ]@ {
84
+ label = $serviceTeamLabel
85
+ }
94
86
}
87
+ )
88
+ },
89
+ [PSCustomObject ]@ {
90
+ hasLabel = [PSCustomObject ]@ {
91
+ label = ' Service Attention'
92
+ }
93
+ },
94
+ [PSCustomObject ]@ {
95
+ hasLabel = [PSCustomObject ]@ {
96
+ label = $serviceTeamLabel
95
97
}
96
- )
97
- },
98
- [PSCustomObject ]@ {
99
- hasLabel = [PSCustomObject ]@ {
100
- label = ' Service Attention'
101
- }
102
- },
103
- [PSCustomObject ]@ {
104
- hasLabel = [PSCustomObject ]@ {
105
- label = $serviceTeamLabel
106
98
}
107
- }
108
- )
109
- then = @ (
110
- [PSCustomObject ]@ {
111
- mentionUsers = [ PSCustomObject ] @ {
112
- mentionees = $ mentionees
113
- replyTemplate = ' Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc ${mentionees}. '
114
- assignMentionees = ' False '
99
+ )
100
+ then = @ (
101
+ [ PSCustomObject ] @ {
102
+ mentionUsers = [PSCustomObject ]@ {
103
+ mentionees = $mentionees
104
+ replyTemplate = ' Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc ${ mentionees}. '
105
+ assignMentionees = ' False '
106
+ }
115
107
}
116
- }
117
- )
118
- })
108
+ )
109
+ } )
110
+ }
119
111
}
120
112
}
121
113
}
122
- }
123
114
124
- # Update yaml file
125
- InitializeRequiredPackages
115
+ # Update yaml file
116
+ InitializeRequiredPackages
126
117
127
- $yamlConfigPath = $PSScriptRoot | Split-Path | Split-Path | Join-Path - ChildPath " .github" | Join-Path - ChildPath " policies" | Join-Path - ChildPath " resourceManagement.yml"
128
- $yamlContent = Get-Content - Path $yamlConfigPath - Raw
129
- $yamlDeserializer = [YamlDotNet.Serialization.DeserializerBuilder ]::new().Build()
130
- $yamlObjectGraph = $yamlDeserializer.Deserialize ($yamlContent )
131
- $jsonSerializer = [YamlDotNet.Serialization.SerializerBuilder ]::new().JsonCompatible().Build()
132
- $jsonObjectGraph = $jsonSerializer.Serialize ($yamlObjectGraph ) | ConvertFrom-Json
118
+ $yamlConfigPath = $PSScriptRoot | Split-Path | Split-Path | Join-Path - ChildPath " .github" | Join-Path - ChildPath " policies" | Join-Path - ChildPath " resourceManagement.yml"
119
+ $yamlContent = Get-Content - Path $yamlConfigPath - Raw
120
+ $yamlDeserializer = [YamlDotNet.Serialization.DeserializerBuilder ]::new().Build()
121
+ $yamlObjectGraph = $yamlDeserializer.Deserialize ($yamlContent )
122
+ $jsonSerializer = [YamlDotNet.Serialization.SerializerBuilder ]::new().JsonCompatible().Build()
123
+ $jsonObjectGraph = $jsonSerializer.Serialize ($yamlObjectGraph ) | ConvertFrom-Json
133
124
134
- $serviceContactsTask = $jsonObjectGraph.configuration.resourceManagementConfiguration.eventResponderTasks | Where-Object { $_.description -eq " Triage issues to the service team" }
135
- if ($null -ne $serviceContactsTask ) {
136
- $serviceContactsTask.then = $serviceContacts.Values
137
- }
125
+ $serviceContactsTask = $jsonObjectGraph.configuration.resourceManagementConfiguration.eventResponderTasks | Where-Object { $_.description -eq " Triage issues to the service team" }
126
+ if ($null -ne $serviceContactsTask ) {
127
+ $serviceContactsTask.then = $serviceContacts.Values
128
+ }
138
129
139
- $updatedJsonContent = $jsonObjectGraph | ConvertTo-Json - Depth 64
140
- $updatedJsonObjectGraph = [Newtonsoft.Json.JsonConvert ]::DeserializeObject[System.Dynamic.ExpandoObject ]($updatedJsonContent )
141
- $yamlSerializer = [YamlDotNet.Serialization.SerializerBuilder ]::new().Build()
142
- $updatedYamlContent = $yamlSerializer.Serialize ($updatedJsonObjectGraph )
143
- $updatedYamlContent | Out-File - FilePath $yamlConfigPath - NoNewline - Force
130
+ $updatedJsonContent = $jsonObjectGraph | ConvertTo-Json - Depth 64
131
+ $updatedJsonObjectGraph = [Newtonsoft.Json.JsonConvert ]::DeserializeObject[System.Dynamic.ExpandoObject ]($updatedJsonContent )
132
+ $yamlSerializer = [YamlDotNet.Serialization.SerializerBuilder ]::new().Build()
133
+ $updatedYamlContent = $yamlSerializer.Serialize ($updatedJsonObjectGraph )
134
+ $updatedYamlContent | Out-File - FilePath $yamlConfigPath - NoNewline - Force
144
135
145
- # Remove trailing space on each line
146
- (Get-Content - Path $yamlConfigPath ) | ForEach-Object { $_.TrimEnd () } | Set-Content - Path $yamlConfigPath
136
+ # Remove trailing space on each line
137
+ (Get-Content - Path $yamlConfigPath ) | ForEach-Object { $_.TrimEnd () } | Set-Content - Path $yamlConfigPath
138
+ }
139
+ catch {
140
+ Write-Error " Error occurred while updating the resourceManagement.yml file. Error Message: $ ( $_.Exception.Message ) "
141
+ throw
142
+ }
0 commit comments