Skip to content
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

Add -AddComment to Set-JiraIssue #168

Merged
merged 5 commits into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions JiraPS/Public/Set-JiraIssue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions Tests/Set-JiraIssue.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ InModuleScope JiraPS {
defParam 'Description'
defParam 'Assignee'
defParam 'Label'
defParam 'AddComment'
defParam 'Fields'
defParam 'Credential'
defParam 'PassThru'
Expand Down Expand Up @@ -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] @{
Expand Down
8 changes: 8 additions & 0 deletions docs/updating_issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down