-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync eng/common directory with azure-sdk-tools for PR 1081 (#751)
Sync eng/common directory with azure-sdk-tools for PR Azure/azure-sdk-tools#1081 See [eng/common workflow](https://github.com/Azure/azure-sdk-tools/blob/master/eng/common/README.md#workflow)
- Loading branch information
Showing
6 changed files
with
299 additions
and
62 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