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

feat(typescript): adds organization to ping event types #378

Merged
merged 1 commit into from
Dec 6, 2020

Conversation

octokitbot
Copy link
Collaborator

A new release of @octokit/webhooks was just released 👋🤖

This pull request updates the TypeScript definitions derived from @octokit/webhooks. I can't tell if the changes are fixes, features or breaking, you'll have to figure that out on yourself and adapt the commit messages accordingly to trigger the right release, see our commit message conventions.

@octokitbot octokitbot added the Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR label Dec 6, 2020
Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

update from octokit/webhooks#225 /cc @G-Rath

@gr2m gr2m changed the title 🚧 🤖📯 Webhooks changed feat(typescript): adds organization to ping event types Dec 6, 2020
@G-Rath
Copy link
Member

G-Rath commented Dec 6, 2020

@gr2m awesome! I don't know if you release for refactors, so could be good to have #377 merged first, since this will trigger a release.

Comment on lines -2870 to +2895
test_url: string;
test_url?: string;
ping_url: string;
last_response: WebhookPayloadPingHookLastResponse;
last_response?: WebhookPayloadPingHookLastResponse;
};
type WebhookPayloadPing = {
zen: string;
hook_id: number;
hook: WebhookPayloadPingHook;
repository: PayloadRepository;
repository?: PayloadRepository;
sender: WebhookPayloadPingSender;
organization?: WebhookPayloadPingOrganization;
Copy link
Contributor

Choose a reason for hiding this comment

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

@G-Rath could you please double check if these changes look good to you?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, they look fine.

Just btw, the ideal would be a union type a la:

   type WebhookPayloadPingBase = {
      zen: string;
      hook_id: number;
      hook: WebhookPayloadPingHook;
      sender: WebhookPayloadPingSender;
    };
    interface WebhookPayloadPingOrg extends WebhookPayloadPingBase {
      organisation: WebhookPayloadPingOrganization;
    }
    interface WebhookPayloadPingRepo extends WebhookPayloadPingBase {
      repository: PayloadRepository;
    }
    type WebhookPayloadPing = WebhookPayloadPingOrg | WebhookPayloadPingRepo

As this would properly represent that you can't have both, and you'd do:

if (event.name === 'ping') {
  if ('organisation' in event.payload) {
    console.log(event.payload.organisation.avatar_url);
  }
}

But that'd be a decent refactor of the type generator + the types themselves, and these types are serviceable as they are currently :)

Copy link
Contributor

Choose a reason for hiding this comment

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

The current types are generated using https://github.com/gimenete/type-writer in https://github.com/octokit/webhooks.js/blob/84f753b284d1a9fef94465a3463de94d0b63da48/scripts/generate-types.js from the JSON example payloads.

The proper solution would be to create a JSON Schema that will become the single place of truth, and then only use the examples as means of testing the schema:
octokit/webhooks#186

We had a similar evolution happening with the types for @octokit/rest and its REST API endpoint methods. Originally I created an OpenAPI spec myself by scraping GitHub's doc pages, eventually GitHub published an official OpenAPI spec with proper schema, which greatly improved the types and reduces the code size: octokit/types.ts#197 (There is a blog post about the whole process). I'm pretty sure eventually GitHub will publish and maintain official JSON Schemas for all the events. I want us to help in the process by creating a starting point via octokit/webhooks#186, similar to what we did for the REST API endpoints

@gr2m gr2m merged commit 393d65c into master Dec 6, 2020
@gr2m gr2m deleted the update-octokit-webhooks branch December 6, 2020 21:47
@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2020

🎉 This PR is included in version 7.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants