diff --git a/GitHubComments.ps1 b/GitHubComments.ps1 index 41d9bb66..a432e55f 100644 --- a/GitHubComments.ps1 +++ b/GitHubComments.ps1 @@ -40,10 +40,10 @@ function Get-GitHubComment .PARAMETER MediaType The format in which the API will return the body of the comment. - raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. - text - Return a text only representation of the markdown body. Response will include body_text. - html - Return HTML rendered from the body's markdown. Response will include body_html. - full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. + Raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. + Text - Return a text only representation of the markdown body. Response will include body_text. + Html - Return HTML rendered from the body's markdown. Response will include body_html. + Full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the @@ -181,7 +181,7 @@ function Get-GitHubComment 'UriFragment' = $uriFragment 'Description' = $description 'AccessToken' = $AccessToken - 'AcceptHeader' = (Get-CommentAcceptHeader -MediaType $MediaType) + 'AcceptHeader' = (Get-MediaAcceptHeader -MediaType $MediaType -AcceptHeader $squirrelAcceptHeader) 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) @@ -220,10 +220,10 @@ function New-GitHubComment .PARAMETER MediaType The format in which the API will return the body of the comment. - raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. - text - Return a text only representation of the markdown body. Response will include body_text. - html - Return HTML rendered from the body's markdown. Response will include body_html. - full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. + Raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. + Text - Return a text only representation of the markdown body. Response will include body_text. + Html - Return HTML rendered from the body's markdown. Response will include body_html. + Full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the @@ -292,7 +292,7 @@ function New-GitHubComment 'Method' = 'Post' 'Description' = "Creating comment under issue $Issue for $RepositoryName" 'AccessToken' = $AccessToken - 'AcceptHeader' = (Get-CommentAcceptHeader -MediaType $MediaType) + 'AcceptHeader' = (Get-MediaAcceptHeader -MediaType $MediaType -AcceptHeader $squirrelAcceptHeader) 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) @@ -331,10 +331,10 @@ function Set-GitHubComment .PARAMETER MediaType The format in which the API will return the body of the comment. - raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. - text - Return a text only representation of the markdown body. Response will include body_text. - html - Return HTML rendered from the body's markdown. Response will include body_html. - full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. + Raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. + Text - Return a text only representation of the markdown body. Response will include body_text. + Html - Return HTML rendered from the body's markdown. Response will include body_html. + Full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. .PARAMETER AccessToken If provided, this will be used as the AccessToken for authentication with the @@ -403,7 +403,7 @@ function Set-GitHubComment 'Method' = 'Patch' 'Description' = "Update comment $CommentID for $RepositoryName" 'AccessToken' = $AccessToken - 'AcceptHeader' = (Get-CommentAcceptHeader -MediaType $MediaType) + 'AcceptHeader' = (Get-MediaAcceptHeader -MediaType $MediaType -AcceptHeader $squirrelAcceptHeader) 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) @@ -501,36 +501,3 @@ function Remove-GitHubComment return Invoke-GHRestMethod @params } -function Get-CommentAcceptHeader -{ -<# - .DESCRIPTION - Returns a formatted AcceptHeader based on the requested MediaType - - The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub - - .PARAMETER MediaType - The format in which the API will return the body of the comment. - - raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. - text - Return a text only representation of the markdown body. Response will include body_text. - html - Return HTML rendered from the body's markdown. Response will include body_html. - full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. - - .EXAMPLE - Get-CommentAcceptHeader -MediaType Raw - - Returns a formatted AcceptHeader for v3 of the response object -#> - [CmdletBinding()] - param( - [ValidateSet('Raw', 'Text', 'Html', 'Full')] - [string] $MediaType ='Raw' - ) - - $acceptHeaders = @( - 'application/vnd.github.squirrel-girl-preview', - "application/vnd.github.$mediaTypeVersion.$($MediaType.ToLower())+json") - - return ($acceptHeaders -join ',') -} diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 8919891d..f1db8048 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -7,6 +7,8 @@ gitHubApiOrgsUrl = 'https://api.github.com/orgs' defaultAcceptHeader = 'application/vnd.github.v3+json' mediaTypeVersion = 'v3' + squirrelAcceptHeader = 'application/vnd.github.squirrel-girl-preview' + symmetraAcceptHeader = 'application/vnd.github.symmetra-preview+json' }.GetEnumerator() | ForEach-Object { Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value @@ -922,3 +924,44 @@ filter ConvertTo-SmarterObject Write-Output -InputObject $InputObject } } + +function Get-MediaAcceptHeader +{ +<# + .DESCRIPTION + Returns a formatted AcceptHeader based on the requested MediaType + + The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub + + .PARAMETER MediaType + The format in which the API will return the body of the comment or issue. + + Raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. + Text - Return a text only representation of the markdown body. Response will include body_text. + Html - Return HTML rendered from the body's markdown. Response will include body_html. + Full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. + + .PARAMETER AcceptHeader + The accept header that should be included with the MediaType accept header. + + .EXAMPLE + Get-MediaAcceptHeader -MediaType Raw + + Returns a formatted AcceptHeader for v3 of the response object +#> + [CmdletBinding()] + param( + [ValidateSet('Raw', 'Text', 'Html', 'Full')] + [string] $MediaType = 'Raw', + + [Parameter(Mandatory)] + [string] $AcceptHeader + ) + + $acceptHeaders = @( + $AcceptHeader, + "application/vnd.github.$mediaTypeVersion.$($MediaType.ToLower())+json") + + return ($acceptHeaders -join ',') +} + diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index dc46e46e..87383f8e 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -87,6 +87,14 @@ function Get-GitHubIssue .PARAMETER Mentioned Only issues that mention this specified user will be returned. + .PARAMETER MediaType + The format in which the API will return the body of the issue. + + Raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. + Text - Return a text only representation of the markdown body. Response will include body_text. + Html - Return HTML rendered from the body's markdown. Response will include body_html. + Full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. + .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. @@ -162,6 +170,9 @@ function Get-GitHubIssue [string] $Mentioned, + [ValidateSet('Raw', 'Text', 'Html', 'Full')] + [string] $MediaType ='Raw', + [string] $AccessToken, [switch] $NoStatus @@ -304,7 +315,7 @@ function Get-GitHubIssue $params = @{ 'UriFragment' = $uriFragment + '?' + ($getParams -join '&') 'Description' = $description - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'AcceptHeader' = (Get-MediaAcceptHeader -MediaType $MediaType -AcceptHeader $symmetraAcceptHeader) 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -450,6 +461,14 @@ function New-GitHubIssue .PARAMETER Label Label(s) to associate with this issue. + .PARAMETER MediaType + The format in which the API will return the body of the issue. + + Raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. + Text - Return a text only representation of the markdown body. Response will include body_text. + Html - Return HTML rendered from the body's markdown. Response will include body_html. + Full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. + .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. @@ -491,6 +510,9 @@ function New-GitHubIssue [string[]] $Label, + [ValidateSet('Raw', 'Text', 'Html', 'Full')] + [string] $MediaType ='Raw', + [string] $AccessToken, [switch] $NoStatus @@ -521,7 +543,7 @@ function New-GitHubIssue 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Post' 'Description' = "Creating new Issue ""$Title"" on $RepositoryName" - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'AcceptHeader' = (Get-MediaAcceptHeader -MediaType $MediaType -AcceptHeader $symmetraAcceptHeader) 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -579,6 +601,14 @@ function Update-GitHubIssue .PARAMETER State Modify the current state of the issue. + .PARAMETER MediaType + The format in which the API will return the body of the issue. + + Raw - Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type. + Text - Return a text only representation of the markdown body. Response will include body_text. + Html - Return HTML rendered from the body's markdown. Response will include body_html. + Full - Return raw, text and HTML representations. Response will include body, body_text, and body_html. + .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. @@ -624,6 +654,9 @@ function Update-GitHubIssue [ValidateSet('Open', 'Closed')] [string] $State, + [ValidateSet('Raw', 'Text', 'Html', 'Full')] + [string] $MediaType ='Raw', + [string] $AccessToken, [switch] $NoStatus @@ -661,7 +694,7 @@ function Update-GitHubIssue 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Patch' 'Description' = "Updating Issue #$Issue on $RepositoryName" - 'AcceptHeader' = 'application/vnd.github.symmetra-preview+json' + 'AcceptHeader' = (Get-MediaAcceptHeader -MediaType $MediaType -AcceptHeader $symmetraAcceptHeader) 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties diff --git a/Tests/GitHubAnalytics.tests.ps1 b/Tests/GitHubAnalytics.tests.ps1 index a00f9ecc..bb6b7c1b 100644 --- a/Tests/GitHubAnalytics.tests.ps1 +++ b/Tests/GitHubAnalytics.tests.ps1 @@ -126,6 +126,15 @@ try } } + Context 'When issues are retrieved with a specific MediaTypes' { + $newIssue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid()) -Body ([guid]::NewGuid()) + + $issues = @(Get-GitHubIssue -Uri $repo.svn_url -Issue $newIssue.number -MediaType 'Html') + It 'Should return an issue with body_html' { + $issues[0].body_html | Should not be $null + } + } + $null = Remove-GitHubRepository -Uri ($repo.svn_url) } diff --git a/Tests/GitHubComments.tests.ps1 b/Tests/GitHubComments.tests.ps1 index 1461bcec..0611a12c 100644 --- a/Tests/GitHubComments.tests.ps1 +++ b/Tests/GitHubComments.tests.ps1 @@ -113,6 +113,14 @@ try } } + Context 'For getting comments from an issue with a specific MediaType' { + $existingComments = @(Get-GitHubComment -Uri $repo.svn_url -Issue $issue.number -MediaType 'Html') + + It 'Should have the expected body_html on the first comment' { + $existingComments[0].body_html | Should not be $null + } + } + Context 'For editing a comment' { $newComment = New-GitHubComment -Uri $repo.svn_url -Issue $issue.number -Body $defaultCommentBody $editedComment = Set-GitHubComment -Uri $repo.svn_url -CommentID $newComment.id -Body $defaultEditedCommentBody