Skip to content

Commit

Permalink
Fix labels in events being treated as full label objects (#306)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
joseartrivera committed Dec 22, 2020
1 parent d499705 commit 8fd4201
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions GitHubEvents.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@{
GitHubEventTypeName = 'GitHub.Event'
GitHubLabelSummaryTypeName = 'GitHub.LabelSummary'
}.GetEnumerator() | ForEach-Object {
Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value
}
Expand Down Expand Up @@ -237,12 +238,12 @@ filter Add-GitHubEventAdditionalProperties

if ($null -ne $item.label)
{
$null = Add-GitHubLabelAdditionalProperties -InputObject $item.label
$null = Add-GitHubLabelAdditionalProperties -InputObject $item.label -TypeName $script:GitHubLabelSummaryTypeName -RepositoryUrl $repositoryUrl
}

if ($null -ne $item.labels)
{
$null = Add-GitHubLabelAdditionalProperties -InputObject $item.labels
$null = Add-GitHubLabelAdditionalProperties -InputObject $item.labels -TypeName $script:GitHubLabelSummaryTypeName -RepositoryUrl $repositoryUrl
}

if ($null -ne $item.milestone)
Expand Down
16 changes: 13 additions & 3 deletions GitHubLabels.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,10 @@ filter Add-GitHubLabelAdditionalProperties
.PARAMETER InputObject
The GitHub object to add additional properties to.
.PARAMETER RepositoryUrl
Optionally supplied if the Label object doesn't have this value already
(as is the case for GitHub.LabelSummary).
.PARAMETER TypeName
The type that should be assigned to the object.
Expand All @@ -1346,6 +1350,8 @@ filter Add-GitHubLabelAdditionalProperties
[AllowEmptyCollection()]
[PSCustomObject[]] $InputObject,

[string] $RepositoryUrl,

[ValidateNotNullOrEmpty()]
[string] $TypeName = $script:GitHubLabelTypeName
)
Expand All @@ -1356,9 +1362,13 @@ filter Add-GitHubLabelAdditionalProperties

if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport))
{
$elements = Split-GitHubUri -Uri $item.url
$repositoryUrl = Join-GitHubUri @elements
Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force
if (-not [System.String]::IsNullOrEmpty($item.url))
{
$elements = Split-GitHubUri -Uri $item.url
$RepositoryUrl = Join-GitHubUri @elements
}

Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $RepositoryUrl -MemberType NoteProperty -Force

if ($null -ne $item.id)
{
Expand Down

0 comments on commit 8fd4201

Please sign in to comment.