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

Implement removal of Jira issues via Remove-JiraIssue #265

Merged
merged 21 commits into from
Jun 5, 2018

Conversation

hmmwhatsthisdo
Copy link
Contributor

@hmmwhatsthisdo hmmwhatsthisdo commented May 25, 2018

Description

This PR adds Remove-JiraIssue, which will DELETE /api/2/issue/{issueIdOrKey} to remove an issue from Jira.

This PR resolves #264.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • I have added Pester Tests that describe what my changes should do.
  • I have updated the documentation accordingly.

@hmmwhatsthisdo hmmwhatsthisdo requested review from a team as code owners May 25, 2018 22:05
@ghost ghost added the Status:In Review label May 25, 2018
@hmmwhatsthisdo
Copy link
Contributor Author

hmmwhatsthisdo commented May 25, 2018

I haven't yet implemented Pester tests for Remove-JiraUser as I wanted to gather feedback on what to do in the event an issue with sub-tasks is removed.

The Jira API includes a deleteSubtasks parameter on DELETE /api/2/issue/{issueIdOrKey}. According to the API documentation:

If the issue has subtasks you must set the parameter deleteSubtasks=true to delete the issue. You cannot delete an issue without its subtasks also being deleted.

Moreover, deleteSubtasks has no effect if the issue doesn't have subtasks:

If the issue has no subtasks this parameter is ignored. If the issue has subtasks and this parameter is missing or false, then the issue will not be deleted and an error will be returned.

I see there being three different options for handling this within JiraPS:

  • 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.
  • Always set deleteSubtasks to true. (This feels dangerous.)
  • Retrieve tasks (if passed by ID/Key/etc.) and check if the subtasks property is non-empty, then warn the user (possibly using $PSCmdlet.ShouldContinue() and act accordingly.

Copy link
Member

@lipkau lipkau left a 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

}

$parameter = @{
URI = $resourceURi -f $issueObj.Key,$IncludeSubTasks
Copy link
Member

@lipkau lipkau May 26, 2018

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?

Copy link
Contributor Author

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.

Credential = $Credential
}

$TargetText = "[$($issueObj.Key)] $($issueObj.Summary)"
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Commit 9d516c8 fixed this.

[Switch]
$IncludeSubTasks,

[PSCredential]
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

@hmmwhatsthisdo hmmwhatsthisdo May 29, 2018

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
---
Copy link
Member

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/
---

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@lipkau lipkau added this to the v2.8 milestone May 26, 2018
@hmmwhatsthisdo
Copy link
Contributor Author

hmmwhatsthisdo commented May 29, 2018

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.

@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. -Issue vs. -IssueId/IssueKey).

[ValidateScript(
{
if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) {
$errorItem = [System.Management.Automation.ErrorRecord]::new(
Copy link
Member

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

Copy link
Contributor Author

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.


[System.Management.Automation.CredentialAttribute()]
[System.Management.Automation.PSCredential]
$Credential,
Copy link
Member

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

Copy link
Contributor Author

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.


. "$PSScriptRoot/Shared.ps1"

$script:ShowMockData = $true
Copy link
Member

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

Copy link
Contributor Author

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.

"errors": {}
}
"@ | ConvertFrom-Json
Resolve-JiraError $MockedResponse -WriteError
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved with commit 575b888

Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly -Times 1 -Scope It
}

It "Throws on issues with subtasks" {
Copy link
Member

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)

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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.

@lipkau
Copy link
Member

lipkau commented May 31, 2018

About your comment:

This is how I did it:

[PSTypeName('JiraPS.Filter')]

you can see in the rest of the function, the benefits of it.

and yes: I am not opposed to having an additional parameter -Id or similar.
At least for now... I need to do some thinking on this

Copy link
Member

@lipkau lipkau left a comment

Choose a reason for hiding this comment

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

Excellent job! Thanks

@lipkau lipkau merged commit 538c221 into AtlassianPS:develop Jun 5, 2018
@ghost ghost removed the Status:In Review label Jun 5, 2018
@hmmwhatsthisdo hmmwhatsthisdo deleted the Remove-JiraIssue_264 branch June 5, 2018 17:32
@lipkau lipkau mentioned this pull request Jun 28, 2018
lipkau added a commit that referenced this pull request Jun 28, 2018
### 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[]])
lipkau added a commit that referenced this pull request Jun 29, 2018
### 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[]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants