Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt the types to the OpenAPI spec types #840

Closed
Tracked by #839
wolfy1339 opened this issue Apr 15, 2023 · 3 comments · Fixed by #841
Closed
Tracked by #839

Adapt the types to the OpenAPI spec types #840

wolfy1339 opened this issue Apr 15, 2023 · 3 comments · Fixed by #841
Labels

Comments

@wolfy1339
Copy link
Member

wolfy1339 commented Apr 15, 2023

The types will need to be adapted to make use of the OpenAPI spec.

We can make use of my package @wolfy1339/openapi-webhooks-types to help with the transition.


Some points which I see as potential issues:

The types format is not the same, the webhooks are not on their own interface like they are currently in @octokit/webhooks-types.
In the OpanAPI spec types, the way to get a webhook resembles like so:

import { webhooks } from `@wolfy1339/openapi-webhooks-types`;

type TEventIdentifier = "check-suite-completed";
type CheckSuiteCompletedEvent = webhooks[TEventIdentifier]["post"]["requestBody"]["content"]["application/json"];

Each webhook definition's name is made like so in reference to the names we accept in the event handlers

const webhookIdentifier = "check_suite.completed".replaceAll(/_|\./g, "-");
// webhookIdentifier: check-suite-completed

The name is seperated by - and dots are replaced by -



There are currently no types for events and all their possible actions, eg: check_suite.

I'm not sure how we can get around this easily without having to resort to a lookup table. If you have any ideas, please comment

@wolfy1339 wolfy1339 mentioned this issue Apr 15, 2023
3 tasks
@wolfy1339 wolfy1339 added the Type: Feature New feature or request label Apr 15, 2023
@wolfy1339
Copy link
Member Author

In #444, we switched from a map of event names and their payloads, to an approach that only uses TypeScript to infer the correct types.

In order to switch to OpenAPI, I had to bring that map back.

I created a PoC, beta...openapi based on my openapi types package

Does anyone have an idea on how to get rid of the map, and stay with a completely typescript approach?

@wolfy1339
Copy link
Member Author

I managed to create this handy utility that can help us convert the webhook event names we get from the event handler to the format used in the openapi spec

type SnakeCaseToKebabCase<TString extends string> =
  TString extends `${infer TPart1}_${infer TRest}`
    ? `${TPart1}-${SnakeCaseToKebabCase<TRest>}`
    : TString;

With this new utility I managed to remove most of the need for a map.
f84e6f1

@kfcampbell kfcampbell moved this from 🆕 Triage to 🏗 In progress in 🧰 Octokit Active Apr 17, 2023
@wolfy1339 wolfy1339 linked a pull request Aug 25, 2023 that will close this issue
5 tasks
Copy link
Contributor

🎉 This issue has been resolved in version 12.2.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in 🧰 Octokit Active Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant