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: Improve Filter functions #266

Merged
merged 10 commits into from
May 27, 2018
16 changes: 16 additions & 0 deletions JiraPS/Public/Get-JiraFilter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
[Object[]]
$InputObject,

[Parameter( Mandatory, ParameterSetName = 'MyFavorite' )]
[Alias('Favourite')]
[Switch]
$Favorite,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
Expand Down Expand Up @@ -88,6 +93,17 @@
Write-Output (Get-JiraFilter -Id $thisId -Credential $Credential)
}
}
"MyFavorite" {
$parameter = @{
URI = $resourceURi -f "favourite"
Method = "GET"
Credential = $Credential
}
Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter"
$result = Invoke-JiraMethod @parameter

Write-Output (ConvertTo-JiraFilter -InputObject $result)
}
}
}

Expand Down
67 changes: 67 additions & 0 deletions JiraPS/Public/New-JiraFilter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
function New-JiraFilter {
[CmdletBinding( SupportsShouldProcess )]
param(
[Parameter( Mandatory, ValueFromPipelineByPropertyName )]
[ValidateNotNullOrEmpty()]
[String]
$Name,

[Parameter( ValueFromPipelineByPropertyName )]
[String]
$Description,

[Parameter( Mandatory, ValueFromPipelineByPropertyName )]
[ValidateNotNullOrEmpty()]
[String]
$JQL,

[Parameter( ValueFromPipelineByPropertyName )]
[Alias('Favourite')]
[Switch]
$Favorite,

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

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

$server = Get-JiraConfigServer -ErrorAction Stop

$resourceURi = "$server/rest/api/latest/filter"
}

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

$requestBody = @{
Name = $Name
JQL = $JQL
}
if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Description")) {
$requestBody["description"] = $Description
}
$requestBody["favourite"] = [Bool]$Favorite

$parameter = @{
URI = $resourceURi
Method = "POST"
Body = ConvertTo-Json -InputObject $requestBody
Credential = $Credential
}
Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter"
if ($PSCmdlet.ShouldProcess($Name, "Creating new Filter")) {
$result = Invoke-JiraMethod @parameter

Write-Output (ConvertTo-JiraFilter -InputObject $result)
}
}

end {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete"
}
}
39 changes: 39 additions & 0 deletions JiraPS/Public/Remove-JiraFilter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function Remove-JiraFilter {
[CmdletBinding( ConfirmImpact = "Medium", SupportsShouldProcess )]
param(
[Parameter( Mandatory, ValueFromPipeline )]
[ValidateNotNullOrEmpty()]
[PSTypeName('JiraPS.Filter')]
$InputObject,

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

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

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

foreach ($filter in $InputObject) {
$parameter = @{
URI = $filter.RestURL
Method = "DELETE"
Credential = $Credential
}
Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter"
if ($PSCmdlet.ShouldProcess($filter.Name, "Deleting Filter")) {
Invoke-JiraMethod @parameter
}
}
}

end {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete"
}
}
75 changes: 75 additions & 0 deletions JiraPS/Public/Set-JiraFilter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
function Set-JiraFilter {
[CmdletBinding( SupportsShouldProcess )]
param(
[Parameter( Mandatory, ValueFromPipeline )]
[ValidateNotNullOrEmpty()]
[PSTypeName('JiraPS.Filter')]
$InputObject,

[Parameter()]
[ValidateNotNullOrEmpty()]
[String]
$Name,

[Parameter()]
[String]
$Description,

[Parameter()]
[ValidateNotNullOrEmpty()]
[String]
$JQL,

[Parameter()]
[Alias('Favourite')]
[Bool]
$Favorite,

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

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

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

$requestBody = @{}
if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Name")) {
$requestBody["name"] = $Name
}
if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Description")) {
$requestBody["description"] = $Description
}
if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("JQL")) {
$requestBody["jql"] = $JQL
}
if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Favorite")) {
$requestBody["favourite"] = $Favorite
}

if ($requestBody.Keys.Count) {
$parameter = @{
URI = $InputObject.RestURL
Method = "PUT"
Body = ConvertTo-Json -InputObject $requestBody
Credential = $Credential
}
Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter"
if ($PSCmdlet.ShouldProcess($InputObject.Name, "Update Filter")) {
$result = Invoke-JiraMethod @parameter

Write-Output (ConvertTo-JiraFilter -InputObject $result)
}
}
}

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