diff --git a/JiraPS/Public/Set-JiraIssue.ps1 b/JiraPS/Public/Set-JiraIssue.ps1 index 402e30ab..b59e8606 100644 --- a/JiraPS/Public/Set-JiraIssue.ps1 +++ b/JiraPS/Public/Set-JiraIssue.ps1 @@ -16,6 +16,9 @@ function Set-JiraIssue { .EXAMPLE Set-JiraIssue -Issue TEST-01 -Assignee 'Unassigned' This example removes the assignee from JIRA issue TEST-01. + .EXAMPLE + Set-JiraIssue -Issue TEST-01 -Assignee 'joe' -AddComment 'Dear [~joe], please review.' + This example assigns the JIRA Issue TEST-01 to 'joe' and adds a comment at one. .INPUTS [JiraPS.Issue[]] The JIRA issue that should be modified .OUTPUTS @@ -61,6 +64,10 @@ function Set-JiraIssue { # Any additional fields that should be updated. [System.Collections.Hashtable] $Fields, + # Add a comment ad once with your changes + [Parameter(Mandatory = $false)] + [String] $AddComment, + # Path of the file where the configuration is stored. [ValidateScript( {Test-Path $_})] [String] $ConfigFile, @@ -151,6 +158,16 @@ function Set-JiraIssue { $actOnIssueUri = $true } + if ($AddComment) { + $issueProps.update.comment = @() + $issueProps.update.comment += @{ + 'add' = @{ + 'body' = $AddComment + } + } + $actOnIssueUri = $true + } + if ($Fields) { Write-Debug "[Set-JiraIssue] Validating field names" foreach ($k in $Fields.Keys) { diff --git a/Tests/Set-JiraIssue.Tests.ps1 b/Tests/Set-JiraIssue.Tests.ps1 index 924c10db..b67a07b1 100644 --- a/Tests/Set-JiraIssue.Tests.ps1 +++ b/Tests/Set-JiraIssue.Tests.ps1 @@ -41,6 +41,7 @@ InModuleScope JiraPS { defParam 'Description' defParam 'Assignee' defParam 'Label' + defParam 'AddComment' defParam 'Fields' defParam 'Credential' defParam 'PassThru' @@ -102,6 +103,11 @@ InModuleScope JiraPS { Assert-MockCalled -CommandName Set-JiraIssueLabel -ModuleName JiraPS -Times 1 -Scope It -ParameterFilter { $Set -ne $null } } + It "Adds a comment if the -AddComemnt parameter is passed" { + { Set-JiraIssue -Issue TEST-001 -AddComment 'New Comment' } | Should Not Throw + Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Times 1 -Scope It -ParameterFilter { $Method -eq 'Put' -and $Uri -like '*/rest/api/2/issue/12345' -and $Body -like '*comment*add*body*New Comment*' } + } + It "Updates custom fields if provided to the -Fields parameter" { Mock Get-JiraField { [PSCustomObject] @{ diff --git a/docs/updating_issues.rst b/docs/updating_issues.rst index 38b017a0..df9a94d2 100644 --- a/docs/updating_issues.rst +++ b/docs/updating_issues.rst @@ -22,6 +22,9 @@ Editing issues is done with the Set-JiraIssue function. $issue = Get-JiraIssue TEST-1 $issue | Set-JiraIssue -Summary "$($issue.Summary) (Modified by PowerShell)" + # Change the issue's summary and add a comment for that change + $issue | Set-JiraIssue -Summary "New Summary" -AddComment "Changed summary for testing" + If the field you want to change does not have a named parameter, Set-JiraIssue also supports changing arbitrary fields using the -Fields parameter. For more information on this parameter, see the :doc:`custom_fields` page. Labels @@ -76,6 +79,11 @@ You can also use Format-Jira to convert a PowerShell object into a JIRA table. .. note:: Like other Format-* commands, Format-Jira is a destructive operation for data in the pipeline. Remember to "filter left, format right!" +Comments can also be added while changing other fields of issues, e.g. the assignee: + +.. code:: PowerShell + Set-JiraIssue -Issue TEST-1 -Assignee "John" -Addcomment "Dear mr. Doe, please review this issue.Thx" + .. _Issue Transitions: Issue Transitions