diff --git a/JiraPS/Public/New-JiraIssue.ps1 b/JiraPS/Public/New-JiraIssue.ps1 index 717b6e07..0efe10b5 100644 --- a/JiraPS/Public/New-JiraIssue.ps1 +++ b/JiraPS/Public/New-JiraIssue.ps1 @@ -2,39 +2,46 @@ function New-JiraIssue { # .ExternalHelp ..\JiraPS-help.xml [CmdletBinding( SupportsShouldProcess )] param( - [Parameter( Mandatory )] + [Parameter( Mandatory, ValueFromPipelineByPropertyName )] [String] $Project, - [Parameter( Mandatory )] + [Parameter( Mandatory, ValueFromPipelineByPropertyName )] [String] $IssueType, - [Parameter( Mandatory )] + [Parameter( Mandatory, ValueFromPipelineByPropertyName )] [String] $Summary, + [Parameter( ValueFromPipelineByPropertyName )] [Int] $Priority, + [Parameter( ValueFromPipelineByPropertyName )] [String] $Description, + [Parameter( ValueFromPipelineByPropertyName )] [AllowNull()] [AllowEmptyString()] [String] $Reporter, + [Parameter( ValueFromPipelineByPropertyName )] [String[]] $Labels, + [Parameter( ValueFromPipelineByPropertyName )] [String] $Parent, + [Parameter( ValueFromPipelineByPropertyName )] [Alias('FixVersions')] [String[]] $FixVersion, + [Parameter( ValueFromPipelineByPropertyName )] [PSCustomObject] $Fields, @@ -46,15 +53,15 @@ function New-JiraIssue { begin { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" + } + process { $server = Get-JiraConfigServer -ErrorAction Stop -Debug:$false $createmeta = Get-JiraIssueCreateMetadata -Project $Project -IssueType $IssueType -Credential $Credential -ErrorAction Stop -Debug:$false $resourceURi = "$server/rest/api/latest/issue" - } - process { Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)" Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" @@ -161,9 +168,9 @@ function New-JiraIssue { # This will fetch the created issue to return it with all it'a properties Write-Output (Get-JiraIssue -Key $result.Key -Credential $Credential) } + Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete" } end { - Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete" } } diff --git a/Tests/New-JiraIssue.Tests.ps1 b/Tests/New-JiraIssue.Tests.ps1 index 93acf18f..d0df80a2 100644 --- a/Tests/New-JiraIssue.Tests.ps1 +++ b/Tests/New-JiraIssue.Tests.ps1 @@ -80,6 +80,8 @@ 'Description' = 'Test description'; } + $pipelineParams = New-Object -TypeName PSCustomObject -Property $newParams + Context "Sanity checking" { $command = Get-Command -Name New-JiraIssue @@ -102,6 +104,13 @@ # including the summary provided in the test call above. Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Times 1 -Scope It -ParameterFilter { $Method -eq 'Post' -and $URI -like "$jiraServer/rest/api/*/issue" } } + It "Creates an issue in JIRA from pipeline" { + { $pipelineParams | New-JiraIssue } | Should Not Throw + # The String in the ParameterFilter is made from the keywords + # we should expect to see in the JSON that should be sent, + # including the summary provided in the test call above. + Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Times 1 -Scope It -ParameterFilter { $Method -eq 'Post' -and $URI -like "$jiraServer/rest/api/*/issue" } + } } Context "Input testing" { diff --git a/docs/en-US/commands/New-JiraIssue.md b/docs/en-US/commands/New-JiraIssue.md index 264fb4e6..775e880e 100644 --- a/docs/en-US/commands/New-JiraIssue.md +++ b/docs/en-US/commands/New-JiraIssue.md @@ -82,6 +82,16 @@ This illustrates how to use splatting for the example above. Read more about splatting: about_Splatting +### EXAMPLE 4 + +```powershell +"project,summary,assignee,IssueType,Priority,Description" > "./data.csv" +"CS,Some Title 1,admin,Minor,1,Some Description 1" >> "./data.csv" +"CS,Some Title 2,admin,Minor,1,Some Description 2" >> "./data.csv" +import-csv "./data.csv" | New-JiraIssue +``` +This example illuetrates how to prepare multiple new stories and pipe them to be created all at once. + ## PARAMETERS ### -Project