Skip to content

Commit

Permalink
Allow test PRs in SubmitPullRequest.ps1 script, updates to Invoke-Git…
Browse files Browse the repository at this point in the history
…HubAPI

update Repos format
  • Loading branch information
chidozieononiwu authored and azure-sdk committed Oct 20, 2020
1 parent 383b4b0 commit 4b66f21
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
4 changes: 3 additions & 1 deletion eng/common/pipelines/templates/steps/create-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ parameters:
# Multiple labels seperated by comma, e.g. "bug, APIView"
PRLabels: ''
SkipCheckingForChanges: false
CloseAfterOpenForTesting: false

steps:

Expand Down Expand Up @@ -63,7 +64,7 @@ steps:
-CommitMsg "${{ parameters.CommitMsg }}"
-GitUrl "https://$(azuresdk-github-pat)@github.com/${{ parameters.PROwner }}/$(RepoNameWithoutOwner).git"
-PushArgs "${{ parameters.PushArgs }}"
-SkipCommit $${{parameters.SkipCheckingForChanges}}
-SkipCommit $${{ parameters.SkipCheckingForChanges }}
- task: PowerShell@2
displayName: Create pull request
Expand All @@ -85,3 +86,4 @@ steps:
-UserReviewers "${{ parameters.GHReviewersVariable }}"
-TeamReviewers "${{ parameters.GHTeamReviewersVariable }}"
-Assignees "${{ parameters.GHAssignessVariable }}"
-CloseAfterOpenForTesting $${{ parameters.CloseAfterOpenForTesting }}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ steps:
GHReviewersVariable: ${{ parameters.GHReviewersVariable }}
GHTeamReviewersVariable: ${{ parameters.GHTeamReviewersVariable }}
PRLabels: ${{ parameters.PRLabels }}
CloseAfterOpenForTesting: $(TestPipeline)

- ${{if ne( parameters['OnboardingBranch'], '')}}:
- pwsh: |
Expand Down Expand Up @@ -122,4 +123,5 @@ steps:
WorkingDirectory: ${{ parameters.WorkingDirectory }}/repo
ScriptDirectory: ${{ parameters.WorkingDirectory }}/${{ parameters.ScriptDirectory }}
GHReviewersVariable: ${{ parameters.GHReviewersVariable }}
GHTeamReviewersVariable: ${{ parameters.GHTeamReviewersVariable }}
GHTeamReviewersVariable: ${{ parameters.GHTeamReviewersVariable }}
CloseAfterOpenForTesting: $(TestPipeline)
8 changes: 6 additions & 2 deletions eng/common/scripts/Invoke-GitHubAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ function Invoke-GitHubAPIPost {
return $resp
}
else {
throw "Did not fire request because of empty body."
$warning = "{0} with Uri [ $apiURI ] did not fire request because of empty body." -f (Get-PSCallStack)[1].FunctionName
LogWarning $warning
exit 0
}
}
catch {
Expand Down Expand Up @@ -65,7 +67,9 @@ function Invoke-GitHubAPIPatch {
return $resp
}
else {
throw "Did not fire request because of empty body."
$warning = "{0} with Uri [ $apiURI ] did not fire request because of empty body." -f (Get-PSCallStack)[1].FunctionName
LogWarning $warning
exit 0
}
}
catch {
Expand Down
18 changes: 14 additions & 4 deletions eng/common/scripts/Submit-PullRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ param(

[string]$TeamReviewers,

[string]$Assignees
[string]$Assignees,

[boolean]$CloseAfterOpenForTesting=$false
)

. "${PSScriptRoot}\common.ps1"
Expand Down Expand Up @@ -87,11 +89,19 @@ else {
# setting variable to reference the pull request by number
Write-Host "##vso[task.setvariable variable=Submitted.PullRequest.Number]$($resp.number)"

Update-GitHubIssue -RepoOwner $RepoOwner -RepoName $RepoName -IssueNumber $resp.number `
-Labels $PRLabels -Assignees $Assignees -AuthToken $AuthToken

Add-GitHubPullRequestReviewers -RepoOwner $RepoOwner -RepoName $RepoName -PrNumber $resp.number `
-Users $UserReviewers -Teams $TeamReviewers -AuthToken $AuthToken

if ($CloseAfterOpenForTesting) {
$prState = "closed"
LogDebug "Updating https://github.com/$RepoOwner/$RepoName/pull/$($resp.number) state to closed because this was only testing."
}
else {
$prState = "open"
}

Update-GitHubIssue -RepoOwner $RepoOwner -RepoName $RepoName -IssueNumber $resp.number `
-State $prState -Labels $PRLabels -Assignees $Assignees -AuthToken $AuthToken
}
catch {
LogError "Call to GitHub API failed with exception:`n$_"
Expand Down

0 comments on commit 4b66f21

Please sign in to comment.