feat(event-handlers): introduce event handler system for GitProxy lifecycle events#1519
feat(event-handlers): introduce event handler system for GitProxy lifecycle events#1519Andreybest wants to merge 1 commit into
Conversation
✅ Deploy Preview for endearing-brigadeiros-63f9d0 canceled.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1519 +/- ##
==========================================
+ Coverage 90.21% 90.46% +0.24%
==========================================
Files 69 75 +6
Lines 5511 5798 +287
Branches 944 1005 +61
==========================================
+ Hits 4972 5245 +273
- Misses 521 534 +13
- Partials 18 19 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@Andreybest Could I vote for an additional phase? We have several custom actions that run when a push is first received and the proxy blocks it for review. This state is not really We also have custom actions that would work really well as plugin events. For example, we:
It would be great if plugins could also add data that can be rendered in the UI. This would be a hugely helpful change, as it would allow us to separate our custom code from the base git-proxy. Keeping the two in sync is painful at the moment. |
|
Hey @andypols ! Thanks for the suggestion, this seems like a good use cases for events. Will try to add mechanisms that would be able to support your use cases :) |
re-vlad
left a comment
There was a problem hiding this comment.
Just a wish: while the code is well-documented, there's no external docs (README, docs, etc.) explaining how to use the event system. This should be added.
| "contactEmail": "", | ||
| "csrfProtection": true, | ||
| "plugins": [], | ||
| "eventHandlers": [], |
There was a problem hiding this comment.
The config schema shows the eventHandlers array, but there are no examples of how to configure event handlers in proxy.config.json. Consider to document example
| if (!action.user && !action.userEmail) { | ||
| return undefined; | ||
| } | ||
| return { username: action.user, email: action.userEmail }; |
There was a problem hiding this comment.
EventDetails.user and repository must be immutable copies (using String()) of Action fields — not references. Otherwise, async handlers may see stale or modified data if Action is mutated later in the chain. This rather critical I believe, but easy to fix:
return {
username = action.user ? String(action.user) : undefined;
email = action.userEmail ? String(action.userEmail) : undefined;
}```.
| } from './types'; | ||
|
|
||
| const buildRepositoryContext = (action: Action): RepositoryContext => ({ | ||
| url: action.url, |
There was a problem hiding this comment.
The same problem like line 38, don't return references, return values instead:
name: action.repoName? String(action.repoName) : undefined,
url: String(action.url),
Implements #1449.
Introduces a lightweight, async, observer-only event system so external integrations (notifications, audit feeds) can react to push/pull lifecycle events without coupling to chain internals.
Event hooks can be added the same way as the
pluginsinconfig.proxy.jsonSupports 2 operations:
pullandpushWith 4 phases:
startedcompletederrorpermissionDeniedThis is not well documented, and not sure where to add info on that, would appreciate suggestions on that matter :)