Skip to content

Commit 182df0c

Browse files
authored
Sync eng/common directory with azure-sdk-tools for PR 2608 (Azure#22875)
1 parent d882a78 commit 182df0c

File tree

3 files changed

+93
-15
lines changed

3 files changed

+93
-15
lines changed

eng/common/pipelines/templates/steps/update-docsms-metadata.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ steps:
9494
-Language '${{parameters.Language}}' `
9595
-RepoId '${{ parameters.RepoId }}' `
9696
-DocValidationImageId '${{ parameters.DocValidationImageId }}' `
97-
-PackageSourceOverride '${{ parameters.PackageSourceOverride }}'
97+
-PackageSourceOverride '${{ parameters.PackageSourceOverride }}' `
98+
-TenantId '$(opensource-aad-tenant-id)' `
99+
-ClientId '$(opensource-aad-app-id)' `
100+
-ClientSecret '$(opensource-aad-secret)'
98101
displayName: Apply Documentation Updates
99102

100103
- template: /eng/common/pipelines/templates/steps/git-push-changes.yml
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
function Generate-AadToken ($TenantId, $ClientId, $ClientSecret)
2+
{
3+
$LoginAPIBaseURI = "https://login.microsoftonline.com/$TenantId/oauth2/token"
4+
5+
$headers = @{
6+
"content-type" = "application/x-www-form-urlencoded"
7+
}
8+
9+
$body = @{
10+
"grant_type" = "client_credentials"
11+
"client_id" = $ClientId
12+
"client_secret" = $ClientSecret
13+
"resource" = "api://repos.opensource.microsoft.com/audience/7e04aa67"
14+
}
15+
Write-Host "Generating aad token..."
16+
$resp = Invoke-RestMethod $LoginAPIBaseURI -Method 'POST' -Headers $headers -Body $body
17+
return $resp.access_token
18+
}
19+
20+
function GetMsAliasFromGithub ($TenantId, $ClientId, $ClientSecret, $GithubUser)
21+
{
22+
$OpensourceAPIBaseURI = "https://repos.opensource.microsoft.com/api/people/links/github/$GithubUser"
23+
24+
$Headers = @{
25+
"Content-Type" = "application/json"
26+
"api-version" = "2019-10-01"
27+
}
28+
29+
try {
30+
$opsAuthToken = Generate-AadToken -TenantId $TenantId -ClientId $ClientId -ClientSecret $ClientSecret
31+
$Headers["Authorization"] = "Bearer $opsAuthToken"
32+
Write-Host "Fetching aad identity for github user: $GithubUser"
33+
$resp = Invoke-RestMethod $OpensourceAPIBaseURI -Method 'GET' -Headers $Headers
34+
}
35+
catch {
36+
Write-Error $_
37+
return $null
38+
}
39+
40+
$resp | Write-Verbose
41+
42+
if ($resp.aad) {
43+
Write-Host "Fetched aad identity $($resp.aad.alias) for github user $GithubUser."
44+
return $resp.aad.alias
45+
}
46+
Write-Error "Failed to retrieve the aad identity from given github user: $GithubName"
47+
return $null
48+
}
49+
50+
function GetPrimaryCodeOwner ($TargetDirectory)
51+
{
52+
$codeOwnerArray = &"$PSScriptRoot/../get-codeowners.ps1" -TargetDirectory $TargetDirectory
53+
if ($codeOwnerArray) {
54+
Write-Host "Code Owners are $codeOwnerArray."
55+
return $codeOwnerArray[0]
56+
}
57+
Write-Error "No code owner found in $TargetDirectory."
58+
return $null
59+
}

eng/common/scripts/Update-DocsMsMetadata.ps1

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ GitHub repository ID of the SDK. Typically of the form: 'Azure/azure-sdk-for-js'
3232
The docker image id in format of '$containerRegistry/$imageName:$tag'
3333
e.g. azuresdkimages.azurecr.io/jsrefautocr:latest
3434
35-
.PARAMETER PackageSourceOverride
36-
Optional parameter to supply a different package source (useful for daily dev
37-
docs generation from pacakges which are not published to the default feed). This
38-
variable is meant to be used in the domain-specific business logic in
39-
&$ValidateDocsMsPackagesFn
35+
.PARAMETER TenantId
36+
The aad tenant id/object id.
37+
38+
.PARAMETER ClientId
39+
The add client id/application id.
40+
41+
.PARAMETER ClientSecret
42+
The client secret of add app.
4043
#>
4144

4245
param(
@@ -56,10 +59,20 @@ param(
5659
[string]$DocValidationImageId,
5760

5861
[Parameter(Mandatory = $false)]
59-
[string]$PackageSourceOverride
62+
[string]$PackageSourceOverride,
63+
64+
[Parameter(Mandatory = $false)]
65+
[string]$TenantId,
66+
67+
[Parameter(Mandatory = $false)]
68+
[string]$ClientId,
69+
70+
[Parameter(Mandatory = $false)]
71+
[string]$ClientSecret
6072
)
6173

6274
. (Join-Path $PSScriptRoot common.ps1)
75+
. (Join-Path $PSScriptRoot Helpers Metadata-Helpers.ps1)
6376

6477
$releaseReplaceRegex = "(https://github.com/$RepoId/(?:blob|tree)/)(?:master|main)"
6578
$TITLE_REGEX = "(\#\s+(?<filetitle>Azure .+? (?:client|plugin|shared) library for (?:JavaScript|Java|Python|\.NET|C)))"
@@ -94,15 +107,18 @@ function GetAdjustedReadmeContent($ReadmeContent, $PackageInfo, $PackageMetadata
94107
}
95108

96109
# Get the first code owners of the package.
97-
$author = "ramya-rao-a"
98-
$msauthor = "ramyar"
99110
Write-Host "Retrieve the code owner from $($PackageInfo.DirectoryPath)."
100-
$codeOwnerArray = ."$PSScriptRoot/get-codeowners.ps1" `
101-
-TargetDirectory $PackageInfo.DirectoryPath
102-
if ($codeOwnerArray) {
103-
Write-Host "Code Owners are $($codeOwnerArray -join ",")"
104-
$author = $codeOwnerArray[0]
105-
$msauthor = $author # This is a placeholder for now. Will change to the right ms alias.
111+
$author = GetPrimaryCodeOwner -TargetDirectory $PackageInfo.DirectoryPath
112+
if (!$author) {
113+
$author = "ramya-rao-a"
114+
$msauthor = "ramyar"
115+
}
116+
else {
117+
$msauthor = GetMsAliasFromGithub -TenantId $TenantId -ClientId $ClientId -ClientSecret $ClientSecret -GithubUser $author
118+
}
119+
# Default value
120+
if (!$msauthor) {
121+
$msauthor = $author
106122
}
107123
Write-Host "The author of package: $author"
108124
Write-Host "The ms author of package: $msauthor"

0 commit comments

Comments
 (0)