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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
Expand Down
21 changes: 9 additions & 12 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@
CHANGELOG.md merge=union

# Set default behaviour, in case users don't have core.autocrlf set.
* text=auto
* text=auto eol=crlf

# Explicitly declare text files we want to always be normalized and converted
# to native line endings on checkout.
*.md text
*.gitattributes text

# Declare files that will always have LF line endings on checkout.
*.ps1 text eol=lf
*.psm1 text eol=lf
*.psd1 text eol=lf
*.psc1 text eol=lf
*.ps1xml text eol=lf
*.clixml text eol=lf
*.xml text eol=lf
*.txt text eol=lf
*.md text eol=lf
*.ps1 text
*.psm1 text
*.psd1 text
*.psc1 text
*.ps1xml text
*.clixml text
*.xml text
*.txt text

# Denote all files that are truly binary and should not be mergeable.
*.dll binary
Expand Down
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