Skip to content
Merged
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
113 changes: 78 additions & 35 deletions .github/workflows/Shared-AutoLabelAssign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jobs:
$AppGitHubAccessHeaders.Add("User-Agent", "OfficeDocs")

# Regex for string matches
$AuthorRegex = "(?m)^(author:\s{0,3})([\w|\-]{1,39})"
$AuthorRegex = "(?m)^(author:\s{0,3})([\w-]{1,39})(?=\s*(?:#|$))"
$ServiceRegex = "(ms\.service:\s{0,3})([\w|\-|\.]{1,60})"
$SubServiceRegex = "(ms\.subservice:\s{0,3})([\w|\-|\.]{1,60})"
$TechnologyRegex = "(ms\.technology:\s{0,3})([\w|\-|\.]{1,60})"
Expand Down Expand Up @@ -265,41 +265,63 @@ jobs:

}

$FullPath = (Resolve-Path -LiteralPath $FilePath -ErrorAction Stop).Path
$RepoRoot = (Resolve-Path -LiteralPath $RepoRoot -ErrorAction Stop).Path.TrimEnd([IO.Path]::DirectorySeparatorChar, [IO.Path]::AltDirectorySeparatorChar)
Try {

# Confirm the file is inside the repo
If (-not $FullPath.StartsWith($RepoRoot, [StringComparison]::OrdinalIgnoreCase)) {
$FullPath = (Resolve-Path -LiteralPath $FilePath -ErrorAction Stop).Path
$RepoRoot = (Resolve-Path -LiteralPath $RepoRoot -ErrorAction Stop).Path.TrimEnd([IO.Path]::DirectorySeparatorChar, [IO.Path]::AltDirectorySeparatorChar)

Throw 'FilePath is not located underneath the repository root.'
$FileResolved = $True

} Catch {

Write-Host "Unable to resolve $FilePath. File may have been deleted."
$FileResolved = $False

}

# Walk up the tree
$CurrentDir = Split-Path -Path $FullPath -Parent
If ($FileResolved) {

While ($CurrentDir) {
# Confirm the file is inside the repo
If (-not $FullPath.StartsWith($RepoRoot, [StringComparison]::OrdinalIgnoreCase)) {

$Candidate = Join-Path -Path $CurrentDir -ChildPath 'docfx.json'
Throw 'FilePath is not located underneath the repository root.'

If (Test-Path -LiteralPath $Candidate -PathType Leaf) {

Write-Host "Getting DocFx config from $Candidate"

Return (Get-Content -LiteralPath $Candidate -Raw) | ConvertFrom-Json -AsHashtable
}

If ($CurrentDir.TrimEnd([IO.Path]::DirectorySeparatorChar, [IO.Path]::AltDirectorySeparatorChar) -eq $RepoRoot) {
# Walk up the tree
$CurrentDir = Split-Path -Path $FullPath -Parent

While ($CurrentDir) {

$Candidate = Join-Path -Path $CurrentDir -ChildPath 'docfx.json'

If (Test-Path -LiteralPath $Candidate -PathType Leaf) {

Write-Host "Getting DocFx config from $Candidate"

Return (Get-Content -LiteralPath $Candidate -Raw) | ConvertFrom-Json -AsHashtable
}

Break
If ($CurrentDir.TrimEnd([IO.Path]::DirectorySeparatorChar, [IO.Path]::AltDirectorySeparatorChar) -eq $RepoRoot) {

Break

}

# Get the parent of the current folder
$CurrentDir = Split-Path -Path $CurrentDir -Parent

}

# Get the parent of the current folder
$CurrentDir = Split-Path -Path $CurrentDir -Parent
}

If ($FileResolved) {

Write-Host "ERROR: File path $FullPath and repo root $RepoRoot were resolved but no docfx.json file was found."

}

# Only reached if $FilePath isn't resolved or if While loop falls through without finding docfx.json.
Return $null
}

Expand Down Expand Up @@ -341,16 +363,17 @@ jobs:
# Pre-processing to be more efficient could actually use more cycles.
$DocFxConfig = Get-DocFxConfig -FilePath $FileName

# Check to see if the file contents contains a string that matches the $AuthorRegex regex pattern. If yes, add value to $Author, check
# fileMetadata and globalMetadata in that order in DocFx. If there's a match in either of those, return value. If not, return null.
# Check to see if the file contents contains a string that matches the $AuthorRegex regex pattern. If yes, add value to $Author. If not, check
# fileMetadata and globalMetadata in that order in DocFx. If there's a match in either of those, return value. If not, or if DocFx couldn't be
# found, return null.
If ($FileContents -match $AuthorRegex) {

$Author = $Matches[2]
$MetadataFound = $True

Write-Host "Found author $Author."
Write-Host "Found author $Author in file."

} Else {
} ElseIf ($DocFxConfig -ne $Null) {

Write-Host "Author not found in article. Checking DocFx fileMetadata for $FileName."

Expand Down Expand Up @@ -379,19 +402,25 @@ jobs:

}

} Else {

Write-Host "WARNING: Unable to retrieve author information from article file and unable to retrieve from docfx.json because it couldn't be found. This is expected if file was deleted."
$Author = $Null

}

# Check to see if file contents contains a string that matches the $ServiceRegex regex pattern. If yes, add value to $Service, check
# fileMetadata and globalMetadata in that order in DocFx. If there's a match in either of those, return value. If not, return null.
# Check to see if file contents contains a string that matches the $ServiceRegex regex pattern. If yes, add value to $Service. If not, check
# fileMetadata and globalMetadata in that order in DocFx. If there's a match in either of those, return value. If not, or if DocFx couldn't be
# found, return null.

If ($FileContents -match $ServiceRegex) {

$Service = $Matches[2]
$MetadataFound = $True

Write-Host "Found service $Service."
Write-Host "Found service $Service in file."

} Else {
} ElseIf ($DocFxConfig -ne $Null) {

Write-Host "Service not found in article. Checking DocFx fileMetadata for $FileName."

Expand Down Expand Up @@ -421,18 +450,24 @@ jobs:

}

} Else {

Write-Host "WARNING: Unable to retrieve service information from article file and unable to retrieve from docfx.json because it couldn't be found. This is expected if file was deleted."
$Service = $Null

}

# Check to see if file contents contains a string that matches the $SubServiceRegex regex pattern. If yes, add value to $SubService, check
# fileMetadata and globalMetadata in that order in DocFx. If there's a match in either of those, return value. If not, return null.
# Check to see if file contents contains a string that matches the $SubServiceRegex regex pattern. If yes, add value to $SubService. If not, check
# fileMetadata and globalMetadata in that order in DocFx. If there's a match in either of those, return value. If not, or if DocFx couldn't be
# found, return null.
If ($FileContents -match $SubServiceRegex) {

$SubService = $Matches[2]
$MetadataFound = $True

Write-Host "Found sub service $SubService."
Write-Host "Found sub service $SubService in file."

} Else {
} ElseIf ($DocFxConfig -ne $Null) {

Write-Host "SubService not found in article. Checking DocFx fileMetadata for $FileName."

Expand All @@ -459,7 +494,12 @@ jobs:

}

}
} Else {

Write-Host "WARNING: Unable to retrieve subservice information from article file and unable to retrieve from docfx.json because it couldn't be found. This is expected if file was deleted."
$SubService = $Null

}

