public/api-v2/comment/Invoke-JiraGetComments.ps1
$JiraCommentExpand = @("renderedBody") #https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-comment-get function Invoke-JiraGetComments { [CmdletBinding(DefaultParameterSetName="Id")] param ( # The ID of the issue [Parameter(Mandatory,Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName,ParameterSetName="Id")] [int32] $Id, # The key of the issue [Parameter(Mandatory,Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName,ParameterSetName="Key")] [string] $Key, # The index of the first item to return in the page of results (page offset). The base index is 0. [Parameter(Position=1)] [int32] $StartAt=0, # The maximum number of items to return per page. The default is 100 and the maximum is 100. [Parameter(Position=2)] [ValidateRange(1,100)] [int32] $MaxResults=50, # How to order the results [Parameter(Position=3)] [ValidateSet("created","-created")] [string] $OrderBy, # Used to expand additional attributes [Parameter(Position=4)] [ValidateScript({ Compare-StringArraySubset $JiraCommentExpand $_ })] [string[]] $Expand, # The JiraContext object to use for the request [Parameter()] [JiraContext] $JiraContext ) begin { $results = @() } process { $issueToken = IIF ($PSCmdlet.ParameterSetName -eq "Id") $Id $Key $functionPath = "/rest/api/2/issue/$issueToken/comment" $verb = "GET" $query = New-Object RestMethodQueryParams @{ startAt = $StartAt maxResults = $MaxResults } if($PSBoundParameters.ContainsKey("OrderBy")){$query.Add("orderBy",$OrderBy)} if($PSBoundParameters.ContainsKey("Expand")){$query.Add("expand",$Expand -join ",")} $method = New-Object RestMethod @($functionPath,$verb,$query) $return = $method.Invoke($JiraContext) if ($PSCmdlet.ParameterSetName -eq "Id") { $return.comments | Add-Member "IssueId" $Id } else { $return.comments | Add-Member "IssueKey" $Key } $results += $return.comments } end { $results } } |