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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0d2bbc1
Initial implementation of Remove-JiraIssue w/ documentation
hmmwhatsthisdo May 25, 2018
750cd9f
Make Remove-JiraIssue "Object" param positional;
hmmwhatsthisdo May 26, 2018
2116117
Use $issueObj (with implied .ToString()) in $PSCmdlet.ShouldProcess()
hmmwhatsthisdo May 29, 2018
4e71efa
Add additional information to Remove-JiraIssue doc frontmatter
hmmwhatsthisdo May 29, 2018
2b5215a
Add alias on -IncludeSubTasks to match Jira API terminology
hmmwhatsthisdo May 29, 2018
d687cff
Forced explicit .ToString on $PSCmdlet.ShouldProcess()
hmmwhatsthisdo May 29, 2018
cea2e6d
Updated -Credential parameter declaration on Remove-JiraIssue
hmmwhatsthisdo May 29, 2018
a8d2165
Fix incorrect variable usage in Remove-JiraIssue foreach loop
hmmwhatsthisdo May 30, 2018
8f1f41e
Add Pester tests for Remove-JiraIssue 🎉
hmmwhatsthisdo May 30, 2018
3bce99e
Merge branch 'develop' into Remove-JiraIssue_264
lipkau May 31, 2018
639c608
Add default value for -Credential
hmmwhatsthisdo May 31, 2018
157dcd4
Remove debugging lines from Remove-JiraIssue tests
hmmwhatsthisdo May 31, 2018
1627090
Change parameter validation to accommodate PSv3
hmmwhatsthisdo May 31, 2018
575b888
Remove unit test dependency on Resolve-JiraError
hmmwhatsthisdo May 31, 2018
ab53595
Merge branch 'develop' into Remove-JiraIssue_264
lipkau Jun 1, 2018
048ecf8
Merge branch 'develop' into Remove-JiraIssue_264
lipkau Jun 2, 2018
e749422
Add -Cmdlet param to Invoke-JiraMethod inside Remove-JiraIssue
hmmwhatsthisdo Jun 4, 2018
2e86d9f
Fix ambiguous test description (with clarifying comments)
hmmwhatsthisdo Jun 4, 2018
9a6825d
* Add separate string-based ParamSet to Remove-JiraIssue
hmmwhatsthisdo Jun 4, 2018
b3d1ab1
Fix inconsistencies in documentation/sanity-check tests
hmmwhatsthisdo Jun 4, 2018
167a1ed
Fix broken tests
hmmwhatsthisdo Jun 4, 2018
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
116 changes: 116 additions & 0 deletions JiraPS/Public/Remove-JiraIssue.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
function Remove-JiraIssue {
[CmdletBinding(
ConfirmImpact = 'High',
SupportsShouldProcess,
DefaultParameterSetName = "ByInputObject"
)]
param (
[Parameter(
Mandatory,
ValueFromPipeline,
Position = 0,
ParameterSetName = "ByInputObject"
)]
[Alias(
"Issue"
)]
[PSTypeName("JiraPS.Issue")]
[Object[]]
$InputObject,

# The issue's ID number or key.
[Parameter(
Mandatory,
Position = 0,
ParameterSetName = "ByIssueId"
)]
[ValidateNotNullOrEmpty()]
[Alias(
"Id",
"Key",
"issueIdOrKey"
)]
[String[]]
$IssueId,

[Switch]
[Alias("deleteSubtasks")]
$IncludeSubTasks,

[System.Management.Automation.CredentialAttribute()]
[System.Management.Automation.PSCredential]
$Credential = [System.Management.Automation.PSCredential]::Empty,

[Switch]
$Force
)

begin {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"

$server = Get-JiraConfigServer -ErrorAction Stop

$resourceURi = "$server/rest/api/latest/issue/{0}?deleteSubtasks={1}"

if ($Force) {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] -Force was passed. Backing up current ConfirmPreference [$ConfirmPreference] and setting to None"
$oldConfirmPreference = $ConfirmPreference
$ConfirmPreference = 'None'
}
}

process {

Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)"
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)"

switch ($PsCmdlet.ParameterSetName) {
"ByInputObject" { $PrimaryIterator = $InputObject }
"ByIssueId" { $PrimaryIterator = $IssueID }
}

foreach ($issueItem in $PrimaryIterator) {

if ($PsCmdlet.ParameterSetName -eq "ByIssueId") {
$_issue = Get-JiraIssue -Key $issueItem -Credential $Credential -ErrorAction Stop
} Else {
$_issue = $issueItem
}

Write-Verbose "[$($MyInvocation.MyCommand.Name)] Processing [$_issue]"
Write-Debug "[$($MyInvocation.MyCommand.Name)] Processing `$issueItem [$_issue]"



$parameter = @{
URI = $resourceURi -f $_issue.Key,$IncludeSubTasks
Method = "DELETE"
Credential = $Credential
Cmdlet = $PsCmdlet
}


If ($IncludeSubTasks) {
$ActionText = "Remove issue and sub-tasks"
} Else {
$ActionText = "Remove issue"
}

if ($PSCmdlet.ShouldProcess($_issue.ToString(), $ActionText)) {

Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter"
Invoke-JiraMethod @parameter
}
}

}

end {
if ($Force) {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Restoring ConfirmPreference to [$oldConfirmPreference]"
$ConfirmPreference = $oldConfirmPreference
}

Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete"
}
}
Loading