webhooks icon indicating copy to clipboard operation
webhooks copied to clipboard

Changes object has 19 possible keys but type is defined with only 3 of them

Open LightningStairs opened this issue 3 years ago • 4 comments

The changes object type is defined to have 3 possible keys: authorized_actors_only, authorized_actor_names, and required_status_checks. But it can have several others as well:

     pull_request_reviews_enforcement_level
      required_approving_review_count
      dismiss_stale_reviews_on_push
      require_code_owner_review
      authorized_dismissal_actors_only
      ignore_approvals_from_contributors
      required_status_checks_enforcement_level
      strict_required_status_checks_policy
      signature_requirement_enforcement_level
      linear_history_requirement_enforcement_level
      admin_enforced
      allow_force_pushes_enforcement_level
      allow_deletions_enforcement_level
      merge_queue_enforcement_level
      required_deployments_enforcement_level
      required_conversation_resolution_level

Because of how this type is defined it is only possible to test cases when authorized_actors_only, authorized_actor_names, and required_status_checks change.

https://github.com/octokit/webhooks/blob/e4bef38ae171f929eb4da9d2913f164eedf58a9a/payload-types/schema.d.ts#L793-L803

LightningStairs avatar Aug 09 '22 19:08 LightningStairs

Can you confirm wether this is for GitHub.com and not GitHub.AE or GitHub Enterprise? Please provide an example payload with those keys

wolfy1339 avatar Aug 09 '22 19:08 wolfy1339

The required_conversation_resolution_level now has a different type in the BranchProtectionRule

https://github.com/octokit/webhooks/blob/5d5bb3ca635b7224a591898321d1a5bad67af3b2/payload-types/schema.d.ts#L440

and BranchProtectionRuleEditedEvent

https://github.com/octokit/webhooks/blob/5d5bb3ca635b7224a591898321d1a5bad67af3b2/payload-types/schema.d.ts#L824-L826

JamieMagee avatar Aug 10 '22 23:08 JamieMagee

I think it might be easiest to introduce a new common schema for each rule type.

  • BranchProtectionRuleBinary - rules where only boolean values are used
  • BranchProtectionRuleMultiLevel - rules where you can select one of off, non_admins, or everyone
  • BranchProtectionRuleArray - rules where an array of strings is expected, used for actor and build rules

wolfy1339 avatar Aug 11 '22 00:08 wolfy1339

That sounds reasonable, and it's effectively what I did in the .NET version. I think you will also need a BranchProtectionRuleNumber as well though:

https://github.com/octokit/webhooks/blob/5d5bb3ca635b7224a591898321d1a5bad67af3b2/payload-types/schema.d.ts#L421

JamieMagee avatar Aug 11 '22 15:08 JamieMagee

I believe all the remaining possible keys have been added

wolfy1339 avatar Oct 26 '22 01:10 wolfy1339