Skip to content

Commit

Permalink
ability to add time spent during issue transition AtlassianPS#314
Browse files Browse the repository at this point in the history
  • Loading branch information
AtlassianPS Automated User committed Mar 18, 2019
1 parent 947628c commit 6658dc0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
15 changes: 14 additions & 1 deletion JiraPS/Public/Invoke-JiraIssueTransition.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ function Invoke-JiraIssueTransition {
[String]
$Comment,

[String]
$TimeSpent,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
Expand Down Expand Up @@ -174,7 +177,17 @@ function Invoke-JiraIssueTransition {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Adding comment"
$requestBody.update.comment += , @{
'add' = @{
'body' = $Comment
'body' = $Comment
}
}
}

if($TimeSpent){
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Adding time spent"
$requestBody.update.worklog += , @{
'add' = @{
'timeSpent' = $TimeSpent
'started' = (Get-Date -Format O) # Round-trip date/time pattern '2019-03-18T17:59:38.0788189+03:00'
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/Functions/Invoke-JiraIssueTransition.Unit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ Describe "Invoke-JiraIssueTransition" -Tag 'Unit' {
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Times 1 -Scope It -ParameterFilter { $Method -eq 'Post' -and $URI -like "*/rest/api/latest/issue/$issueID/transitions" -and $Body -like '*body*test comment*' }
}

It "Adds time spent if provided to the -TimeSpent parameter" {
{ Invoke-JiraIssueTransition -Issue $issueKey -Transition 11 -TimeSpent "15m"} | Should Not Throw

Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Times 1 -Scope It -ParameterFilter { $Method -eq 'Post' -and $URI -like "*/rest/api/latest/issue/$issueID/transitions" -and $Body -like '*timeSpent*15m*' }
}

It "Returns the Issue object when -Passthru is provided" {
{ $result = Invoke-JiraIssueTransition -Issue $issueKey -Transition 11 -Passthru} | Should Not Throw
$result = Invoke-JiraIssueTransition -Issue $issueKey -Transition 11 -Passthru
Expand Down
8 changes: 4 additions & 4 deletions docs/en-US/commands/Invoke-JiraIssueTransition.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Performs an issue transition on a JIRA issue changing it's status

```powershell
Invoke-JiraIssueTransition [-Issue] <Object> [-Transition] <Object> [[-Fields] <PSCustomObject>]
[[-Assignee] <Object>] [[-Comment] <String>] [[-Credential] <PSCredential>] [-Passthru] [<CommonParameters>]
[[-Assignee] <Object>] [[-Comment] <String>] [[-TimeSpent] <String>] [[-Credential] <PSCredential>] [-Passthru] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -48,11 +48,11 @@ Invokes transition ID 11 on issue TEST-01.
### EXAMPLE 2

```powershell
Invoke-JiraIssueTransition -Issue TEST-01 -Transition 11 -Comment 'Transition comment'
Invoke-JiraIssueTransition -Issue TEST-01 -Transition 11 -Comment 'Transition comment' -TimeSpent "15m"
```

Invokes transition ID 11 on issue TEST-01 with a comment.
Requires the comment field to be configured visible for transition.
Invokes transition ID 11 on issue TEST-01 with a comment and time spent of 15m (can be any jira supported suffix, like 'h' for hours e.g.)
Requires the comment field to be configured visible for transition and time tracking enabled in JIRA preferences.

### EXAMPLE 3

Expand Down

0 comments on commit 6658dc0

Please sign in to comment.