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

Sync eng/common directory with azure-sdk-tools for PR 2608 #1143

Merged
merged 2 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ steps:
-Language '${{parameters.Language}}' `
-RepoId '${{ parameters.RepoId }}' `
-DocValidationImageId '${{ parameters.DocValidationImageId }}' `
-PackageSourceOverride '${{ parameters.PackageSourceOverride }}'
-PackageSourceOverride '${{ parameters.PackageSourceOverride }}' `
-TenantId '$(opensource-aad-tenant-id)' `
-ClientId '$(opensource-aad-app-id)' `
-ClientSecret '$(opensource-aad-secret)'
displayName: Apply Documentation Updates

- template: /eng/common/pipelines/templates/steps/git-push-changes.yml
Expand Down
59 changes: 59 additions & 0 deletions eng/common/scripts/Helpers/Metadata-Helpers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
function Generate-AadToken ($TenantId, $ClientId, $ClientSecret)
{
$LoginAPIBaseURI = "https://login.microsoftonline.com/$TenantId/oauth2/token"

$headers = @{
"content-type" = "application/x-www-form-urlencoded"
}

$body = @{
"grant_type" = "client_credentials"
"client_id" = $ClientId
"client_secret" = $ClientSecret
"resource" = "api://repos.opensource.microsoft.com/audience/7e04aa67"
}
Write-Host "Generating aad token..."
$resp = Invoke-RestMethod $LoginAPIBaseURI -Method 'POST' -Headers $headers -Body $body
return $resp.access_token
}

function GetMsAliasFromGithub ($TenantId, $ClientId, $ClientSecret, $GithubUser)
{
$OpensourceAPIBaseURI = "https://repos.opensource.microsoft.com/api/people/links/github/$GithubUser"

$Headers = @{
"Content-Type" = "application/json"
"api-version" = "2019-10-01"
}

try {
$opsAuthToken = Generate-AadToken -TenantId $TenantId -ClientId $ClientId -ClientSecret $ClientSecret
$Headers["Authorization"] = "Bearer $opsAuthToken"
Write-Host "Fetching aad identity for github user: $GithubUser"
$resp = Invoke-RestMethod $OpensourceAPIBaseURI -Method 'GET' -Headers $Headers
}
catch {
Write-Error $_
return $null
}

$resp | Write-Verbose

if ($resp.aad) {
Write-Host "Fetched aad identity $($resp.aad.alias) for github user $GithubUser."
return $resp.aad.alias
}
Write-Error "Failed to retrieve the aad identity from given github user: $GithubName"
return $null
}

function GetPrimaryCodeOwner ($TargetDirectory)
{
$codeOwnerArray = &"$PSScriptRoot/../get-codeowners.ps1" -TargetDirectory $TargetDirectory
if ($codeOwnerArray) {
Write-Host "Code Owners are $codeOwnerArray."
return $codeOwnerArray[0]
}
Write-Error "No code owner found in $TargetDirectory."
return $null
}
44 changes: 30 additions & 14 deletions eng/common/scripts/Update-DocsMsMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ GitHub repository ID of the SDK. Typically of the form: 'Azure/azure-sdk-for-js'
The docker image id in format of '$containerRegistry/$imageName:$tag'
e.g. azuresdkimages.azurecr.io/jsrefautocr:latest

.PARAMETER PackageSourceOverride
Optional parameter to supply a different package source (useful for daily dev
docs generation from pacakges which are not published to the default feed). This
variable is meant to be used in the domain-specific business logic in
&$ValidateDocsMsPackagesFn
.PARAMETER TenantId
The aad tenant id/object id.

.PARAMETER ClientId
The add client id/application id.

.PARAMETER ClientSecret
The client secret of add app.
#>

param(
Expand All @@ -56,10 +59,20 @@ param(
[string]$DocValidationImageId,

[Parameter(Mandatory = $false)]
[string]$PackageSourceOverride
[string]$PackageSourceOverride,

[Parameter(Mandatory = $false)]
[string]$TenantId,

[Parameter(Mandatory = $false)]
[string]$ClientId,

[Parameter(Mandatory = $false)]
[string]$ClientSecret
)

. (Join-Path $PSScriptRoot common.ps1)
. (Join-Path $PSScriptRoot Helpers Metadata-Helpers.ps1)

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

# Get the first code owners of the package.
$author = "ramya-rao-a"
$msauthor = "ramyar"
Write-Host "Retrieve the code owner from $($PackageInfo.DirectoryPath)."
$codeOwnerArray = ."$PSScriptRoot/get-codeowners.ps1" `
-TargetDirectory $PackageInfo.DirectoryPath
if ($codeOwnerArray) {
Write-Host "Code Owners are $($codeOwnerArray -join ",")"
$author = $codeOwnerArray[0]
$msauthor = $author # This is a placeholder for now. Will change to the right ms alias.
$author = GetPrimaryCodeOwner -TargetDirectory $PackageInfo.DirectoryPath
if (!$author) {
$author = "ramya-rao-a"
$msauthor = "ramyar"
}
else {
$msauthor = GetMsAliasFromGithub -TenantId $TenantId -ClientId $ClientId -ClientSecret $ClientSecret -GithubUser $author
}
# Default value
if (!$msauthor) {
$msauthor = $author
}
Write-Host "The author of package: $author"
Write-Host "The ms author of package: $msauthor"
Expand Down