# Check to see if file contents contains a string that matches the $ProdRegex regex pattern. If yes, add value to $Product. Then check TechnologyRegex regex pattern.
# If value isn't matched, assign $Null and don't check Technology.
Expand Down Expand Up @@ -1185,7 +1225,7 @@ jobs:

}

Write-Host "Reviewers found: $($ReviewerList | Sort-Object -Unique)"
Write-Host "Reviewers found in teams: $($ReviewerList | Sort-Object -Unique)"

Return $ReviewerList | Sort-Object -Unique

Expand Down Expand Up @@ -1292,13 +1332,15 @@ jobs:
# Main

Write-Host "Repo: $GitHubRepoName"
Write-Host "PR number: $PrNumber"
Write-Host "Sender: $GitHubSender"
Write-Host "Request event: $GitRequestEvent"
Write-Host "GitHub action: $GitHubAction"
Write-Host "GitHub state: $GitHubState"
Write-Host "Default branch: $DefaultBranch"
Write-Host "Target branch: $TargetBranch"
Write-Host "PR files URL: $PrFileListUrl"
Write-Host "PR HTML URL: $PrHtmlUrl"

Write-Host "Auto assign users on $GitHubRepoName`: $AutoAssignUsers"
Write-Host "Auto label on $GitHubRepoName`: $AutoLabel"
Expand Down Expand Up @@ -1435,10 +1477,10 @@ jobs:

$ReviewerAccounts = Get-TeamMembership -ReviewerTeams $ReviewerTeamArray

$AtMentionedGitHubAccounts = Add-AtPrefix -GitHubReviewers $ReviewerAccounts

If ($ReviewerAccounts.Length -gt 0) {

$AtMentionedGitHubAccounts = Add-AtPrefix -GitHubReviewers $ReviewerAccounts

$MissingReviewers = Compare-PRIndividualReviewers -GitHubReviewers $ReviewerAccounts

If ($MissingReviewers) {
Expand Down Expand Up @@ -1566,3 +1608,4 @@ jobs:

} # PR event and action check