Skip to content

Commit

Permalink
Allow fields to be filtered by id only
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Baran authored and lipkau committed Jun 13, 2024
1 parent 845495f commit 16604f3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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
[PSCustomObject]
$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

0 comments on commit 16604f3

Please sign in to comment.