-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eng Common Sync Improvements. #1081
Changes from all commits
38ce279
2fb1c49
0c95814
6cf8b50
efb05cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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 | ||
} |
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 | ||
} |
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()] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it valid to pass in empty to clear the assignees? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for this function. That can be done with the Update-Issue function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not that I think it is important but it would appear as though the Update-Issue function also blocks empty. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see what you mean. I should check for whitespace in this. |
||
[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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this does happen, what is the recovery step, delete the sync PRs and trigger again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to delete the sync pipeline. You'll just need to rerun the particular template pipeline that experienced the race condition. Again you only have to do this if your changes will potentially affect release.