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

Fix issue 229 - New-JiraIssue should take params from pipeline. #312

Merged
merged 3 commits into from
Sep 21, 2018
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
19 changes: 13 additions & 6 deletions JiraPS/Public/New-JiraIssue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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)"

Expand Down Expand Up @@ -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"
}
}
9 changes: 9 additions & 0 deletions Tests/New-JiraIssue.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
'Description' = 'Test description';
}

$pipelineParams = New-Object -TypeName PSCustomObject -Property $newParams

Context "Sanity checking" {
$command = Get-Command -Name New-JiraIssue

Expand All @@ -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" {
Expand Down
10 changes: 10 additions & 0 deletions docs/en-US/commands/New-JiraIssue.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down