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

Inconsistency in representing events in HookInput and Hook #70

Open
chhsia0 opened this issue Aug 19, 2020 · 1 comment
Open

Inconsistency in representing events in HookInput and Hook #70

chhsia0 opened this issue Aug 19, 2020 · 1 comment

Comments

@chhsia0
Copy link
Contributor

chhsia0 commented Aug 19, 2020

Right now, hooks are created with parameters specified by HookInput, which contains a HookEvents to indicate which abstract event should be listened to. But the Hook struct returned by FindHook() contains Events []string, which is a list of native event names. This makes it hard to implement a "reconciliation" logic, where the program needs to check if an existing webhook matches a HookInput to decide if it should recreate the webhook. The workaround is to only use HookInput.NativeEvents and don't rely on HookInput.Events at all.

It seems reasonable to change Hook.Events from []string to HookEvents, and introduce a HookEvents.NativeEvents field to make the API more consistent. However, these are all breaking changes.

Would it make sense to deprecate HookInput.Events, HookInput.NativeEvents and Hook.Events, and instead having a new field name for HookEvents in both HookInput and Hook?

@bradrydzewski
Copy link
Member

bradrydzewski commented Aug 19, 2020

I do not believe the webhook events can be fully abstracted — they are not consistently implemented across providers — which is why we return the native event types. Native events are required for creating hooks with provider-specific events that are not abstracted by or supported by this library. I consider HookEvents to be a convenient option to create all hooks that are supported by this library, but not a viable replacement for NativeEvents.

The reason I did not use HookEvents when returning the Hook structure is because I did not believe it would be possible to accurately perform this mapping. For example, what happens if the create event is enabled but the delete event is disabled in GitHub? What would we return for HookEvents.Tag and HookEvents.Branch given the events are partially enabled (create) but not fully enabled (delete)? Was it really worth trying to abstract this data if we could not return accurate information? I decided that it was probably best to avoid this abstraction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants