Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 1091 (#16027)
Browse files Browse the repository at this point in the history
* Refactpr Submit Pull Request Script

* Refactor logic for interacting with Pull Requests

* Rework API Lib

Co-authored-by: Chidozie Ononiwu <[email protected]>
  • Loading branch information
azure-sdk and chidozieononiwu authored Oct 16, 2020
1 parent 9876881 commit baa4ac0
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 221 deletions.
22 changes: 5 additions & 17 deletions eng/common/pipelines/templates/steps/create-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ parameters:
ScriptDirectory: eng/common/scripts
GHReviewersVariable: ''
GHTeamReviewersVariable: ''
GHAssignessVariable: ''
# Multiple labels seperated by comma, e.g. "bug, APIView"
PRLabels: ''
SkipCheckingForChanges: false
Expand Down Expand Up @@ -80,20 +81,7 @@ steps:
-AuthToken "$(azuresdk-github-pat)"
-PRTitle "${{ parameters.PRTitle }}"
-PRBody "${{ coalesce(parameters.PRBody, parameters.CommitMsg, parameters.PRTitle) }}"
-PRLabels "${{ parameters.PRLabels}}"
- task: PowerShell@2
displayName: Tag a Reviewer on PR
condition: and(succeeded(), eq(variables['HasChanges'], 'true'))
continueOnError: true
inputs:
pwsh: true
workingDirectory: ${{ parameters.WorkingDirectory }}
filePath: ${{ parameters.ScriptDirectory }}/add-pullrequest-reviewers.ps1
arguments: >
-RepoOwner "${{ parameters.RepoOwner }}"
-RepoName "$(RepoNameWithoutOwner)"
-AuthToken "$(azuresdk-github-pat)"
-GitHubUsers "$(${{ parameters.GHReviewersVariable }})"
-GitHubTeams "$(${{ parameters.GHTeamReviewersVariable }})"
-PRNumber "$(Submitted.PullRequest.Number)"
-PRLabels "${{ parameters.PRLabels }}"
-UserReviewers "${{ parameters.GHReviewersVariable }}"
-TeamReviewers "${{ parameters.GHTeamReviewersVariable }}"
-Assignees "${{ parameters.GHAssignessVariable }}"
4 changes: 2 additions & 2 deletions eng/common/scripts/Add-IssueComment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ param(
. "${PSScriptRoot}\common.ps1"

try {
Add-IssueComment -RepoOwner $RepoOwner -RepoName $RepoName `
Add-GithubIssueComment -RepoOwner $RepoOwner -RepoName $RepoName `
-IssueNumber $IssueNumber -Comment $Comment -AuthToken $AuthToken
}
catch {
LogError "Add-IssueComment failed with exception:`n$_"
LogError "Add-GithubIssueComment failed with exception:`n$_"
exit 1
}
4 changes: 2 additions & 2 deletions eng/common/scripts/Add-IssueLabels.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ param(
. "${PSScriptRoot}\common.ps1"

try {
Add-IssueLabels -RepoOwner $RepoOwner -RepoName $RepoName `
Add-GithubIssueLabels -RepoOwner $RepoOwner -RepoName $RepoName `
-IssueNumber $IssueNumber -Labels $Labels -AuthToken $AuthToken
}
catch {
LogError "Add-IssueLabels failed with exception:`n$_"
LogError "Add-GithubIssueLabels failed with exception:`n$_"
exit 1
}
12 changes: 6 additions & 6 deletions eng/common/scripts/Delete-RemoteBranches.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ param(

LogDebug "Operating on Repo [ $RepoName ]"
try{
$branches = (List-References -RepoOwner $RepoOwner -RepoName $RepoName -Ref "heads/$BranchPrefix").ref
$branches = (Get-GitHubSourceReferences -RepoOwner $RepoOwner -RepoName $RepoName -Ref "heads/$BranchPrefix").ref
}
catch {
LogError "List-References failed with exception:`n$_"
LogError "Get-GitHubSourceReferences failed with exception:`n$_"
exit 1
}

Expand All @@ -22,22 +22,22 @@ foreach ($branch in $branches)
$branchName = $branch.Replace("refs/heads/","")
$head = "${RepoOwner}/${RepoName}:${branchName}"
LogDebug "Operating on branch [ $branchName ]"
$pullRequests = List-PullRequests -RepoOwner $RepoOwner -RepoName $RepoName -head $head
$pullRequests = Get-GitHubPullRequests -RepoOwner $RepoOwner -RepoName $RepoName -head $head
}
catch
{
LogError "List-PullRequests failed with exception:`n$_"
LogError "Get-GitHubPullRequests failed with exception:`n$_"
exit 1
}

if ($pullRequests.Count -eq 0)
{
LogDebug "Branch [ $branchName ] in repo [ $RepoName ] has no associated Pull Request. Deleting Branch"
try{
Delete-References -RepoOwner $RepoOwner -RepoName $RepoName -Ref ($branch.Remove(0,5)) -AuthToken $AuthToken
Remove-GitHubSourceReferences -RepoOwner $RepoOwner -RepoName $RepoName -Ref ($branch.Remove(0,5)) -AuthToken $AuthToken
}
catch {
LogError "Delete-References failed with exception:`n$_"
LogError "Remove-GitHubSourceReferences failed with exception:`n$_"
exit 1
}
}
Expand Down
24 changes: 24 additions & 0 deletions eng/common/scripts/Get-PullRequestCreator.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
param (
[Parameter(Mandatory = $true)]
[string]$RepoOwner,

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

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

. "${PSScriptRoot}\common.ps1"

try
{
$pullRequest = Get-GithubPullRequest -RepoOwner $RepoOwner -RepoName $RepoName -PullRequestNumber $PullRequestNumber
Write-Host "##vso[task.setvariable variable=System.PullRequest.Creator;]$($pullRequest.user.login)"
}
catch
{
Write-Error "Get-PullRequest failed with exception:`n$_"
exit 1
}

Loading

0 comments on commit baa4ac0

Please sign in to comment.