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

fix the issue that detected special commit incorrectly in use GenerateExternalContributors.ps1 #14828

Merged
merged 7 commits into from
Apr 28, 2021
38 changes: 26 additions & 12 deletions tools/GenerateExternalContributors.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ param(
[int]
$DaysBack = 28
)

$SinceDate = (Get-Date).AddDays((0-$DaysBack))
$SinceDateStr = $SinceDate.ToString('yyyy-MM-ddTHH:mm:ssZ')
$Branch = git branch --show-current # The Git 2.22 and above support.
Expand Down Expand Up @@ -74,28 +73,43 @@ $sortPRs = $validPRs | Sort-Object -Property @{Expression = {$_.author.login}; D

$skipContributors = @('aladdindoc')

$contributorsMDHeaderFlag = $True
# Get team members of the azure-powershell-team.
$teamMembers = (Invoke-WebRequest -Uri "https://api.github.com/orgs/Azure/teams/azure-powershell-team/members" -Authentication Bearer -Token $token).Content | ConvertFrom-Json

foreach ($members in $teamMembers) {
$skipContributors += $members.login
}

# Output external contributors information.
Write-Debug 'Output external contributors information.'
'### Thanks to our community contributors' | Out-File -FilePath $contributorsMDFile -Force
Write-Host '### Thanks to our community contributors'

for ($PR = 0; $PR -lt $sortPRs.Length; $PR++) {
if ($skipContributors.Contains($sortPRs[$PR].author.login))

$account = $sortPRs[$PR].author.login
$name = $sortPRs[$PR].commit.author.name
$index = $sortPRs[$PR].commit.message.IndexOf("`n`n")

if ($skipContributors.Contains($account))
{
continue
}

# Skip if commit author exists in skipContributors list.
if ([System.String]::IsNullOrEmpty($account) -and $skipContributors.Contains($name))
{
continue
}

# Check whether the contributor belongs to the Azure organization.
Invoke-RestMethod -Uri "https://api.github.com/orgs/Azure/members/$($sortPRs[$PR].author.login)" -Authentication Bearer -Token $token -ResponseHeadersVariable 'ResponseHeaders' -StatusCodeVariable 'StatusCode' -SkipHttpErrorCheck > $null
if ($StatusCode -eq '204') {
# Add internal contributors to skipContributors to reduce the number of https requests sent.
$skipContributors += $sortPRs[$PR].author.login
continue
}
if ($contributorsMDHeaderFlag) {
Write-Debug 'Output exteneral contributors infomation.'
'### Thanks to our community contributors' | Out-File -FilePath $contributorsMDFile -Force
Write-Host '### Thanks to our community contributors'
$contributorsMDHeaderFlag = $False
}
$account = $sortPRs[$PR].author.login
$name = $sortPRs[$PR].commit.author.name
$index = $sortPRs[$PR].commit.message.IndexOf("`n`n")

if ($index -lt 0) {
$commitMessage = $sortPRs[$PR].commit.message
} else {
Expand Down