Refactor inline structs into reusable nested types
The current webhook event structs (e.g., PushEvent) contain large, inline nested structs that are hard to work with, difficult to populate in tests, and often result in duplicated code across different event types.
I propose extracting these inline definitions into reusable named types (e.g., Project, Commit, Author) similar to what’s already done in some other cases.
Key issues:
- The Commits field in PushEvent is defined as a slice of anonymous structs, which makes it nearly impossible to construct in Go tests without using raw JSON strings.
- The Project field is repeated with identical fields in multiple webhook types. This not only violates DRY principles but also leads to inconsistencies — for example, in SnippetCommentEvent, the Project field is missing the ID, although GitLab’s documentation states it should be present: https://docs.gitlab.com/user/project/integrations/webhook_events/#comment-on-a-code-snippet
- Using named reusable types would improve readability, testability, and maintainability.
Let me know what you think. I’d be happy to contribute a PR with this refactor if it aligns with project goals.
Edited by Tim Kuzmin