Skip to content

Fix labels in events being treated as full label objects - #306

Merged
Howard Wolosky (HowardWolosky) merged 6 commits into
microsoft:masterfrom
joseartrivera:joriv/eventfix
Dec 22, 2020
Merged

Howard Wolosky (HowardWolosky) merged 6 commits into
microsoft:masterfrom
joseartrivera:joriv/eventfix

Conversation

@joseartrivera

Copy link
Copy Markdown
Contributor

Description

The 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 events 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.

Issues Fixed

none

References

The docs do not explicitly call this out, but you can check the payload in fiddler for verificaiton.

Checklist

  • You actually ran the code that you just wrote, especially if you did just "one last quick change".
  • Comment-based help added/updated, including examples.
  • Static analysis is reporting back clean.
  • New/changed code adheres to our coding guidelines.
  • Formatters were created for any new types being added.
  • New/changed code continues to support the pipeline.
  • Changes to the manifest file follow the manifest guidance.
  • Unit tests were added/updated and are all passing. See testing guidelines. This includes making sure that all pipeline input variations have been covered.
  • Relevant usage examples have been added/updated in USAGE.md.
  • If desired, ensure your name is added to our Contributors list

@joseartrivera Pepe Rivera (joseartrivera) added the bug This relates to a bug in the existing module. label Dec 17, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the report. I was able to repro your issue by calling

Get-GitHubEvent -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 306

What you supplied would indeed fix the specific issue you're running into, but I don't know if it's actually the right fix.

I think the more complete fix would be to create a new Type called GitHub.LabelSummary for the reduce content, similar to what we do for GitHub.Team/GitHub.TeamSummary, and then update Add-GitHubLabelAdditionalProperties to optionally take in the OwnerName and RepositoryName. If supplied, and $item.url is not defined, then those should be used for forming the $repositoryUrl. Then you'd update Add-GitHubEventAdditionalProperties to pass in the ReposistoryUrl and OwnerName along with the new TypeName.

That should fix the bug while also ensuring individual labels can still be passed via the pipeline into other functions.

@joseartrivera

Pepe Rivera (joseartrivera) commented Dec 17, 2020 •

Copy link
Copy Markdown
Contributor Author

I thought of this approach too, but I thought it was a mistake that would add too much complexity if we try and treat this as a Label object when that was not the original intention / format of the original Github API, but I can go this route if you prefer.

Edit: For example, in the future if more data is added to Label objects, we may be forced to make an extra call to Get-GithubLabel to stay in sync with the object schema.

I'm not as worried about that. The purpose of Add-GitHub*AdditionalProperties is to add the minimal set of additional properties to the objects so that they can be passed-in to other functions via the pipeline. By ensuring that we call those functions on .label and .labels, we ensure that those individual items could later be piped directly into the label functions and they'd have all the necessary information (LabelName, RepositoryUrl) to work seemlessly. We just want to make sure that we give the object a different type from the normal GitHub.Label so that assumptions aren't made by the caller and so that PowerShell formatters can work correctly.

@ghost ghost removed the needs-author-feedback label Dec 17, 2020
@joseartrivera

Copy link
Copy Markdown
Contributor Author

Thanks for the report. I was able to repro your issue by calling

Get-GitHubEvent -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 306

What you supplied would indeed fix the specific issue you're running into, but I don't know if it's actually the right fix.

I think the more complete fix would be to create a new Type called GitHub.LabelSummary for the reduce content, similar to what we do for GitHub.Team/GitHub.TeamSummary, and then update Add-GitHubLabelAdditionalProperties to optionally take in the OwnerName and RepositoryName. If supplied, and $item.url is not defined, then those should be used for forming the $repositoryUrl. Then you'd update Add-GitHubEventAdditionalProperties to pass in the ReposistoryUrl and OwnerName along with the new TypeName.

That should fix the bug while also ensuring individual labels can still be passed via the pipeline into other functions.

I updated the code, there is no need to update the params to GitHubEventAdditionalProperties as the repository url is already available from the base event object.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. Some minor additional updates being requested here.

Comment thread GitHubLabels.ps1 Resolved
Comment thread GitHubLabels.ps1 Resolved
Comment thread GitHubLabels.ps1 Resolved
Comment thread GitHubLabels.ps1 Resolved
@ghost ghost removed the needs-author-feedback label Dec 18, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update.
There are some additional changes to make, but I've already supplied the fixes as suggestions and can apply them myself once this review is submitted.

Comment thread GitHubLabels.ps1 Resolved
Comment thread GitHubLabels.ps1 Resolved
Comment thread GitHubLabels.ps1 Resolved
@HowardWolosky

Copy link
Copy Markdown
Contributor

/azp run PowerShellForGitHub-CI

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@HowardWolosky
Howard Wolosky (HowardWolosky) merged commit 8fd4201 into microsoft:master Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This relates to a bug in the existing module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants