Skip to content

Commit 8fd4201

Browse files
Fix labels in events being treated as full label objects (#306)
`Get-GitHubEvent` is currently broken if the issue contains and event that includes the "label" or "labels" property. This is because `Add-GitHubEventAdditionalProperties` treats the labels in the event object as full fledged label objects that normally contain a URL property and other additional pieces of data. The label property in a `GitHub.Event` is a lighter-weight object that simply contains the string for the label and color that was changed, it is not the full object that you would typically receive from a call like `Get-GithubLabel`. Updated to add a new `GitHub.LabelSummary` type to describe this scenario, as well as passing in the needed `RepositoryUrl` when adding the additional label properties.
1 parent d499705 commit 8fd4201

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

GitHubEvents.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
@{
55
GitHubEventTypeName = 'GitHub.Event'
6+
GitHubLabelSummaryTypeName = 'GitHub.LabelSummary'
67
}.GetEnumerator() | ForEach-Object {
78
Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value
89
}
@@ -237,12 +238,12 @@ filter Add-GitHubEventAdditionalProperties
237238

238239
if ($null -ne $item.label)
239240
{
240-
$null = Add-GitHubLabelAdditionalProperties -InputObject $item.label
241+
$null = Add-GitHubLabelAdditionalProperties -InputObject $item.label -TypeName $script:GitHubLabelSummaryTypeName -RepositoryUrl $repositoryUrl
241242
}
242243

243244
if ($null -ne $item.labels)
244245
{
245-
$null = Add-GitHubLabelAdditionalProperties -InputObject $item.labels
246+
$null = Add-GitHubLabelAdditionalProperties -InputObject $item.labels -TypeName $script:GitHubLabelSummaryTypeName -RepositoryUrl $repositoryUrl
246247
}
247248

248249
if ($null -ne $item.milestone)

GitHubLabels.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,10 @@ filter Add-GitHubLabelAdditionalProperties
13271327
.PARAMETER InputObject
13281328
The GitHub object to add additional properties to.
13291329
1330+
.PARAMETER RepositoryUrl
1331+
Optionally supplied if the Label object doesn't have this value already
1332+
(as is the case for GitHub.LabelSummary).
1333+
13301334
.PARAMETER TypeName
13311335
The type that should be assigned to the object.
13321336
@@ -1346,6 +1350,8 @@ filter Add-GitHubLabelAdditionalProperties
13461350
[AllowEmptyCollection()]
13471351
[PSCustomObject[]] $InputObject,
13481352

1353+
[string] $RepositoryUrl,
1354+
13491355
[ValidateNotNullOrEmpty()]
13501356
[string] $TypeName = $script:GitHubLabelTypeName
13511357
)
@@ -1356,9 +1362,13 @@ filter Add-GitHubLabelAdditionalProperties
13561362

13571363
if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport))
13581364
{
1359-
$elements = Split-GitHubUri -Uri $item.url
1360-
$repositoryUrl = Join-GitHubUri @elements
1361-
Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force
1365+
if (-not [System.String]::IsNullOrEmpty($item.url))
1366+
{
1367+
$elements = Split-GitHubUri -Uri $item.url
1368+
$RepositoryUrl = Join-GitHubUri @elements
1369+
}
1370+
1371+
Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $RepositoryUrl -MemberType NoteProperty -Force
13621372

13631373
if ($null -ne $item.id)
13641374
{

0 commit comments

Comments
 (0)