Draft: Feature: Add Webhook To Intake
(WIP Description)
MR Purpose
The purpose of this merge request is to allow for the Triage Gem to take in GitLab's webhook payloads.
Reasoning
Currently, there is no way to use the Gem to get detailed information on comments. Having this ability will allow for anyone using the gem to create more in-depth automation around comments.
While comments were the main concern due to an internal project, this MR will allow for webhook data to be passed in from the following events:
- Issue Events
- Merge Request Events
- Note (comment) Events
- Note On An Issue Events
- Note On A Merge Request Event
- Note On A Commit Event
The ability to parse webhook payloads will allow for possibly using fewer resources when the gem runs. This is because the webhook is sent when an event happens, so we no longer need to limit our searches as we know that the event happened.
TL;DR it removes the need to list issues/MRs/etc.
Details
How It Works
Event Classes
All events that are parsed by the Gem will initially hit the BaseEvent
class. All webhook payloads will have the project
and user
attributes parsed and put into the project
and author
fields for the final mappings.
- This is done because these two attributes are common between all Event types. The
project
field will be used to let the Gem know which project the event is coming from and in turn which project to run anyactions
on. - This class then has a case statement to find which kind of event we are parsing (IssueEvent, MergeRequestEvent, or NoteEvent).
- If an
IssueEvent
, then we will build out the hash to match the Single Issue API Response as close as we can. - If a
MergeRequestEvent
, then we will build out the hash to match the Single Merge Request API Response as close as we can. - If a
NoteEvent
then we will start by building out thenote
hash that will be filtered on via theEngine
class.- The
NoteEvent
can have one of the following three sub-note categoriesIssueNoteEvent
MergeRequestNoteEvent
CommitNoteEvent
- These subcategories will build out the portions of the hash for each different note event type, respectively
- The
- If an
Once the webhooks payload has been run through the event classes, it returns a hash that will mimic the API returns. This is then used to apply the same filters you would on API calls in the Engine
class.
The idea behind this is that we will be able to make minimal changes to the Engine
and Action
classes in order to have webhooks become an intake form for the Gem.