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

feature/issue 314 - Ability to add worklog during issue transition #343

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
13 changes: 13 additions & 0 deletions 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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason why not to use [TimeSpan]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's much common practice to use in JQL things like 10m, 8h, 3w and people get used to it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also TimeSpan is more .NET solution rather than Powershell. It should be simple to use the Module

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well...
we already have the [TimeSpan] behavior in the module (for the worklog to be precise)

[Parameter( Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName )]
[TimeSpan]
$TimeSpent,

$TimeSpent,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
Expand Down Expand Up @@ -179,6 +182,16 @@ function Invoke-JiraIssueTransition {
}
}

if ($TimeSpent) {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Adding time spent"
$requestBody.update.worklog += , @{
'add' = @{
'timeSpent' = $TimeSpent
'started' = (Get-Date -f "yyyy-MM-ddThh:mm:ss.fffzz00") #should be ISO 8601: YYYY-MM-DDThh:mm:ss.sTZD, format -o not working, cause zzz contains semicolon
}
}
}

$parameter = @{
URI = "{0}/transitions" -f $issueObj.RestURL
Method = "POST"
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 a worklog if provide 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
30 changes: 24 additions & 6 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 -TimeSpent "15m" 'Transition comment'
```

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 worklog of 15m (you can use jira suffixes, e.g. 8h)
Requires the comment field to be configured visible for transition and Time Tracking to be enabled in JIRA instance

### EXAMPLE 3

Expand Down Expand Up @@ -176,6 +176,24 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -TimeSpent

Time Spent worklog should be added to issue

Time Tracking should be enabled on JIRA instance.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 6
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Credential

Credentials to use to connect to JIRA.
Expand All @@ -187,7 +205,7 @@ Parameter Sets: (All)
Aliases:

Required: False
Position: 6
Position: 7
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Expand All @@ -212,7 +230,7 @@ Accept wildcard characters: False
### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
For more information, see about_CommonParameters (<http://go.microsoft.com/fwlink/?LinkID=113216).>
alexsuslin marked this conversation as resolved.
Show resolved Hide resolved

## INPUTS

Expand Down