-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eng Common Sync Improvements. (#1081)
- Refactor GitHub API call to allow reusability. - Add Clean up pipeline with step that deletes upstream sync branches . Moved to #1088 - Add auto-merge label to Sync and Tools PRs - Remove the Verify and Merge stage.
- Loading branch information
1 parent
b66d7d8
commit ab89dd4
Showing
8 changed files
with
331 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[string]$RepoOwner, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string]$RepoName, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string]$IssueNumber, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string]$Comment, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string]$AuthToken | ||
) | ||
|
||
. "${PSScriptRoot}\common.ps1" | ||
|
||
try { | ||
Add-IssueComment -RepoOwner $RepoOwner -RepoName $RepoName ` | ||
-IssueNumber $IssueNumber -Comment $Comment -AuthToken $AuthToken | ||
} | ||
catch { | ||
LogError "Add-IssueComment failed with exception:`n$_" | ||
exit 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[string]$RepoOwner, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string]$RepoName, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string]$IssueNumber, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string]$Labels, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string]$AuthToken | ||
) | ||
|
||
. "${PSScriptRoot}\common.ps1" | ||
|
||
try { | ||
Add-IssueLabels -RepoOwner $RepoOwner -RepoName $RepoName ` | ||
-IssueNumber $IssueNumber -Labels $Labels -AuthToken $AuthToken | ||
} | ||
catch { | ||
LogError "Add-IssueLabels failed with exception:`n$_" | ||
exit 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
$GithubAPIBaseURI = "https://api.github.com/repos" | ||
|
||
function Get-GitHubHeaders ($token) { | ||
$headers = @{ | ||
Authorization = "bearer $token" | ||
} | ||
return $headers | ||
} | ||
|
||
function Invoke-GitHubAPIPost { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
$apiURI, | ||
[Parameter(Mandatory = $true)] | ||
$body, | ||
[Parameter(Mandatory = $true)] | ||
$token | ||
) | ||
|
||
$resp = Invoke-RestMethod ` | ||
-Method POST ` | ||
-Body ($body | ConvertTo-Json) ` | ||
-Uri $apiURI ` | ||
-Headers (Get-GitHubHeaders -token $token) ` | ||
-MaximumRetryCount 3 | ||
|
||
return $resp | ||
} | ||
|
||
function Invoke-GitHubAPIPatch { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
$apiURI, | ||
[Parameter(Mandatory = $true)] | ||
$body, | ||
[Parameter(Mandatory = $true)] | ||
$token | ||
) | ||
|
||
$resp = Invoke-RestMethod ` | ||
-Method PATCH ` | ||
-Body ($body | ConvertTo-Json) ` | ||
-Uri $apiURI ` | ||
-Headers (Get-GitHubHeaders -token $token) ` | ||
-MaximumRetryCount 3 | ||
|
||
return $resp | ||
} | ||
|
||
function Invoke-GitHubAPIGet { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
$apiURI, | ||
$token | ||
) | ||
|
||
if ($token) | ||
{ | ||
$resp = Invoke-RestMethod ` | ||
-Method GET ` | ||
-Uri $apiURI ` | ||
-Headers (Get-GitHubHeaders -token $token) ` | ||
-MaximumRetryCount 3 | ||
} | ||
else { | ||
$resp = Invoke-RestMethod ` | ||
-Method GET ` | ||
-Uri $apiURI ` | ||
-MaximumRetryCount 3 | ||
} | ||
|
||
return $resp | ||
} | ||
|
||
function SplitMembers ($membersString) | ||
{ | ||
if (!$membersString) { return $null } | ||
return @($membersString.Split(",") | % { $_.Trim() } | ? { return $_ }) | ||
} | ||
|
||
function List-PullRequests { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
$RepoOwner, | ||
[Parameter(Mandatory = $true)] | ||
$RepoName, | ||
[ValidateSet("open","closed","all")] | ||
$State = "open", | ||
$Head, | ||
$Base, | ||
[ValidateSet("created","updated","popularity","long-running")] | ||
$Sort, | ||
[ValidateSet("asc","desc")] | ||
$Direction | ||
) | ||
|
||
$uri = "$GithubAPIBaseURI/$RepoOwner/$RepoName/pulls" | ||
if ($State -or $Head -or $Base -or $Sort -or $Direction) { $uri += '?'} | ||
if ($State) { $uri += "state=$State&" } | ||
if ($Head) { $uri += "head=$Head&" } | ||
if ($Base) { $uri += "base=$Base&" } | ||
if ($Sort) { $uri += "sort=$Sort&" } | ||
if ($Direction){ $uri += "direction=$Direction&" } | ||
|
||
return Invoke-GitHubAPIGet -apiURI $uri | ||
} | ||
|
||
function Add-IssueComment { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
$RepoOwner, | ||
[Parameter(Mandatory = $true)] | ||
$RepoName, | ||
[Parameter(Mandatory = $true)] | ||
$IssueNumber, | ||
[Parameter(Mandatory = $true)] | ||
$Comment, | ||
[Parameter(Mandatory = $true)] | ||
$AuthToken | ||
|
||
) | ||
$uri = "$GithubAPIBaseURI/$RepoOwner/$RepoName/issues/$IssueNumber/comments" | ||
|
||
$parameters = @{ | ||
body = $Comment | ||
} | ||
|
||
return Invoke-GitHubAPIPost -apiURI $uri -body $parameters -token $AuthToken | ||
} | ||
|
||
# Will add labels to existing labels on the issue | ||
function Add-IssueLabels { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
$RepoOwner, | ||
[Parameter(Mandatory = $true)] | ||
$RepoName, | ||
[Parameter(Mandatory = $true)] | ||
$IssueNumber, | ||
[ValidateNotNullOrEmpty()] | ||
[Parameter(Mandatory = $true)] | ||
$Labels, | ||
[Parameter(Mandatory = $true)] | ||
$AuthToken | ||
) | ||
|
||
if ($Labels.Trim().Length -eq 0) | ||
{ | ||
throw "The 'Labels' parameter should not not be whitespace..` | ||
You can use the 'Update-Issue' function if you plan to reset the labels" | ||
} | ||
|
||
$uri = "$GithubAPIBaseURI/$RepoOwner/$RepoName/issues/$IssueNumber/labels" | ||
$labelAdditions = SplitMembers -membersString $Labels | ||
$parameters = @{ | ||
labels = @($labelAdditions) | ||
} | ||
|
||
return Invoke-GitHubAPIPost -apiURI $uri -body $parameters -token $AuthToken | ||
} | ||
|
||
# Will add assignees to existing assignees on the issue | ||
function Add-IssueAssignees { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
$RepoOwner, | ||
[Parameter(Mandatory = $true)] | ||
$RepoName, | ||
[Parameter(Mandatory = $true)] | ||
$IssueNumber, | ||
[ValidateNotNullOrEmpty()] | ||
[Parameter(Mandatory = $true)] | ||
$Assignees, | ||
[Parameter(Mandatory = $true)] | ||
$AuthToken | ||
) | ||
|
||
if ($Assignees.Trim().Length -eq 0) | ||
{ | ||
throw "The 'Assignees' parameter should not be whitespace.` | ||
You can use the 'Update-Issue' function if you plan to reset the Assignees" | ||
} | ||
|
||
$uri = "$GithubAPIBaseURI/$RepoOwner/$RepoName/issues/$IssueNumber/assignees" | ||
$assigneesAdditions = SplitMembers -membersString $Assignees | ||
$parameters = @{ | ||
assignees = @($assigneesAdditions) | ||
} | ||
|
||
return Invoke-GitHubAPIPost -apiURI $uri -body $parameters -token $AuthToken | ||
} | ||
|
||
# For labels and assignee pass comma delimited string, to replace existing labels or assignees. | ||
# Or pass white space " " to remove all labels or assignees | ||
function Update-Issue { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
$RepoOwner, | ||
[Parameter(Mandatory = $true)] | ||
$RepoName, | ||
[Parameter(Mandatory = $true)] | ||
$IssueNumber, | ||
[string]$Title, | ||
[string]$Body, | ||
[ValidateSet("open","closed")] | ||
[string]$State, | ||
[int]$Milestome, | ||
[ValidateNotNullOrEmpty()] | ||
[string]$Labels, | ||
[ValidateNotNullOrEmpty()] | ||
[string]$Assignees, | ||
[Parameter(Mandatory = $true)] | ||
$AuthToken | ||
) | ||
|
||
$uri = "$GithubAPIBaseURI/$RepoOwner/$RepoName/issues/$IssueNumber" | ||
$parameters = @{} | ||
if ($Title) { $parameters["title"] = $Title } | ||
if ($Body) { $parameters["body"] = $Body } | ||
if ($State) { $parameters["state"] = $State } | ||
if ($Milestone) { $parameters["milestone"] = $Milestone } | ||
if ($Labels) { | ||
$labelAdditions = SplitMembers -membersString $Labels | ||
$parameters["labels"] = @($labelAdditions) | ||
} | ||
if ($Assignees) { | ||
$assigneesAdditions = SplitMembers -membersString $Assignees | ||
$parameters["assignees"] = @($assigneesAdditions) | ||
} | ||
|
||
return Invoke-GitHubAPIPatch -apiURI $uri -body $parameters -token $AuthToken | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.