yanyongyu / githubkit

The modern, all-batteries-included GitHub SDK for Python, including rest api, graphql, webhooks, like octokit!
MIT License
158 stars 21 forks source link

Bug: action type error for webhook event of type `repository_dispatch` #93

Closed criemen closed 4 months ago

criemen commented 4 months ago

backtrace

Traceback (most recent call last):
  File "/Users/criemen/repos/codeql-halo/.venv/lib/python3.11/site-packages/flask/app.py", line 2529, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/criemen/repos/codeql-halo/.venv/lib/python3.11/site-packages/flask/app.py", line 1825, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/criemen/repos/codeql-halo/.venv/lib/python3.11/site-packages/flask/app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/criemen/repos/codeql-halo/.venv/lib/python3.11/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/criemen/repos/codeql-halo/webhook_receiver/server.py", line 208, in github_hook
    event: WebhookEvent = parse(event_name, request.data)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/criemen/repos/codeql-halo/.venv/lib/python3.11/site-packages/githubkit/versions/v2022_11_28/webhooks/_namespace.py", line 741, in parse
    return type_validate_json(Event, payload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/criemen/repos/codeql-halo/.venv/lib/python3.11/site-packages/githubkit/compat.py", line 100, in type_validate_json
    return parse_raw_as(type_, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pydantic/tools.py", line 82, in pydantic.tools.parse_raw_as
  File "pydantic/tools.py", line 38, in pydantic.tools.parse_obj_as
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for ParsingModel[WebhookRepositoryDispatchSample]
__root__ -> action
  unexpected value; permitted: 'sample.collected' (type=value_error.const; given=halo_execute_dag_codeql_release_process; permitted=('sample.collected',))

The problem seems to stem from https://github.com/yanyongyu/githubkit/blob/5d88fdc2349496a696d000ea31fef30efcae5e55/githubkit/versions/v2022_11_28/types/group_0719.py#L26 being a literal, instead of allowing any strings. The value comes from the docs, so presumably this is an error in the schema provided by GitHub.