Add GitHub Reactions support (#193)
Adds support for `Issue` and `PullRequest` reactions by adding the following new functions: * [`Get-GitHubReaction`](https://developer.github.com/v3/reactions/#list-reactions-for-an-issue) * [`Set-GitHubReaction`](https://developer.github.com/v3/reactions/#create-reaction-for-an-issue) * [`Remove-GitHubReaction`](https://developer.github.com/v3/reactions/#delete-an-issue-reaction)
This commit is contained in:
Родитель
d76f54b08e
Коммит
8e55f5af03
|
@ -44,6 +44,7 @@ filter Get-GitHubAssignee
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
GitHub.User
|
||||
|
@ -156,6 +157,7 @@ filter Test-GitHubAssignee
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
GitHub.User
|
||||
|
@ -299,6 +301,7 @@ function Add-GitHubAssignee
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
GitHub.User
|
||||
|
@ -476,6 +479,7 @@ function Remove-GitHubAssignee
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ filter Get-GitHubRepositoryBranch
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ filter Get-GitHubEvent
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ filter Get-GitHubIssueComment
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -343,6 +344,7 @@ filter New-GitHubIssueComment
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
GitHub.User
|
||||
|
@ -486,6 +488,7 @@ filter Set-GitHubIssueComment
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
GitHub.User
|
||||
|
@ -616,6 +619,7 @@ filter Remove-GitHubIssueComment
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -128,6 +128,7 @@ filter Get-GitHubIssue
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
GitHub.User
|
||||
|
@ -431,6 +432,7 @@ filter Get-GitHubIssueTimeline
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -569,6 +571,7 @@ filter New-GitHubIssue
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -737,6 +740,7 @@ filter Set-GitHubIssue
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -887,6 +891,7 @@ filter Lock-GitHubIssue
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -1017,6 +1022,7 @@ filter Unlock-GitHubIssue
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ filter Get-GitHubLabel
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -250,6 +251,7 @@ filter New-GitHubLabel
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -391,6 +393,7 @@ filter Remove-GitHubLabel
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -548,6 +551,7 @@ filter Set-GitHubLabel
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -694,6 +698,7 @@ filter Initialize-GitHubLabel
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -833,6 +838,7 @@ function Add-GitHubIssueLabel
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -993,6 +999,7 @@ function Set-GitHubIssueLabel
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -1184,6 +1191,7 @@ filter Remove-GitHubIssueLabel
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ filter Get-GitHubMilestone
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -269,6 +270,7 @@ filter New-GitHubMilestone
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -450,6 +452,7 @@ filter Set-GitHubMilestone
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -630,6 +633,7 @@ filter Remove-GitHubMilestone
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -235,7 +235,6 @@ filter Get-GitHubLicense
|
|||
the background, enabling the command prompt to provide status information.
|
||||
If not supplied here, the DefaultNoStatus configuration property value will be used.
|
||||
|
||||
|
||||
.INPUTS
|
||||
[String]
|
||||
GitHub.Branch
|
||||
|
@ -249,10 +248,10 @@ filter Get-GitHubLicense
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
||||
.OUTPUTS
|
||||
GitHub.License
|
||||
|
||||
|
@ -487,10 +486,10 @@ filter Get-GitHubCodeOfConduct
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
||||
.OUTPUTS
|
||||
GitHub.CodeOfConduct
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ filter Get-GitHubProject
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -274,6 +275,7 @@ filter New-GitHubProject
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -76,6 +76,7 @@ filter Get-GitHubPullRequest
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -271,6 +272,7 @@ filter New-GitHubPullRequest
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -0,0 +1,710 @@
|
|||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
@{
|
||||
GitHubReactionTypeName = 'GitHub.Reaction'
|
||||
}.GetEnumerator() | ForEach-Object {
|
||||
Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value
|
||||
}
|
||||
|
||||
filter Get-GitHubReaction
|
||||
{
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Retrieve reactions of a given GitHub Issue or Pull Request.
|
||||
|
||||
.DESCRIPTION
|
||||
Retrieve reactions of a given GitHub Issue or Pull Request.
|
||||
|
||||
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
|
||||
|
||||
.PARAMETER OwnerName
|
||||
Owner of the repository.
|
||||
If not supplied here, the DefaultOwnerName configuration property value will be used.
|
||||
|
||||
.PARAMETER RepositoryName
|
||||
Name of the repository.
|
||||
If not supplied here, the DefaultRepositoryName configuration property value will be used.
|
||||
|
||||
.PARAMETER Uri
|
||||
Uri for the repository.
|
||||
The OwnerName and RepositoryName will be extracted from here instead of needing to provide
|
||||
them individually.
|
||||
|
||||
.PARAMETER Issue
|
||||
The issue number.
|
||||
|
||||
.PARAMETER PullRequest
|
||||
The pull request number.
|
||||
|
||||
.PARAMETER ReactionType
|
||||
The type of reaction you want to retrieve. This is also called the 'content' in
|
||||
the GitHub API. Valid options are based off:
|
||||
https://developer.github.com/v3/reactions/#reaction-types
|
||||
|
||||
.PARAMETER AccessToken
|
||||
If provided, this will be used as the AccessToken for authentication with the
|
||||
REST Api. Otherwise, will attempt to use the configured value or will run
|
||||
unauthenticated.
|
||||
|
||||
.PARAMETER NoStatus
|
||||
If this switch is specified, long-running commands will run on the main thread
|
||||
with no commandline status update. When not specified, those commands run in
|
||||
the background, enabling the command prompt to provide status information.
|
||||
If not supplied here, the DefaultNoStatus configuration property value will be used.
|
||||
|
||||
.INPUTS
|
||||
GitHub.Branch
|
||||
GitHub.Content
|
||||
GitHub.Event
|
||||
GitHub.Issue
|
||||
GitHub.IssueComment
|
||||
GitHub.Label
|
||||
GitHub.Milestone
|
||||
GitHub.PullRequest
|
||||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
.OUTPUTS
|
||||
GitHub.Reaction
|
||||
|
||||
.EXAMPLE
|
||||
Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157
|
||||
|
||||
Gets the reactions for issue 157 from the Microsoft\PowerShellForGitHub
|
||||
project.
|
||||
|
||||
.EXAMPLE
|
||||
Get-GitHubReaction -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 -ReactionType eyes
|
||||
|
||||
Gets the 'eyes' reactions for issue 157 from the Microsoft\PowerShellForGitHub
|
||||
project.
|
||||
|
||||
.EXAMPLE
|
||||
Get-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 157 | Get-GitHubReaction
|
||||
|
||||
Gets a GitHub issue and pipe it into Get-GitHubReaction to get all
|
||||
the reactions for that issue.
|
||||
|
||||
.EXAMPLE
|
||||
Get-GitHubPullRequest -Uri https://github.com/microsoft/PowerShellForGitHub -PullRequest 193 | Get-GitHubReaction
|
||||
|
||||
Gets a GitHub pull request and pipes it into Get-GitHubReaction
|
||||
to get all the reactions for that pull request.
|
||||
|
||||
.NOTES
|
||||
Currently, issue comments, pull request comments and commit comments are not supported.
|
||||
#>
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess,
|
||||
DefaultParameterSetName='ElementsIssue')]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
|
||||
param(
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='ElementsIssue')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='ElementsPullRequest')]
|
||||
[string] $OwnerName,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='ElementsIssue')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='ElementsPullRequest')]
|
||||
[string] $RepositoryName,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='UriIssue')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='UriPullRequest')]
|
||||
[Alias('RepositoryUrl')]
|
||||
[string] $Uri,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='ElementsIssue')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='UriIssue',
|
||||
ValueFromPipelineByPropertyName)]
|
||||
[Alias('IssueNumber')]
|
||||
[int64] $Issue,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='ElementsPullRequest')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='UriPullRequest')]
|
||||
[Alias('PullRequestNumber')]
|
||||
[int64] $PullRequest,
|
||||
|
||||
[ValidateSet('+1', '-1', 'Laugh', 'Confused', 'Heart', 'Hooray', 'Rocket', 'Eyes')]
|
||||
[string] $ReactionType,
|
||||
|
||||
[string] $AccessToken,
|
||||
|
||||
[switch] $NoStatus
|
||||
)
|
||||
|
||||
Write-InvocationLog
|
||||
|
||||
$elements = Resolve-RepositoryElements
|
||||
$OwnerName = $elements.ownerName
|
||||
$RepositoryName = $elements.repositoryName
|
||||
|
||||
$telemetryProperties = @{
|
||||
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
|
||||
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
|
||||
}
|
||||
|
||||
$splatForAddedProperties = @{
|
||||
OwnerName = $OwnerName
|
||||
Repository = $RepositoryName
|
||||
}
|
||||
|
||||
if ($Issue)
|
||||
{
|
||||
$splatForAddedProperties.Issue = $Issue
|
||||
$targetObjectNumber = $Issue
|
||||
$targetObjectTypeName = 'Issue'
|
||||
$uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions"
|
||||
}
|
||||
else
|
||||
{
|
||||
# Pull Request
|
||||
$splatForAddedProperties.PullRequest = $PullRequest
|
||||
$targetObjectNumber = $PullRequest
|
||||
$targetObjectTypeName = 'Pull Request'
|
||||
$uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions"
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('ReactionType'))
|
||||
{
|
||||
$uriFragment += "?content=" + [Uri]::EscapeDataString($ReactionType.ToLower())
|
||||
}
|
||||
|
||||
$description = "Getting reactions for $targetObjectTypeName $targetObjectNumber in $RepositoryName"
|
||||
|
||||
$params = @{
|
||||
'UriFragment' = $uriFragment
|
||||
'Description' = $description
|
||||
'AcceptHeader' = $script:squirrelGirlAcceptHeader
|
||||
'AccessToken' = $AccessToken
|
||||
'TelemetryEventName' = $MyInvocation.MyCommand.Name
|
||||
'TelemetryProperties' = $telemetryProperties
|
||||
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
|
||||
}
|
||||
|
||||
$result = Invoke-GHRestMethodMultipleResult @params
|
||||
return ($result | Add-GitHubReactionAdditionalProperties @splatForAddedProperties)
|
||||
}
|
||||
|
||||
filter Set-GitHubReaction
|
||||
{
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sets a reaction of a given GitHub Issue or Pull Request.
|
||||
|
||||
.DESCRIPTION
|
||||
Sets a reaction of a given GitHub Issue or Pull Request.
|
||||
|
||||
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
|
||||
|
||||
.PARAMETER OwnerName
|
||||
Owner of the repository.
|
||||
If not supplied here, the DefaultOwnerName configuration property value will be used.
|
||||
|
||||
.PARAMETER RepositoryName
|
||||
Name of the repository.
|
||||
If not supplied here, the DefaultRepositoryName configuration property value will be used.
|
||||
|
||||
.PARAMETER Uri
|
||||
Uri for the repository.
|
||||
The OwnerName and RepositoryName will be extracted from here instead of needing to provide
|
||||
them individually.
|
||||
|
||||
.PARAMETER Issue
|
||||
The issue number.
|
||||
|
||||
.PARAMETER PullRequest
|
||||
The pull request number.
|
||||
|
||||
.PARAMETER ReactionType
|
||||
The type of reaction you want to set. This is aslo called the 'content' in the GitHub API.
|
||||
Valid options are based off: https://developer.github.com/v3/reactions/#reaction-types
|
||||
|
||||
.PARAMETER AccessToken
|
||||
If provided, this will be used as the AccessToken for authentication with the
|
||||
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
|
||||
|
||||
.PARAMETER NoStatus
|
||||
If this switch is specified, long-running commands will run on the main thread
|
||||
with no commandline status update. When not specified, those commands run in
|
||||
the background, enabling the command prompt to provide status information.
|
||||
If not supplied here, the DefaultNoStatus configuration property value will be used.
|
||||
|
||||
.INPUTS
|
||||
GitHub.Branch
|
||||
GitHub.Content
|
||||
GitHub.Event
|
||||
GitHub.Issue
|
||||
GitHub.IssueComment
|
||||
GitHub.Label
|
||||
GitHub.Milestone
|
||||
GitHub.PullRequest
|
||||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
.OUTPUTS
|
||||
GitHub.Reaction
|
||||
|
||||
.EXAMPLE
|
||||
Set-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket
|
||||
|
||||
Sets the 'rocket' reaction for issue 12626 of the PowerShell\PowerShell project.
|
||||
|
||||
.EXAMPLE
|
||||
Get-GitHubPullRequest -Uri https://github.com/microsoft/PowerShellForGitHub -PullRequest 193 | Set-GitHubReaction -ReactionType Heart
|
||||
|
||||
Gets a GitHub pull request and pipes it into Set-GitHubReaction to set the
|
||||
'heart' reaction for that pull request.
|
||||
|
||||
.NOTES
|
||||
Currently, issue comments, pull request comments and commit comments are not supported.
|
||||
#>
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess,
|
||||
DefaultParameterSetName='ElementsIssue')]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
|
||||
param(
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='ElementsIssue')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='ElementsPullRequest')]
|
||||
[string] $OwnerName,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='ElementsIssue')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='ElementsPullRequest')]
|
||||
[string] $RepositoryName,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='UriIssue')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='UriPullRequest')]
|
||||
[Alias('RepositoryUrl')]
|
||||
[string] $Uri,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='ElementsIssue')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='UriIssue',
|
||||
ValueFromPipelineByPropertyName)]
|
||||
[Alias('IssueNumber')]
|
||||
[int64] $Issue,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='ElementsPullRequest')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='UriPullRequest')]
|
||||
[Alias('PullRequestNumber')]
|
||||
[int64] $PullRequest,
|
||||
|
||||
[ValidateSet('+1', '-1', 'Laugh', 'Confused', 'Heart', 'Hooray', 'Rocket', 'Eyes')]
|
||||
[Parameter(Mandatory)]
|
||||
[string] $ReactionType,
|
||||
|
||||
[string] $AccessToken,
|
||||
|
||||
[switch] $NoStatus
|
||||
)
|
||||
|
||||
Write-InvocationLog
|
||||
|
||||
$elements = Resolve-RepositoryElements
|
||||
$OwnerName = $elements.ownerName
|
||||
$RepositoryName = $elements.repositoryName
|
||||
|
||||
$telemetryProperties = @{
|
||||
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
|
||||
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
|
||||
}
|
||||
|
||||
$splatForAddedProperties = @{
|
||||
OwnerName = $OwnerName
|
||||
Repository = $RepositoryName
|
||||
}
|
||||
|
||||
if ($Issue)
|
||||
{
|
||||
$splatForAddedProperties.Issue = $Issue
|
||||
$targetObjectNumber = $Issue
|
||||
$targetObjectTypeName = 'Issue'
|
||||
$uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions"
|
||||
}
|
||||
else
|
||||
{
|
||||
# Pull request
|
||||
$splatForAddedProperties.PullRequest = $PullRequest
|
||||
$targetObjectNumber = $PullRequest
|
||||
$targetObjectTypeName = 'Pull Request'
|
||||
$uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions"
|
||||
}
|
||||
|
||||
$description = "Setting reaction $ReactionType for $targetObjectTypeName $targetObjectNumber in $RepositoryName"
|
||||
|
||||
$params = @{
|
||||
'UriFragment' = $uriFragment
|
||||
'Description' = $description
|
||||
'Method' = 'Post'
|
||||
'Body' = ConvertTo-Json -InputObject @{ content = $ReactionType.ToLower() }
|
||||
'AcceptHeader' = $script:squirrelGirlAcceptHeader
|
||||
'AccessToken' = $AccessToken
|
||||
'TelemetryEventName' = $MyInvocation.MyCommand.Name
|
||||
'TelemetryProperties' = $telemetryProperties
|
||||
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
|
||||
}
|
||||
|
||||
$result = Invoke-GHRestMethod @params
|
||||
|
||||
return ($result | Add-GitHubReactionAdditionalProperties @splatForAddedProperties)
|
||||
}
|
||||
|
||||
filter Remove-GitHubReaction
|
||||
{
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Removes a reaction on a given GitHub Issue or Pull Request.
|
||||
|
||||
.DESCRIPTION
|
||||
Removes a reaction on a given GitHub Issue or Pull Request.
|
||||
|
||||
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
|
||||
|
||||
.PARAMETER OwnerName
|
||||
Owner of the repository.
|
||||
If not supplied here, the DefaultOwnerName configuration property value will be used.
|
||||
|
||||
.PARAMETER RepositoryName
|
||||
Name of the repository.
|
||||
If not supplied here, the DefaultRepositoryName configuration property value will be used.
|
||||
|
||||
.PARAMETER Uri
|
||||
Uri for the repository.
|
||||
The OwnerName and RepositoryName will be extracted from here instead of needing to provide
|
||||
them individually.
|
||||
|
||||
.PARAMETER Issue
|
||||
The issue number.
|
||||
|
||||
.PARAMETER PullRequest
|
||||
The pull request number.
|
||||
|
||||
.PARAMETER ReactionId
|
||||
The Id of the reaction. You can get this from using Get-GitHubReaction.
|
||||
|
||||
.PARAMETER Force
|
||||
If this switch is specified, you will not be prompted for confirmation of command execution.
|
||||
|
||||
.PARAMETER AccessToken
|
||||
If provided, this will be used as the AccessToken for authentication with the
|
||||
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
|
||||
|
||||
.PARAMETER NoStatus
|
||||
If this switch is specified, long-running commands will run on the main thread
|
||||
with no commandline status update. When not specified, those commands run in
|
||||
the background, enabling the command prompt to provide status information.
|
||||
If not supplied here, the DefaultNoStatus configuration property value will be used.
|
||||
|
||||
.INPUTS
|
||||
GitHub.Branch
|
||||
GitHub.Content
|
||||
GitHub.Event
|
||||
GitHub.Issue
|
||||
GitHub.IssueComment
|
||||
GitHub.Label
|
||||
GitHub.Milestone
|
||||
GitHub.PullRequest
|
||||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
.OUTPUTS
|
||||
None
|
||||
|
||||
.EXAMPLE
|
||||
Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 `
|
||||
-ReactionId 1234
|
||||
|
||||
Remove a reaction by Id on Issue 12626 from the PowerShell\PowerShell project
|
||||
interactively.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionId 1234 -Confirm:$false
|
||||
|
||||
Remove a reaction by Id on Issue 12626 from the PowerShell\PowerShell project
|
||||
non-interactively.
|
||||
|
||||
.EXAMPLE
|
||||
Get-GitHubReaction -OwnerName PowerShell -RepositoryName PowerShell -Issue 12626 -ReactionType rocket | Remove-GitHubReaction -Confirm:$false
|
||||
|
||||
Gets a reaction using Get-GitHubReaction and pipes it into Remove-GitHubReaction.
|
||||
|
||||
.NOTES
|
||||
Currently, issue comments, pull request comments and commit comments are not supported.
|
||||
#>
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess,
|
||||
DefaultParameterSetName='ElementsIssue',
|
||||
ConfirmImpact='High')]
|
||||
[Alias('Delete-GitHubReaction')]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
|
||||
param(
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='ElementsIssue')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='ElementsPullRequest')]
|
||||
[string] $OwnerName,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='ElementsIssue')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='ElementsPullRequest')]
|
||||
[string] $RepositoryName,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='UriIssue')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='UriPullRequest')]
|
||||
[Alias('RepositoryUrl')]
|
||||
[string] $Uri,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='ElementsIssue')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='UriIssue',
|
||||
ValueFromPipelineByPropertyName)]
|
||||
[Alias('IssueNumber')]
|
||||
[int64] $Issue,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='ElementsPullRequest')]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ParameterSetName='UriPullRequest')]
|
||||
[Alias('PullRequestNumber')]
|
||||
[int64] $PullRequest,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipelineByPropertyName,
|
||||
ValueFromPipeline)]
|
||||
[int64] $ReactionId,
|
||||
|
||||
[Parameter()]
|
||||
[switch] $Force,
|
||||
|
||||
[string] $AccessToken,
|
||||
|
||||
[switch] $NoStatus
|
||||
)
|
||||
|
||||
Write-InvocationLog
|
||||
|
||||
$elements = Resolve-RepositoryElements
|
||||
$OwnerName = $elements.ownerName
|
||||
$RepositoryName = $elements.repositoryName
|
||||
|
||||
$telemetryProperties = @{
|
||||
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
|
||||
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
|
||||
}
|
||||
|
||||
if ($Issue)
|
||||
{
|
||||
$targetObjectNumber = $Issue
|
||||
$targetObjectTypeName = 'Issue'
|
||||
$uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions/$ReactionId"
|
||||
}
|
||||
else
|
||||
{
|
||||
# Pull request
|
||||
$targetObjectNumber = $PullRequest
|
||||
$targetObjectTypeName = 'Pull Request'
|
||||
$uriFragment = "/repos/$OwnerName/$RepositoryName/issues/$targetObjectNumber/reactions/$ReactionId"
|
||||
}
|
||||
|
||||
$description = "Removing reaction $ReactionId for $targetObjectTypeName $targetObjectNumber in $RepositoryName"
|
||||
|
||||
if ($Force -and (-not $Confirm))
|
||||
{
|
||||
$ConfirmPreference = 'None'
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess(
|
||||
$ReactionId,
|
||||
"Removing reaction for $targetObjectTypeName $targetObjectNumber in $RepositoryName"))
|
||||
{
|
||||
$params = @{
|
||||
'UriFragment' = $uriFragment
|
||||
'Description' = $description
|
||||
'Method' = 'Delete'
|
||||
'AcceptHeader' = $script:squirrelGirlAcceptHeader
|
||||
'AccessToken' = $AccessToken
|
||||
'TelemetryEventName' = $MyInvocation.MyCommand.Name
|
||||
'TelemetryProperties' = $telemetryProperties
|
||||
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
|
||||
}
|
||||
|
||||
return Invoke-GHRestMethod @params
|
||||
}
|
||||
}
|
||||
|
||||
filter Add-GitHubReactionAdditionalProperties
|
||||
{
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Adds type name and additional properties to ease pipelining to GitHub Reaction objects.
|
||||
|
||||
.PARAMETER InputObject
|
||||
The GitHub object to add additional properties to.
|
||||
|
||||
.PARAMETER TypeName
|
||||
The type that should be assigned to the object.
|
||||
|
||||
.PARAMETER OwnerName
|
||||
Owner of the repository.
|
||||
|
||||
.PARAMETER RepositoryName
|
||||
Name of the repository.
|
||||
|
||||
.PARAMETER Issue
|
||||
The issue number.
|
||||
|
||||
.PARAMETER PullRequest
|
||||
The pull request number.
|
||||
|
||||
.INPUTS
|
||||
[PSCustomObject]
|
||||
|
||||
.OUTPUTS
|
||||
GitHub.Reaction
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")]
|
||||
param(
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ValueFromPipeline)]
|
||||
[AllowNull()]
|
||||
[AllowEmptyCollection()]
|
||||
[PSCustomObject[]] $InputObject,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string] $TypeName = $script:GitHubReactionTypeName,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[string] $OwnerName,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[string] $RepositoryName,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='Issue')]
|
||||
[Alias('IssueNumber')]
|
||||
[int64] $Issue,
|
||||
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
ParameterSetName='PullRequest')]
|
||||
[Alias('PullRequestNumber')]
|
||||
[int64] $PullRequest
|
||||
)
|
||||
|
||||
foreach ($item in $InputObject)
|
||||
{
|
||||
$item.PSObject.TypeNames.Insert(0, $TypeName)
|
||||
|
||||
if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport))
|
||||
{
|
||||
$repositoryUrl = Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName
|
||||
Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force
|
||||
Add-Member -InputObject $item -Name 'ReactionId' -Value $item.id -MemberType NoteProperty -Force
|
||||
|
||||
if ($PullRequest)
|
||||
{
|
||||
Add-Member -InputObject $item -Name 'PullRequestNumber' -Value $PullRequest -MemberType NoteProperty -Force
|
||||
}
|
||||
else
|
||||
{
|
||||
# Issue
|
||||
Add-Member -InputObject $item -Name 'IssueNumber' -Value $Issue -MemberType NoteProperty -Force
|
||||
}
|
||||
|
||||
@('assignee', 'assignees', 'user') |
|
||||
ForEach-Object {
|
||||
if ($null -ne $item.$_)
|
||||
{
|
||||
$null = Add-GitHubUserAdditionalProperties -InputObject $item.$_
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Output $item
|
||||
}
|
||||
}
|
|
@ -65,6 +65,7 @@ filter Get-GitHubRelease
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -448,6 +448,7 @@ filter Remove-GitHubRepository
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -614,6 +615,7 @@ filter Get-GitHubRepository
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -938,6 +940,7 @@ filter Rename-GitHubRepository
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -1119,6 +1122,7 @@ filter Set-GitHubRepository
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -1303,6 +1307,7 @@ filter Get-GitHubRepositoryTopic
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -1418,6 +1423,7 @@ function Set-GitHubRepositoryTopic
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -1605,6 +1611,7 @@ filter Get-GitHubRepositoryContributor
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -1757,6 +1764,7 @@ filter Get-GitHubRepositoryCollaborator
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -1875,6 +1883,7 @@ filter Get-GitHubRepositoryLanguage
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -1983,6 +1992,7 @@ filter Get-GitHubRepositoryTag
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -2097,6 +2107,7 @@ filter Move-GitHubRepositoryOwnership
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ filter Get-GitHubRepositoryFork
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -167,6 +168,7 @@ filter New-GitHubRepositoryFork
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ filter Get-GitHubReferrerTraffic
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -169,6 +170,7 @@ filter Get-GitHubPathTraffic
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -289,6 +291,7 @@ filter Get-GitHubViewTraffic
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
@ -413,6 +416,7 @@ filter Get-GitHubCloneTraffic
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ filter Get-GitHubTeam
|
|||
GitHub.Project
|
||||
GitHub.ProjectCard
|
||||
GitHub.ProjectColumn
|
||||
GitHub.Reaction
|
||||
GitHub.Release
|
||||
GitHub.Repository
|
||||
GitHub.Team
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
'GitHubProjectCards.ps1',
|
||||
'GitHubProjectColumns.ps1',
|
||||
'GitHubPullRequests.ps1',
|
||||
'GitHubReactions.ps1',
|
||||
'GitHubReleases.ps1',
|
||||
'GitHubRepositories.ps1',
|
||||
'GitHubRepositoryForks.ps1',
|
||||
|
@ -85,6 +86,7 @@
|
|||
'Get-GitHubProjectColumn',
|
||||
'Get-GitHubPullRequest',
|
||||
'Get-GitHubRateLimit',
|
||||
'Get-GitHubReaction',
|
||||
'Get-GitHubReferrerTraffic',
|
||||
'Get-GitHubRelease',
|
||||
'Get-GitHubRepository',
|
||||
|
@ -131,6 +133,7 @@
|
|||
'Remove-GitHubProject',
|
||||
'Remove-GitHubProjectCard',
|
||||
'Remove-GitHubProjectColumn',
|
||||
'Remove-GitHubReaction',
|
||||
'Remove-GitHubRepository',
|
||||
'Remove-GitHubRepositoryBranch'
|
||||
'Rename-GitHubRepository',
|
||||
|
@ -148,7 +151,8 @@
|
|||
'Set-GitHubProject',
|
||||
'Set-GitHubProjectCard',
|
||||
'Set-GitHubProjectColumn',
|
||||
'Set-GitHubRepository'
|
||||
'Set-GitHubReaction',
|
||||
'Set-GitHubRepository',
|
||||
'Set-GitHubRepositoryTopic',
|
||||
'Split-GitHubUri',
|
||||
'Test-GitHubAssignee',
|
||||
|
@ -166,7 +170,8 @@
|
|||
'Delete-GitHubMilestone',
|
||||
'Delete-GitHubProject',
|
||||
'Delete-GitHubProjectCard',
|
||||
'Delete-GitHubProjectColumn'
|
||||
'Delete-GitHubProjectColumn',
|
||||
'Delete-GitHubReaction',
|
||||
'Delete-GitHubRepository',
|
||||
'Delete-GitHubRepositoryBranch',
|
||||
'Get-GitHubBranch',
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
<#
|
||||
.Synopsis
|
||||
Tests for GitHubReactions.ps1 module
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '',
|
||||
Justification='Suppress false positives in Pester code blocks')]
|
||||
param()
|
||||
|
||||
# This is common test code setup logic for all Pester test files
|
||||
$moduleRootPath = Split-Path -Path $PSScriptRoot -Parent
|
||||
. (Join-Path -Path $moduleRootPath -ChildPath 'Tests\Common.ps1')
|
||||
|
||||
try
|
||||
{
|
||||
# Define Script-scoped, readonly, hidden variables.
|
||||
@{
|
||||
defaultIssueTitle = "Test Title"
|
||||
defaultCommentBody = "This is a test body."
|
||||
defaultReactionType = "+1"
|
||||
otherReactionType = "eyes"
|
||||
}.GetEnumerator() | ForEach-Object {
|
||||
Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value
|
||||
}
|
||||
|
||||
Describe 'Creating, modifying and deleting reactions' {
|
||||
BeforeAll {
|
||||
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
|
||||
$issue = New-GitHubIssue -Uri $repo.svn_url -Title $defaultIssueTitle
|
||||
$issueComment = $issue | New-GitHubIssueComment -Body "Foo"
|
||||
}
|
||||
|
||||
Context 'For creating a reaction' {
|
||||
Set-GitHubReaction -Uri $repo.svn_url -Issue $issue.IssueNumber -ReactionType $defaultReactionType
|
||||
$existingReaction = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.IssueNumber
|
||||
|
||||
It "Should have the expected reaction type" {
|
||||
$existingReaction.content | Should -Be $defaultReactionType
|
||||
}
|
||||
}
|
||||
|
||||
Context 'For getting reactions from an issue' {
|
||||
Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.IssueNumber | Set-GitHubReaction -ReactionType $otherReactionType
|
||||
$allReactions = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.IssueNumber
|
||||
$specificReactions = Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.IssueNumber -ReactionType $otherReactionType
|
||||
|
||||
It 'Should have the expected number of reactions' {
|
||||
$allReactions.Count | Should -Be 2
|
||||
$specificReactions | Measure-Object | Select-Object -ExpandProperty Count | Should -Be 1
|
||||
}
|
||||
|
||||
It 'Should have the expected reaction content' {
|
||||
$specificReactions.content | Should -Be $otherReactionType
|
||||
$specificReactions.RepositoryUrl | Should -Be $repo.RepositoryUrl
|
||||
$specificReactions.IssueNumber | Should -Be $issue.IssueNumber
|
||||
$specificReactions.ReactionId | Should -Be $specificReactions.id
|
||||
$specificReactions.PSObject.TypeNames[0] | Should -Be 'GitHub.Reaction'
|
||||
}
|
||||
}
|
||||
|
||||
Context 'For getting reactions from a pull request' {
|
||||
# TODO: there are currently PRs out to add the ability to create new branches and add content to a repo.
|
||||
# When those go in, this test can be refactored to use those so the test is more reliable using a test PR.
|
||||
$url = 'https://github.com/microsoft/PowerShellForGitHub'
|
||||
$pr = Get-GitHubPullRequest -Uri $url -PullRequest 193
|
||||
|
||||
$allReactions = $pr | Get-GitHubReaction
|
||||
$specificReactions = $pr | Get-GitHubReaction -ReactionType $otherReactionType
|
||||
|
||||
It 'Should have the expected number of reactions' {
|
||||
$allReactions.Count | Should -Be 2
|
||||
$specificReactions | Measure-Object | Select-Object -ExpandProperty Count | Should -Be 1
|
||||
}
|
||||
|
||||
It 'Should have the expected reaction content' {
|
||||
$specificReactions.content | Should -Be $otherReactionType
|
||||
$specificReactions.RepositoryUrl | Should -Be $url
|
||||
$specificReactions.PullRequestNumber | Should -Be $pr.PullRequestNumber
|
||||
$specificReactions.ReactionId | Should -Be $specificReactions.id
|
||||
$specificReactions.PSObject.TypeNames[0] | Should -Be 'GitHub.Reaction'
|
||||
}
|
||||
}
|
||||
|
||||
Context 'For getting reactions from an Issue and deleting them' {
|
||||
$existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number)
|
||||
|
||||
It 'Should have the expected number of reactions' {
|
||||
$existingReactions.Count | Should -Be 2
|
||||
}
|
||||
|
||||
$existingReactions | Remove-GitHubReaction -Force
|
||||
|
||||
$existingReactions = @(Get-GitHubReaction -Uri $repo.svn_url -Issue $issue.number)
|
||||
|
||||
It 'Should have no reactions' {
|
||||
$existingReactions
|
||||
$existingReactions.Count | Should -Be 0
|
||||
}
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (Test-Path -Path $script:originalConfigFile -PathType Leaf)
|
||||
{
|
||||
# Restore the user's configuration to its pre-test state
|
||||
Restore-GitHubConfiguration -Path $script:originalConfigFile
|
||||
$script:originalConfigFile = $null
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче