fiftyone.geolocation 4.2.1 → 4.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitmodules +3 -0
- package/README.md +2 -2
- package/ci/README.md +2 -0
- package/ci/build-and-test.yml +34 -0
- package/ci/common-ci/.github/labels.yml +59 -0
- package/ci/common-ci/.github/workflows/sync-labels.yml +49 -0
- package/ci/common-ci/CiTips.md +34 -0
- package/ci/common-ci/GitVersion.yml +18 -0
- package/ci/common-ci/LICENSE +286 -0
- package/ci/common-ci/README.md +365 -0
- package/ci/common-ci/build-and-test.yml +65 -0
- package/ci/common-ci/check-merge-commit-format.yml +50 -0
- package/ci/common-ci/cloud-release-config.json +51 -0
- package/ci/common-ci/create-tag.yml +41 -0
- package/ci/common-ci/deploy.yml +25 -0
- package/ci/common-ci/dotnet/shared-code-signing-steps.yml +20 -0
- package/ci/common-ci/dotnet/shared-extract-and-publish-packages.yml +29 -0
- package/ci/common-ci/go/shared-go-list-stage.yml +64 -0
- package/ci/common-ci/java/readme.md +22 -0
- package/ci/common-ci/java/shared-code-signing-steps.yml +17 -0
- package/ci/common-ci/node/shared-extract-and-publish-packages.yml +26 -0
- package/ci/common-ci/php/readme.md +15 -0
- package/ci/common-ci/release-config-schema.json +52 -0
- package/ci/common-ci/release-config-template.json +310 -0
- package/ci/common-ci/release-config.json +128 -0
- package/ci/common-ci/release-process.drawio +165 -0
- package/ci/common-ci/release-process.png +0 -0
- package/ci/common-ci/scripts/azure/checkSlot.ps1 +28 -0
- package/ci/common-ci/scripts/modules/51DAuthorizationModule/51DAuthorizationModule.Tests.ps1 +1 -0
- package/ci/common-ci/scripts/modules/51DAuthorizationModule/51DAuthorizationModule.psm1 +16 -0
- package/ci/common-ci/scripts/modules/51DBuildModule/51DBuildModule.Tests.ps1 +3 -0
- package/ci/common-ci/scripts/modules/51DBuildModule/51DBuildModule.psm1 +200 -0
- package/ci/common-ci/scripts/modules/51DDeployModule/51DDeployModule.psm1 +66 -0
- package/ci/common-ci/scripts/modules/51DDownloadDataFileModule/51DDownloadDataFileModule.psm1 +58 -0
- package/ci/common-ci/scripts/modules/51DEnvironmentModule/51DEnvironmentModule.Tests.ps1 +25 -0
- package/ci/common-ci/scripts/modules/51DEnvironmentModule/51DEnvironmentModule.psm1 +22 -0
- package/ci/common-ci/scripts/modules/51DErrorHandleModule/51DErrorHandleModule.Tests.ps1 +1 -0
- package/ci/common-ci/scripts/modules/51DErrorHandleModule/51DErrorHandleModule.psm1 +41 -0
- package/ci/common-ci/scripts/modules/51DGitModule/51DGitModule.Tests.ps1 +5 -0
- package/ci/common-ci/scripts/modules/51DGitModule/51DGitModule.psm1 +698 -0
- package/ci/common-ci/scripts/modules/51DPackageModule/51DPackageModule.Tests.ps1 +842 -0
- package/ci/common-ci/scripts/modules/51DPackageModule/51DPackageModule.psm1 +926 -0
- package/ci/common-ci/scripts/modules/51DPipelineModule/51DPipelineModule.Tests.ps1 +1 -0
- package/ci/common-ci/scripts/modules/51DPipelineModule/51DPipelineModule.psm1 +87 -0
- package/ci/common-ci/scripts/modules/51DPullRequestModule/51DPullRequestModule.Tests.ps1 +194 -0
- package/ci/common-ci/scripts/modules/51DPullRequestModule/51DPullRequestModule.psm1 +653 -0
- package/ci/common-ci/scripts/modules/51DReleaseModule/51DReleaseModule.Tests.ps1 +277 -0
- package/ci/common-ci/scripts/modules/51DReleaseModule/51DReleaseModule.psm1 +554 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/51DReleaseTestEnvModule.Tests.ps1 +1141 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/51DReleaseTestEnvModule.psd1 +0 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/51DReleaseTestEnvModule.psm1 +1465 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/ConfigurationVerifier.Tests.ps1 +318 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/ConfigurationVerifier.psm1 +344 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/ReleaseVerifier.Tests.ps1 +1186 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/ReleaseVerifier.psm1 +900 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/SharedVariables.psm1 +139 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/c-test-env-config.json +268 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/dotnet-deploy-test-env-config.json +700 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/dotnet-test-env-config.json +533 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/go-deploy-test-env-config.json +290 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/go-test-env-config.json +260 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/java-deploy-test-env-config.json +511 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/java-test-env-config.json +388 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/node-deploy-test-env-config.json +419 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/node-test-env-config.json +329 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/php-test-env-config.json +540 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/python-deploy-test-env-config.json +411 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/python-test-env-config.json +321 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/test-env-config.json +457 -0
- package/ci/common-ci/scripts/modules/51DRestModule/51DRestModule.psm1 +38 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DApplicationInsightsModule/51DApplicationInsightsModule.psm1 +104 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DChecksModule/51DChecksModule.psm1 +68 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DCloudModule/51DCloudModule.psm1 +155 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DConnectAzureModule/51DConnectAzureModule.psm1 +45 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DSSLBindingsModule/51DSSLBIndingsModule.psm1 +100 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DStagingSlotModule/51DStagingSlotModule.psm1 +50 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DStorageAccountModule/51DStorageAccountModule.psm1 +248 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DTrafficManagerModule/51DTrafficManagerModule.psm1 +58 -0
- package/ci/common-ci/shared-auto-complete-pr-stage.yml +61 -0
- package/ci/common-ci/shared-create-tag-job.yml +23 -0
- package/ci/common-ci/shared-docker-build-steps.yml +34 -0
- package/ci/common-ci/shared-docker-push-steps.yml +32 -0
- package/ci/common-ci/shared-docker-test-http-steps.yml +69 -0
- package/ci/common-ci/shared-git-tag-job.yml +38 -0
- package/ci/common-ci/shared-git-version-job.yml +71 -0
- package/ci/common-ci/shared-publish-github-stage.yml +107 -0
- package/ci/common-ci/shared-submodule-trigger-stage.yml +110 -0
- package/ci/common-ci/shared-variables.yml +3 -0
- package/ci/common-ci/trigger-release-apis.yml +39 -0
- package/ci/create-packages.yml +109 -0
- package/ci/deploy-external.yml +55 -0
- package/ci/deploy-internal.yml +50 -0
- package/ci/shared-build-and-test-platforms.yml +26 -0
- package/ci/shared-build-and-test-stage.yml +128 -0
- package/ci/shared-variables.yml +7 -0
- package/ci/submodule-trigger.yml +12 -0
- package/docs/Doxyfile +3 -3
- package/docs/DoxygenLayout.xml +1 -1
- package/examples/examples.test.js +3 -3
- package/geoLocationPipelineBuilder.js +16 -13
- package/package.json +14 -6
- package/setup.js +1 -0
- package/tests/geoLocationCloud.test.js +192 -0
- package/tsconfig.json +21 -0
- package/types/geoLocationCloud.d.ts +7 -0
- package/types/geoLocationPipelineBuilder.d.ts +17 -0
- package/types/index.d.ts +2 -0
- package/build-and-test.yml +0 -112
- package/publish-packages.yml +0 -87
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
<#
|
|
2
|
+
===================== Pull Request =====================
|
|
3
|
+
.Description
|
|
4
|
+
This module contains functions that perform actions on
|
|
5
|
+
Azure Devops pull requests.
|
|
6
|
+
For more information, please read description of
|
|
7
|
+
each function.
|
|
8
|
+
#>
|
|
9
|
+
|
|
10
|
+
Using module 51DAuthorizationModule
|
|
11
|
+
Using module 51DEnvironmentModule
|
|
12
|
+
|
|
13
|
+
# Global variables to be updated when one of the main APIs is called.
|
|
14
|
+
$script:releaseConfig = $null
|
|
15
|
+
$script:repositories = $null
|
|
16
|
+
|
|
17
|
+
<#
|
|
18
|
+
.Description
|
|
19
|
+
Get the existing pull request to 'main' branch.
|
|
20
|
+
|
|
21
|
+
.Parameter RepositoryName
|
|
22
|
+
Name of the repository
|
|
23
|
+
|
|
24
|
+
.Parameter ReleaseBranch
|
|
25
|
+
Ref of the release branch
|
|
26
|
+
|
|
27
|
+
.Parameter TeamProjectName
|
|
28
|
+
Name ofthe repository team project
|
|
29
|
+
|
|
30
|
+
.Outputs
|
|
31
|
+
A pull request object based on Azure Devops definition.
|
|
32
|
+
$null if nothing is found.
|
|
33
|
+
#>
|
|
34
|
+
function Get-PullRequestToMain {
|
|
35
|
+
param (
|
|
36
|
+
[Parameter(Mandatory)]
|
|
37
|
+
[string]$RepositoryName,
|
|
38
|
+
[Parameter(Mandatory)]
|
|
39
|
+
[string]$ReleaseBranch,
|
|
40
|
+
[Parameter(Mandatory)]
|
|
41
|
+
[string]$TeamProjectName
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
$url = "$([EnvironmentHandler]::GetEnvironmentVariable($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI))$($TeamProjectName)/_apis/git/repositories/$RepositoryName/pullrequests?api-version=6.0"
|
|
45
|
+
|
|
46
|
+
$response = Invoke-WebRequest `
|
|
47
|
+
-URI $url `
|
|
48
|
+
-Headers @{
|
|
49
|
+
Authorization = "$([Authorization]::AuthorizationString)"
|
|
50
|
+
} `
|
|
51
|
+
-Method GET
|
|
52
|
+
|
|
53
|
+
if ($(Test-RestResponse `
|
|
54
|
+
-Response $response `
|
|
55
|
+
-ErrorMessage "Failed to get the list of existing pull requests for $RepositoryName.")){
|
|
56
|
+
$content = $response.content | Out-String | ConvertFrom-Json
|
|
57
|
+
for ($i = 0; $i -lt $content.value.count; $i++) {
|
|
58
|
+
if ($content.value[$i].sourceRefName -match "$ReleaseBranch$" `
|
|
59
|
+
-and $content.value[$i].targetRefName -match "refs/heads/(master|main)" `
|
|
60
|
+
-and $content.value[$i].status -eq "active") {
|
|
61
|
+
Write-Host "# Matching Pull Request: " $content.value[$i]
|
|
62
|
+
return $content.value[$i]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
Write-Host "# ERROR: Rest API call fails."
|
|
67
|
+
}
|
|
68
|
+
return $null
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
<#
|
|
72
|
+
.Description
|
|
73
|
+
Add a comment to a pull request
|
|
74
|
+
|
|
75
|
+
.Parameter TeamRepositoryName
|
|
76
|
+
Name of a Team Project
|
|
77
|
+
|
|
78
|
+
.Parameter RepositoryName
|
|
79
|
+
Name of a repository
|
|
80
|
+
|
|
81
|
+
.Parameter PullRequestId
|
|
82
|
+
Id of a pull request
|
|
83
|
+
|
|
84
|
+
.Parameter Comment
|
|
85
|
+
Content of a comment
|
|
86
|
+
|
|
87
|
+
.Parameter AuthorizationHeader
|
|
88
|
+
A authorization header that contains the Access Token to the Azure Devops
|
|
89
|
+
|
|
90
|
+
.Outputs
|
|
91
|
+
true or false
|
|
92
|
+
#>
|
|
93
|
+
function Add-PullRequestComment {
|
|
94
|
+
param (
|
|
95
|
+
[Parameter(Mandatory)]
|
|
96
|
+
[string]$TeamProjectName,
|
|
97
|
+
[Parameter(Mandatory)]
|
|
98
|
+
[string]$RepositoryName,
|
|
99
|
+
[Parameter(Mandatory)]
|
|
100
|
+
[int32]$PullRequestId,
|
|
101
|
+
[Parameter(Mandatory)]
|
|
102
|
+
[string]$Comment,
|
|
103
|
+
[string]$AuthorizationHeader
|
|
104
|
+
)
|
|
105
|
+
# Default Authorization Header
|
|
106
|
+
if ([string]::IsNullOrEmpty($AuthorizationHeader)) {
|
|
107
|
+
$AuthorizationHeader = "$([Authorization]::AuthorizationString)"
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
$url = "$([EnvironmentHandler]::GetEnvironmentVariable($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI))$($TeamProjectName)/_apis/git/repositories/$RepositoryName/pullrequests/$PullRequestId/threads?api-version=6.0"
|
|
111
|
+
$jsonBody = @"
|
|
112
|
+
{
|
|
113
|
+
"status": "active",
|
|
114
|
+
"comments": [
|
|
115
|
+
{
|
|
116
|
+
"commentType": "text",
|
|
117
|
+
"content": "$Comment"
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
"@
|
|
122
|
+
|
|
123
|
+
$response = Invoke-WebRequest `
|
|
124
|
+
-URI $url `
|
|
125
|
+
-Headers @{
|
|
126
|
+
Authorization = "$AuthorizationHeader"
|
|
127
|
+
} `
|
|
128
|
+
-Method POST `
|
|
129
|
+
-ContentType "application/json" `
|
|
130
|
+
-Body $jsonBody
|
|
131
|
+
|
|
132
|
+
return $(Test-RestResponse `
|
|
133
|
+
-Response $response `
|
|
134
|
+
-ErrorMessage "Failed to add a comment to pull request $PullRequestId.")
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
<#
|
|
138
|
+
.Description
|
|
139
|
+
Create a pull request.
|
|
140
|
+
|
|
141
|
+
.Parameter TeamProjectName
|
|
142
|
+
Name of a Team project
|
|
143
|
+
|
|
144
|
+
.Parameter RepositoryName
|
|
145
|
+
Name of a repository
|
|
146
|
+
|
|
147
|
+
.Parameter SourceBranchRef
|
|
148
|
+
Full reference of the source branch. (i.e. prefixed with 'refs/heads')
|
|
149
|
+
|
|
150
|
+
.Parameter TargetBranchRef
|
|
151
|
+
Full reference of the target branch. (i.e. prefixed with 'refs/heads')
|
|
152
|
+
|
|
153
|
+
.Parameter AuthorizationHeader
|
|
154
|
+
A authorization header that contains the Access Token to the Azure Devops
|
|
155
|
+
|
|
156
|
+
.Outputs
|
|
157
|
+
response content or $null
|
|
158
|
+
#>
|
|
159
|
+
function New-PullRequest {
|
|
160
|
+
param (
|
|
161
|
+
[Parameter(Mandatory)]
|
|
162
|
+
[string]$TeamProjectName,
|
|
163
|
+
[Parameter(Mandatory)]
|
|
164
|
+
[string]$RepositoryName,
|
|
165
|
+
[Parameter(Mandatory)]
|
|
166
|
+
[string]$SourceBranchRef,
|
|
167
|
+
[Parameter(Mandatory)]
|
|
168
|
+
[string]$TargetBranchRef,
|
|
169
|
+
[string]$AuthorizationHeader
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
# Default Authorization Header
|
|
173
|
+
if ([string]::IsNullOrEmpty($AuthorizationHeader)) {
|
|
174
|
+
$AuthorizationHeader = "$([Authorization]::AuthorizationString)"
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
$url = "$([EnvironmentHandler]::GetEnvironmentVariable($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI))$($TeamProjectName)/_apis/git/repositories/$RepositoryName/pullrequests?api-version=6.0"
|
|
178
|
+
# Extract source and target branch names. This is to match the branch name to be extracted later.
|
|
179
|
+
$rc = $SourceBranchRef -match "refs/heads/(?<srcbranch>.*)"
|
|
180
|
+
$srcBranch = $Matches['srcbranch']
|
|
181
|
+
$rc = $TargetBranchRef -match "refs/heads/(?<tgtbranch>.*)"
|
|
182
|
+
$tgtBranch = $Matches['tgtbranch']
|
|
183
|
+
$prTitle = "Merge branch '$srcBranch' into '$tgtBranch'"
|
|
184
|
+
$jsonBody = @"
|
|
185
|
+
{
|
|
186
|
+
"title" : "$prTitle",
|
|
187
|
+
"sourceRefName" : "$SourceBranchRef",
|
|
188
|
+
"TargetRefName" : "$TargetBranchRef"
|
|
189
|
+
}
|
|
190
|
+
"@
|
|
191
|
+
|
|
192
|
+
$response = Invoke-WebRequest `
|
|
193
|
+
-URI $url `
|
|
194
|
+
-Headers @{
|
|
195
|
+
Authorization = "$AuthorizationHeader"
|
|
196
|
+
} `
|
|
197
|
+
-Method POST `
|
|
198
|
+
-ContentType "application/json" `
|
|
199
|
+
-Body $jsonBody
|
|
200
|
+
|
|
201
|
+
if (!$(Test-RestResponse `
|
|
202
|
+
-Response $response `
|
|
203
|
+
-ErrorMessage "Failed to create a pull request.")) {
|
|
204
|
+
return $null
|
|
205
|
+
}
|
|
206
|
+
return $($response.content | Out-String | ConvertFrom-Json)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
<#
|
|
210
|
+
.Description
|
|
211
|
+
Create a pull to 'main' branch.
|
|
212
|
+
|
|
213
|
+
.Parameter RepositoryName
|
|
214
|
+
Name of a repository
|
|
215
|
+
|
|
216
|
+
.Parameter SourceBranchRef
|
|
217
|
+
Full reference of the source branch. (i.e. prefixed with 'refs/heads')
|
|
218
|
+
|
|
219
|
+
.Parameter TeamProjectName
|
|
220
|
+
Name ofthe repository team project
|
|
221
|
+
|
|
222
|
+
.Outputs true or false
|
|
223
|
+
#>
|
|
224
|
+
function New-PullRequestToMain {
|
|
225
|
+
param (
|
|
226
|
+
[Parameter(Mandatory)]
|
|
227
|
+
[string]$RepositoryName,
|
|
228
|
+
[Parameter(Mandatory)]
|
|
229
|
+
[string]$SourceBranchRef,
|
|
230
|
+
[Parameter(Mandatory)]
|
|
231
|
+
[string]$TeamProjectName
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
$mainBranch = $(Get-MainBranchRef `
|
|
235
|
+
-RepositoryName $RepositoryName `
|
|
236
|
+
-TeamProjectName $TeamProjectName)
|
|
237
|
+
if($(New-PullRequest `
|
|
238
|
+
-TeamProjectName $TeamProjectName `
|
|
239
|
+
-RepositoryName $RepositoryName `
|
|
240
|
+
-SourceBranchRef $SourceBranchRef `
|
|
241
|
+
-TargetBranchRef $mainBranch `
|
|
242
|
+
-AuthorizationHeader "$([Authorization]::AuthorizationString)") -eq $null) {
|
|
243
|
+
Write-Host "# ERROR: Failed to create pull request to main"
|
|
244
|
+
return $false
|
|
245
|
+
}
|
|
246
|
+
return $true
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
<#
|
|
250
|
+
.Description
|
|
251
|
+
Decide an action on a release branch. Either request a test pipeline
|
|
252
|
+
if a pull request eixsts, or create a new one.
|
|
253
|
+
|
|
254
|
+
.Parameter RepositoryName
|
|
255
|
+
Name of the repository
|
|
256
|
+
|
|
257
|
+
.Parameter ReleaseBranch
|
|
258
|
+
Full reference of the release branch.
|
|
259
|
+
|
|
260
|
+
.Parameter TeamProjectName
|
|
261
|
+
Name ofthe repository team project
|
|
262
|
+
|
|
263
|
+
.Outputs
|
|
264
|
+
True or False
|
|
265
|
+
#>
|
|
266
|
+
function Start-ProcessPullRequest {
|
|
267
|
+
param (
|
|
268
|
+
[Parameter(Mandatory)]
|
|
269
|
+
[string]$RepositoryName,
|
|
270
|
+
[Parameter(Mandatory)]
|
|
271
|
+
[string]$ReleaseBranch,
|
|
272
|
+
[Parameter(Mandatory)]
|
|
273
|
+
[string]$TeamProjectName
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
# Check if a Pull Request already exist
|
|
277
|
+
$pullRequest = Get-PullRequestToMain `
|
|
278
|
+
-RepositoryName $RepositoryName `
|
|
279
|
+
-ReleaseBranch $ReleaseBranch `
|
|
280
|
+
-TeamProjectName $TeamProjectName
|
|
281
|
+
|
|
282
|
+
if ($pullRequest -ne $null) {
|
|
283
|
+
Write-Host "# Pull request exists. Requeue the test pipeline."
|
|
284
|
+
#Rerun the build-and-test pipeline for this pull request.
|
|
285
|
+
return $(Restart-TestBuild `
|
|
286
|
+
-RepositoryName $RepositoryName `
|
|
287
|
+
-PullRequestId $pullRequest.pullRequestId `
|
|
288
|
+
-TeamProjectName $TeamProjectName)
|
|
289
|
+
} else {
|
|
290
|
+
Write-Host "# Pull request does not exist. Create one."
|
|
291
|
+
#Create a pull request which should trigger the build-and-test pipeline.
|
|
292
|
+
return $(New-PullRequestToMain `
|
|
293
|
+
-RepositoryName $RepositoryName `
|
|
294
|
+
-SourceBranchRef $ReleaseBranch `
|
|
295
|
+
-TeamProjectName $TeamProjectName)
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
<#
|
|
300
|
+
.Description
|
|
301
|
+
Check if all required votes for a pull requests have been approved.
|
|
302
|
+
|
|
303
|
+
.Parameter RepositoryName
|
|
304
|
+
Name of the repository that the PR belongs to
|
|
305
|
+
|
|
306
|
+
.Parameter PullRequestId
|
|
307
|
+
Id number of a pull request.
|
|
308
|
+
|
|
309
|
+
.Parameter TeamProjectName
|
|
310
|
+
Name ofthe repository team project
|
|
311
|
+
|
|
312
|
+
.Outputs true or false
|
|
313
|
+
#>
|
|
314
|
+
function Test-PullRequestVotes {
|
|
315
|
+
param (
|
|
316
|
+
[Parameter(Mandatory)]
|
|
317
|
+
[string]$RepositoryName,
|
|
318
|
+
[Parameter(Mandatory)]
|
|
319
|
+
[int32]$PullRequestId,
|
|
320
|
+
[Parameter(Mandatory)]
|
|
321
|
+
[string]$TeamProjectName
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
$url = "$([EnvironmentHandler]::GetEnvironmentVariable($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI))$($TeamProjectName)/_apis/git/repositories/$RepositoryName/pullrequests/$($PullRequestId)?api-version=6.0"
|
|
325
|
+
$response = Invoke-WebRequest `
|
|
326
|
+
-URI $url `
|
|
327
|
+
-Headers @{
|
|
328
|
+
Authorization = "$([Authorization]::AuthorizationString)"
|
|
329
|
+
} `
|
|
330
|
+
-Method GET
|
|
331
|
+
|
|
332
|
+
if ($(Test-RestResponse -Response $response -ErrorMessage "Failed to get pull request details.")) {
|
|
333
|
+
$content = $response.content | Out-String | ConvertFrom-Json
|
|
334
|
+
foreach ($reviewer in $content.reviewers) {
|
|
335
|
+
if ($reviewer.isRequired `
|
|
336
|
+
-and $reviewer.vote -ne 10 `
|
|
337
|
+
-and $reviewer.vote -ne 5) {
|
|
338
|
+
Write-Host "# Required reviewer has not accepted the PR."
|
|
339
|
+
return $false
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return $true
|
|
343
|
+
}
|
|
344
|
+
return $false
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
<#
|
|
348
|
+
.Description
|
|
349
|
+
Check if all comments have been resolved for a pull request.
|
|
350
|
+
|
|
351
|
+
.Parameter RepositoryName
|
|
352
|
+
Name of a repository that a pull request belongs to.
|
|
353
|
+
|
|
354
|
+
.Parameter PullRequestId
|
|
355
|
+
Id number of a pull request.
|
|
356
|
+
|
|
357
|
+
.Parameter TeamProjectName
|
|
358
|
+
Name ofthe repository team project
|
|
359
|
+
|
|
360
|
+
.Outputs true or false.
|
|
361
|
+
#>
|
|
362
|
+
function Test-PullRequestComments {
|
|
363
|
+
param (
|
|
364
|
+
[Parameter(Mandatory)]
|
|
365
|
+
[string]$RepositoryName,
|
|
366
|
+
[Parameter(Mandatory)]
|
|
367
|
+
[int32]$PullRequestId,
|
|
368
|
+
[Parameter(Mandatory)]
|
|
369
|
+
[string]$TeamProjectName
|
|
370
|
+
)
|
|
371
|
+
|
|
372
|
+
$url = "$([EnvironmentHandler]::GetEnvironmentVariable($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI))$($TeamProjectName)/_apis/git/repositories/$RepositoryName/pullrequests/$($PullRequestId)/threads?api-version=6.0"
|
|
373
|
+
$response = Invoke-WebRequest `
|
|
374
|
+
-URI $url `
|
|
375
|
+
-Headers @{
|
|
376
|
+
Authorization = "$([Authorization]::AuthorizationString)"
|
|
377
|
+
} `
|
|
378
|
+
-Method GET
|
|
379
|
+
|
|
380
|
+
if ($(Test-RestResponse -Response $response -ErrorMessage "Failed to get pull request threads.")) {
|
|
381
|
+
$content = $response.content | Out-String | ConvertFrom-Json
|
|
382
|
+
foreach ($thread in $content.value) {
|
|
383
|
+
if ($thread.status -eq "active") {
|
|
384
|
+
Write-Host "# Comment has not been resolved."
|
|
385
|
+
return $false
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return $true
|
|
389
|
+
}
|
|
390
|
+
return $false
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
<#
|
|
394
|
+
.Description
|
|
395
|
+
Complete a pull request.
|
|
396
|
+
|
|
397
|
+
.Parameter RepositoryName
|
|
398
|
+
Name of a repository that the pull request belongs to.
|
|
399
|
+
|
|
400
|
+
.Parameter PullRequestId
|
|
401
|
+
Id number of a pull request.
|
|
402
|
+
|
|
403
|
+
.Parameter ApprovalRequired.
|
|
404
|
+
Whether approval is required to complete.
|
|
405
|
+
|
|
406
|
+
.Parameter TeamProjectName
|
|
407
|
+
Name ofthe repository team project
|
|
408
|
+
|
|
409
|
+
.Outputs true or false.
|
|
410
|
+
#>
|
|
411
|
+
function Complete-PullRequest {
|
|
412
|
+
param (
|
|
413
|
+
[Parameter(Mandatory)]
|
|
414
|
+
[string]$RepositoryName,
|
|
415
|
+
[Parameter(Mandatory)]
|
|
416
|
+
[int32]$PullRequestId,
|
|
417
|
+
[Parameter(Mandatory)]
|
|
418
|
+
[bool]$ApprovalRequired,
|
|
419
|
+
[Parameter(Mandatory)]
|
|
420
|
+
[string]$TeamProjectName
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
$canComplete = $false
|
|
424
|
+
if (!$ApprovalRequired) {
|
|
425
|
+
Write-Host "# No approval is required. Bypass any policies."
|
|
426
|
+
$canComplete = $true
|
|
427
|
+
} elseif (($(Test-PullRequestVotes `
|
|
428
|
+
-RepositoryName $RepositoryName `
|
|
429
|
+
-PullRequestId $PullRequestId `
|
|
430
|
+
-TeamProjectName $TeamProjectName) `
|
|
431
|
+
-and $(Test-PullRequestComments `
|
|
432
|
+
-RepositoryName $RepositoryName `
|
|
433
|
+
-PullRequestId $PullRequestId `
|
|
434
|
+
-TeamProjectName $TeamProjectName))) {
|
|
435
|
+
Write-Host "# Pull request has been approved and no comments left unresolved."
|
|
436
|
+
$canComplete = $true
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if ($canComplete) {
|
|
440
|
+
# Get Last Merge Source Commit
|
|
441
|
+
$url = "$([EnvironmentHandler]::GetEnvironmentVariable($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI))$($TeamProjectName)/_apis/git/repositories/$RepositoryName/pullrequests/$($PullRequestId)?api-version=6.0"
|
|
442
|
+
Write-Host "$url"
|
|
443
|
+
$response = Invoke-WebRequest `
|
|
444
|
+
-URI $url `
|
|
445
|
+
-Headers @{
|
|
446
|
+
Authorization = "$([Authorization]::AuthorizationString)"
|
|
447
|
+
} `
|
|
448
|
+
-Method GET
|
|
449
|
+
|
|
450
|
+
if ($(Test-RestResponse -Response $response -ErrorMessage "Failed to get pull request info.")) {
|
|
451
|
+
$content = $response.content | Out-String | ConvertFrom-Json
|
|
452
|
+
$lastMergeSourceCommit = $content.lastMergeSourceCommit.commitId
|
|
453
|
+
|
|
454
|
+
$url = "$([EnvironmentHandler]::GetEnvironmentVariable($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI))$($TeamProjectName)/_apis/git/repositories/$RepositoryName/pullrequests/$($PullRequestId)?api-version=6.0"
|
|
455
|
+
$jsonBody = @"
|
|
456
|
+
{
|
|
457
|
+
"lastMergeSourceCommit" : {
|
|
458
|
+
"commitId" : "$lastMergeSourceCommit"
|
|
459
|
+
},
|
|
460
|
+
"status" : "completed",
|
|
461
|
+
"completionOptions" : {
|
|
462
|
+
"bypassPolicy" : true,
|
|
463
|
+
"bypassReason" : "Auto Release Process"
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
"@
|
|
467
|
+
|
|
468
|
+
$response = Invoke-WebRequest `
|
|
469
|
+
-URI $url `
|
|
470
|
+
-Headers @{
|
|
471
|
+
Authorization = "$([Authorization]::AuthorizationString)"
|
|
472
|
+
} `
|
|
473
|
+
-Method PATCH `
|
|
474
|
+
-ContentType "application/json" `
|
|
475
|
+
-Body $jsonBody
|
|
476
|
+
|
|
477
|
+
return $(Test-RestResponse -Response $response -ErrorMessage "Failed to complete pull request.")
|
|
478
|
+
} else {
|
|
479
|
+
return $false
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
} else {
|
|
483
|
+
Write-Host "# Can't complete pull request as comments has not been resolved or reviewer has not approved."
|
|
484
|
+
return $false
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
<#
|
|
489
|
+
.Description
|
|
490
|
+
Check if a pull request is from a release/hotfix branch to main.
|
|
491
|
+
|
|
492
|
+
.Parameter PullRequestId
|
|
493
|
+
The id number of a pull request
|
|
494
|
+
|
|
495
|
+
.Parameter TeamProjectName
|
|
496
|
+
Name ofthe repository team project
|
|
497
|
+
|
|
498
|
+
.Outputs
|
|
499
|
+
true or false
|
|
500
|
+
#>
|
|
501
|
+
function Test-IsReleasePullRequest {
|
|
502
|
+
param (
|
|
503
|
+
[Parameter(Mandatory)]
|
|
504
|
+
[int32]$PullRequestId,
|
|
505
|
+
[Parameter(Mandatory)]
|
|
506
|
+
[string]$TeamProjectName
|
|
507
|
+
)
|
|
508
|
+
|
|
509
|
+
$prSourceBranch = [EnvironmentHandler]::GetEnvironmentVariable($Env:SYSTEM_PULLREQUEST_SOURCEBRANCH)
|
|
510
|
+
$prTargetBranch = [EnvironmentHandler]::GetEnvironmentVariable($Env:SYSTEM_PULLREQUEST_TARGETBRANCH)
|
|
511
|
+
$repoName = [EnvironmentHandler]::GetEnvironmentVariable($Env:BUILD_REPOSITORY_NAME) # This should always be available.
|
|
512
|
+
# If the source or target branch is not available from environment variables
|
|
513
|
+
# Try the query it using the REST api.
|
|
514
|
+
if ($prSourceBranch -eq $null `
|
|
515
|
+
-or $prTargetBranch -eq $null) {
|
|
516
|
+
$url = "$([EnvironmentHandler]::GetEnvironmentVariable($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI))$($TeamProjectName)/_apis/git/repositories/$repoName/pullrequests/$($PullRequestId)?api-version=6.0"
|
|
517
|
+
$response = Invoke-WebRequest `
|
|
518
|
+
-URI $url `
|
|
519
|
+
-Headers @{
|
|
520
|
+
Authorization = "$([Authorization]::AuthorizationString)"
|
|
521
|
+
} `
|
|
522
|
+
-Method GET
|
|
523
|
+
|
|
524
|
+
if (Test-RestResponse `
|
|
525
|
+
-Response $response `
|
|
526
|
+
-ErrorMessage "Failed to query pull request details.") {
|
|
527
|
+
$content = $response.content | Out-String | ConvertFrom-Json
|
|
528
|
+
$prSourceBranch = $content.sourceRefName
|
|
529
|
+
$prTargetBranch = $content.targetRefName
|
|
530
|
+
} else {
|
|
531
|
+
Write-Host "# ERROR: Can obtain source and target branch of the pull request $PullRequestId."
|
|
532
|
+
return $false
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if ($prSourceBranch -match "refs/heads/(release|hotfix)/v?(?<version>\d+\.\d+\.\d+)") {
|
|
537
|
+
Write-Host "# Pull request is from a release/hotfix branch."
|
|
538
|
+
$prVersion = $Matches['version']
|
|
539
|
+
} else {
|
|
540
|
+
Write-Host "# Pull request is not from a release/hotfix branch."
|
|
541
|
+
return $false
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
if (!$($prTargetBranch -match "refs/heads/(main|master)")) {
|
|
545
|
+
Write-Host "# Pull request is not to the 'main' branch."
|
|
546
|
+
return $false
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
# Check if the pull request is from a release target versions.
|
|
550
|
+
# Get the module name
|
|
551
|
+
$targetVersion = $script:repositories."$repoName".version
|
|
552
|
+
if ($prVersion -eq $targetVersion) {
|
|
553
|
+
Write-Host "# Pull request matches the target release version. Proceed to complete."
|
|
554
|
+
} else {
|
|
555
|
+
Write-Host "# Pull request does not match the target release version. `
|
|
556
|
+
The pull request version is $prVersion, while the target version is $targetVersion. `
|
|
557
|
+
Do not proceed."
|
|
558
|
+
return $false
|
|
559
|
+
}
|
|
560
|
+
return $true
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
<#
|
|
564
|
+
.Description
|
|
565
|
+
Initialise the global variables
|
|
566
|
+
|
|
567
|
+
.Parameter Configuration
|
|
568
|
+
A configuration object
|
|
569
|
+
#>
|
|
570
|
+
function Initialize-GlobalVariables {
|
|
571
|
+
param (
|
|
572
|
+
[object]$Configuration
|
|
573
|
+
)
|
|
574
|
+
|
|
575
|
+
# Obtain the config file content. Initialise the global variables
|
|
576
|
+
$script:releaseConfig = $Configuration
|
|
577
|
+
$script:repositories = $script:releaseConfig.repositories
|
|
578
|
+
Write-Host "# Init config: " + $script:releaseConfig
|
|
579
|
+
Write-Host "# Init repositories: " + $script:repositories
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
<#
|
|
583
|
+
.Description
|
|
584
|
+
If the script is called in a build running on a pullrequest branch, try
|
|
585
|
+
to complete the corresponding pull request.
|
|
586
|
+
|
|
587
|
+
.Parameter ConfigFile
|
|
588
|
+
Path to the configration file
|
|
589
|
+
|
|
590
|
+
.Outputs
|
|
591
|
+
true or false
|
|
592
|
+
NOTE: The only time when this should return false is when the build is
|
|
593
|
+
triggered by a pull request and it failed to complete the pull request.
|
|
594
|
+
#>
|
|
595
|
+
function Complete-CorrespondingPullRequest {
|
|
596
|
+
param (
|
|
597
|
+
[string]$ConfigFile
|
|
598
|
+
)
|
|
599
|
+
|
|
600
|
+
# Initialise global variables
|
|
601
|
+
$configuration = Get-Content $ConfigFile | Out-String | ConvertFrom-Json
|
|
602
|
+
Initialize-GlobalVariables -Configuration $configuration
|
|
603
|
+
|
|
604
|
+
# Get pull request
|
|
605
|
+
Write-Host "Build.SourceBranch: " [EnvironmentHandler]::GetEnvironmentVariable($Env:BUILD_SOURCEBRANCH)
|
|
606
|
+
Write-Host "System.PullRequest.SourceBranch: " [EnvironmentHandler]::GetEnvironmentVariable($Env:SYSTEM_PULLREQUEST_SOURCEBRANCH)
|
|
607
|
+
Write-Host "System.PullRequest.TargetBranch: " [EnvironmentHandler]::GetEnvironmentVariable($Env:SYSTEM_PULLREQUEST_TARGETBRANCH)
|
|
608
|
+
Write-Host "Build.Repository.Name: " [EnvironmentHandler]::GetEnvironmentVariable($Env:BUILD_REPOSITORY_NAME)
|
|
609
|
+
$sourceBranch = [EnvironmentHandler]::GetEnvironmentVariable($Env:BUILD_SOURCEBRANCH)
|
|
610
|
+
if ($sourceBranch -match "refs/pull/(?<content>\d+)/merge") {
|
|
611
|
+
Write-Host "# Triggered by a pull request."
|
|
612
|
+
$pullRequestId = $Matches['content']
|
|
613
|
+
if ($(Test-IsReleasePullRequest `
|
|
614
|
+
-PullRequestId $pullRequestId `
|
|
615
|
+
-TeamProjectName "$([EnvironmentHandler]::GetEnvironmentVariable($Env:SYSTEM_TEAMPROJECTID))")) {
|
|
616
|
+
if ($(Update-SubmoduleReferences -Configuration $configuration)) {
|
|
617
|
+
# Check if any changes are required. If there are, submodules are not up to date.
|
|
618
|
+
if ($(git diff --cached --name-only).count -eq 0 ) {
|
|
619
|
+
Write-Host "# All submodules are up to date. Complete the corresponding pull request now."
|
|
620
|
+
# Complete the pull request
|
|
621
|
+
if (!$(Complete-PullRequest `
|
|
622
|
+
-RepositoryName "$([EnvironmentHandler]::GetEnvironmentVariable($Env:BUILD_REPOSITORY_NAME))" `
|
|
623
|
+
-PullRequestId $pullRequestId `
|
|
624
|
+
-ApprovalRequired $script:releaseConfig.approvalRequired `
|
|
625
|
+
-TeamProjectName "$([EnvironmentHandler]::GetEnvironmentVariable($Env:SYSTEM_TEAMPROJECTID))")) {
|
|
626
|
+
Write-Host "# ERROR: Cannot complete the pull request $pullRequestId."
|
|
627
|
+
return $false
|
|
628
|
+
}
|
|
629
|
+
} else {
|
|
630
|
+
Write-Host "# ERROR: Not all submodules are up to date. Don't complete the pull request."
|
|
631
|
+
return $false
|
|
632
|
+
}
|
|
633
|
+
} else {
|
|
634
|
+
Write-Host "# ERROR: Failed to check if all submodules are up to date."
|
|
635
|
+
return $false
|
|
636
|
+
}
|
|
637
|
+
} else {
|
|
638
|
+
Write-Host "# Not a release pull request. Nothing to complete."
|
|
639
|
+
return $false
|
|
640
|
+
}
|
|
641
|
+
} else {
|
|
642
|
+
Write-Host "# Not triggered by a pull request. Nothing to complete."
|
|
643
|
+
return $false
|
|
644
|
+
}
|
|
645
|
+
return $true
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
Export-ModuleMember -Function Get-PullRequestToMain
|
|
649
|
+
Export-ModuleMember -Function Add-PullRequestComment
|
|
650
|
+
Export-ModuleMember -Function New-PullRequest
|
|
651
|
+
Export-ModuleMember -Function New-PullRequestToMain
|
|
652
|
+
Export-ModuleMember -Function Start-ProcessPullRequest
|
|
653
|
+
Export-ModuleMember -Function Complete-CorrespondingPullRequest
|