-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Implement removal of Jira issues via Remove-JiraIssue #265
Implement removal of Jira issues via Remove-JiraIssue #265
Conversation
I haven't yet implemented Pester tests for The Jira API includes a
Moreover,
I see there being three different options for handling this within JiraPS:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.) regarding your concern with sub-tasks:
The first suggestion of yours
Expose
deleteSubtasks
as a parameter (this is the current functionality) and simply percolate the API error back to the user if they try to delete an issue when it would be required otherwise.
IMHO it is the best suiting one for the module.
2.) About -Issue
I have some functions stashed which no longer take [Object]
as input for -Issue
.
This has the consequence of -Issue
always to depend on the output of Get-JiraIssue
.
But this will happen with the next major version anyway.
If you are interested in making this function only take [JiraPS.Issue]
as input, let me know and I will share the code.
--> this has the advantage of not needing Resolve-JiraIssue
and using
$parameter = @{
URI = $Issue.RestURL
Method = "DELETE"
Eg: https://github.com/AtlassianPS/JiraPS/pull/266/files#diff-eb644f77aa0b0f42e9317e245a236817
3.) About Pester Tests
This might be a good place to start:
https://github.com/AtlassianPS/JiraPS/pull/266/files#diff-bd4e363afdce9b0c34fac95d8fad0c8f
JiraPS/Public/Remove-JiraIssue.ps1
Outdated
} | ||
|
||
$parameter = @{ | ||
URI = $resourceURi -f $issueObj.Key,$IncludeSubTasks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this will work, as {1}
has to be a string true
or false
Did you test this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minimum reproducible test-case:
function Invoke-SwitchStringTest {
Param(
[switch]$TestSwitch
)
Process {
Return "Switch Output: {0}" -f $TestSwitch
}
}
Invoke-SwitchStringTest -TestSwitch
# Switch Output: True
Invoke-SwitchStringTest
# Switch Output: False
As the deleteSubTasks
param is passed on the query-string, it being a string vs. a bool shouldn't have much of a bearing (the value isn't being quoted or similar).
I have already tested the API accepting True
/False
instead of true
/false
using the Atlassian REST API Browser, and my initial testing with Remove-JiraIssue
itself seemed to indicate that the cmdlet functioned as expected.
JiraPS/Public/Remove-JiraIssue.ps1
Outdated
Credential = $Credential | ||
} | ||
|
||
$TargetText = "[$($issueObj.Key)] $($issueObj.Summary)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the same as $issueObj.ToString()
.
You could skip this variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I wasn't aware of that - I'll get rid of that momentarily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit 9d516c8 fixed this.
JiraPS/Public/Remove-JiraIssue.ps1
Outdated
[Switch] | ||
$IncludeSubTasks, | ||
|
||
[PSCredential] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a PR (#263) on develop
which will change the definition of -Credential
.
Please use the changed version, so that I don't have to merge again:
https://github.com/AtlassianPS/JiraPS/pull/263/files#diff-2ebb9ed7b267e9feab2af2ea05fd9422
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I should be able to rebase onto develop
so this is a non-issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've rebased onto develop
, which should automatically include #263. AFAIK [PSCredential]
should be analogous to [System.Management.Automation.PSCredential]
, but I also added [System.Management.Automation.CredentialAttribute()]
as well so strings are handled appropriately.
Module Name: JiraPS | ||
online version: | ||
schema: 2.0.0 | ||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing some metadata. Eg:
---
external help file: JiraPS-help.xml
Module Name: JiraPS
online version: https://atlassianps.org/docs/JiraPS/commands/Remove-JiraGroup/
locale: en-US
schema: 2.0.0
layout: documentation
permalink: /docs/JiraPS/commands/Remove-JiraGroup/
---
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay - I wasn't sure if the add'l data was added automatically. I'll get that put in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit 6450878 added the missing metadata.
Only call Get-JiraIssue when needed
1dc47aa
to
d687cff
Compare
@lipkau I'd like to see what you have available in this regard. As an alternative relying on specifically pipeline-based input, we may be able to leverage parameter sets to allow for string-based issue selection (i.e. |
JiraPS/Public/Remove-JiraIssue.ps1
Outdated
[ValidateScript( | ||
{ | ||
if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { | ||
$errorItem = [System.Management.Automation.ErrorRecord]::new( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unfortunatly not compatible with PSv3.
Please update it, as I did with the rest of the module:
https://github.com/AtlassianPS/JiraPS/pull/273/files#diff-762c92178567422918bfa5448fbb1e52R28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit 1627090 should have fixed this.
JiraPS/Public/Remove-JiraIssue.ps1
Outdated
|
||
[System.Management.Automation.CredentialAttribute()] | ||
[System.Management.Automation.PSCredential] | ||
$Credential, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For compatibility with PSv3 and v4, this requires a default value (because of [System.Management.Automation.CredentialAttribute()]
)
$Credential = [System.Management.Automation.PSCredential]::Empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been fixed in commit 639c608.
Tests/Remove-JiraIssue.Tests.ps1
Outdated
|
||
. "$PSScriptRoot/Shared.ps1" | ||
|
||
$script:ShowMockData = $true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this for the PR once you are done with debugging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! I completely forgot I'd left that in there. Commit 157dcd4 removed that line.
Tests/Remove-JiraIssue.Tests.ps1
Outdated
"errors": {} | ||
} | ||
"@ | ConvertFrom-Json | ||
Resolve-JiraError $MockedResponse -WriteError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are not supposed to use another function from the module in the UnitTests.
Please use Write-Error instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved with commit 575b888
Tests/Remove-JiraIssue.Tests.ps1
Outdated
Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly -Times 1 -Scope It | ||
} | ||
|
||
It "Throws on issues with subtasks" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it shouldn't throw.
IMHO it should be a non-terminating error.
as in:
Get-JiraIssue -Query "project= Foo" | Remove-JiraIssue -ErrorVariable $fails
I would expect the command to process all issues... (continuing if one fails)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right - normally, it would simply write a non-terminating error. However, it seems that Pester can't (directly) check if something wrote an error (at least according to pester/Pester#366) - the only options are to promote it to a terminating error using -ErrorAction Stop
or to use -ErrorVariable
and check its contents afterwards. I chose the former only because it seemed more concise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine. but the text of the It
block should describe what the function does. In this case, writes an error on issues with subtasks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was fixed in commit 2e86d9f.
About your comment: This is how I did it:
you can see in the rest of the function, the benefits of it. and yes: I am not opposed to having an additional parameter |
* Update Remove-JiraIssue to use [PSTypeName()]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent job! Thanks
### IMPROVEMENTS - Added support for paginated response from API server by means of `-Paging` (#291, [@lipkau[]]) - Added full set of functions to manage Filter Permissions (#289, [@lipkau[]]) - Added `-Id` parameter to `Remove-JiraFilter` (#288, [@lipkau[]]) - Changed logic of `Get-JiraUser` to return multiple results for a search (#272, [@lipkau[]]) - Added posts for homepage to the module's repository (#268, [@lipkau[]]) - Improved handling of _Credentials_ (#271, [@lipkau[]]) - Added missing interactions with _Filters_ (#266, [@lipkau[]]) - Added `Remove-JiraIssue` (#265, [@hmmwhatsthisdo[]]) - Improved Build script (to deploy changes to the homepage) (#259, [@lipkau[]]) ### BUG FIXES - Reverted `Add-JiraIssueAttachament` as JiraPS v2.7 broke it (#287, [@lipkau[]]) - Fixed resolving of Remote Link (#286, [@lipkau[]]) - Improved error handling for ErrorDetails and non-JSON/HTML responses (#277, [@hmmwhatsthisdo[]]) - Fully support Powershell v3 (#273, [@lipkau[]]) - Fixed parameter used in documentation but not in code (#263, [@lipkau[]])
### IMPROVEMENTS - Added support for paginated response from API server by means of `-Paging` (#291, [@lipkau[]]) - Added full set of functions to manage Filter Permissions (#289, [@lipkau[]]) - Added `-Id` parameter to `Remove-JiraFilter` (#288, [@lipkau[]]) - Changed logic of `Get-JiraUser` to return multiple results for a search (#272, [@lipkau[]]) - Added posts for homepage to the module's repository (#268, [@lipkau[]]) - Improved handling of _Credentials_ (#271, [@lipkau[]]) - Added missing interactions with _Filters_ (#266, [@lipkau[]]) - Added `Remove-JiraIssue` (#265, [@hmmwhatsthisdo[]]) - Improved Build script (to deploy changes to the homepage) (#259, [@lipkau[]]) ### BUG FIXES - Reverted `Add-JiraIssueAttachament` as JiraPS v2.7 broke it (#287, [@lipkau[]]) - Fixed resolving of Remote Link (#286, [@lipkau[]]) - Improved error handling for ErrorDetails and non-JSON/HTML responses (#277, [@hmmwhatsthisdo[]]) - Fully support Powershell v3 (#273, [@lipkau[]]) - Fixed parameter used in documentation but not in code (#263, [@lipkau[]])
Description
This PR adds
Remove-JiraIssue
, which willDELETE /api/2/issue/{issueIdOrKey}
to remove an issue from Jira.This PR resolves #264.
Types of changes
Checklist: