Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools repository for Tools P…
Browse files Browse the repository at this point in the history
…R 989
  • Loading branch information
azure-sdk committed Sep 11, 2020
1 parent b6b74ee commit 0d7e0c9
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
18 changes: 18 additions & 0 deletions eng/common/pipelines/templates/steps/create-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,21 @@ steps:
-GitHubUsers "$(${{ parameters.GHReviewersVariable }})"
-GitHubTeams "$(${{ parameters.GHTeamReviewersVariable }})"
-PRNumber "$(Submitted.PullRequest.Number)"
- task: PowerShell@2
displayName: Add Assignee to Pull Request
condition: and(succeeded(), eq(variables['HasChanges'], 'true'))
continueOnError: true
inputs:
pwsh: true
workingDirectory: ${{ parameters.WorkingDirectory }}
filePath: ${{ parameters.ScriptDirectory }}/add-issue-assignees.ps1
arguments: >
-RepoOwner "${{ parameters.RepoOwner }}"
-RepoName "${{ parameters.RepoName }}"
-AuthToken "$(azuresdk-github-pat)"
-GitHubUsers "$(${{ parameters.GHReviewersVariable }})"
-IssueNumber "$(Submitted.PullRequest.Number)"
55 changes: 55 additions & 0 deletions eng/common/scripts/add-issue-assignees.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
param(
[Parameter(Mandatory = $true)]
$RepoOwner,

[Parameter(Mandatory = $true)]
$RepoName,

[Parameter(Mandatory = $false)]
$GitHubUsers = "",

[Parameter(Mandatory = $true)]
$IssueNumber,

[Parameter(Mandatory = $true)]
$AuthToken
)

function AddMembers($memberName, $additionSet) {
$headers = @{
Authorization = "bearer $AuthToken"
}
$uri = "https://api.github.com/repos/$RepoOwner/$RepoName/issues/$IssueNumber"
$errorOccurred = $false

foreach ($id in $additionSet) {
try {
$postResp = @{}
$postResp[$memberName] = @($id)
$postResp = $postResp | ConvertTo-Json

Write-Host $postResp
$resp = Invoke-RestMethod -Method Patch -Headers $headers -Body $postResp -Uri $uri -MaximumRetryCount 3
$resp | Write-Verbose
}
catch {
Write-Host "Error attempting to add $user`n$_"
$errorOccurred = $true
}
}

return $errorOccurred
}

if (-not $GitHubUsers) {
Write-Host "No user provided for addition, exiting."
exit 0
}

$userAdditions = @($GitHubUsers.Split(",") | % { $_.Trim() } | ? { return $_ })

$errorsOccurredAddingUsers = AddMembers -memberName "assignees" -additionSet $userAdditions

if ($errorsOccurredAddingUsers) {
exit 1
}
26 changes: 26 additions & 0 deletions eng/common/scripts/get-pr-creator.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
param (
$PullRequestNumber,
$VsoPRCreatorVariable,
$AuthToken
)

$headers = @{ }

if ($AuthToken) {
$headers = @{
Authorization = "bearer $AuthToken"
}
}

try
{
$prApiUrl = "https://api.github.com/repos/Azure/azure-sdk-tools/pulls/${PullRequestNumber}"
$response = Invoke-RestMethod -Headers $headers $prApiUrl
Write-Host "##vso[task.setvariable variable=$VsoPRCreatorVariable;]$($response.user.login)"
}
catch
{
Write-Error "Invoke-RestMethod ${prApiUrl} failed with exception:`n$_"
exit 1
}

0 comments on commit 0d7e0c9

Please sign in to comment.