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

Allow fields to be filtered by id only in Get-JiraField (mainly for use in Set-JiraIssue) #476

Open
wants to merge 2 commits into
base: release/2.15-alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 23 additions & 1 deletion JiraPS/Public/Get-JiraField.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ function Get-JiraField {
[String[]]
$Field,

[Parameter]
[Switch]
$filterByName,

[Parameter]
[Switch]
$filterById,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
Expand Down Expand Up @@ -43,7 +51,21 @@ function Get-JiraField {

$allFields = Get-JiraField -Credential $Credential

Write-Output ($allFields | Where-Object -FilterScript { ($_.Id -eq $_field) -or ($_.Name -like $_field) })
Write-Output ($allFields | Where-Object -FilterScript {
if (($filterByName -and $filterById) -or (-not $filterByName -and -not $filterById))
{
($_.Id -eq $_field) -or ($_.Name -like $_field)

}
elseif ($filterByName)
{
($_.Name -like $_field)
}
elseif ($filterById)
{
($_.Id -eq $_field)
}
})
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion JiraPS/Public/Set-JiraIssue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ function Set-JiraIssue {
[PSCustomObject]
$Fields,

#this is to fix case when there are multiple fields of the same name
[Switch]
$filterFieldsById,

[String]
$AddComment,

Expand Down Expand Up @@ -162,7 +166,7 @@ function Set-JiraIssue {
$name = $_key
$value = $Fields.$_key

$field = Get-JiraField -Field $name -Credential $Credential -ErrorAction Stop
$field = Get-JiraField -Field $name -Credential $Credential -filterById:$filterFieldsById -ErrorAction Stop

# For some reason, this was coming through as a hashtable instead of a String,
# which was causing ConvertTo-Json to crash later.
Expand Down
Loading