(w http.ResponseWriter, r *http.Request)
| 182 | } |
| 183 | |
| 184 | func (a *APIController) WebhookHandler(w http.ResponseWriter, r *http.Request) { |
| 185 | ctx := r.Context() |
| 186 | |
| 187 | vars := mux.Vars(r) |
| 188 | controllerID, ok := vars["controllerID"] |
| 189 | // If the webhook URL includes a controller ID, we validate that it's meant for us. We still |
| 190 | // support bare webhook URLs, which are tipically configured manually by the user. |
| 191 | // The controllerID suffixed webhook URL is useful when configuring the webhook for an entity |
| 192 | // via garm. We cannot tag a webhook URL on github, so there is no way to determine ownership. |
| 193 | // Using a controllerID suffix is a simple way to denote ownership. |
| 194 | if ok && controllerID != a.controllerID { |
| 195 | slog.InfoContext(ctx, "ignoring webhook meant for foreign controller", "req_controller_id", controllerID) |
| 196 | return |
| 197 | } |
| 198 | |
| 199 | headers := r.Header.Clone() |
| 200 | |
| 201 | event := runnerParams.Event(headers.Get("X-Github-Event")) |
| 202 | switch event { |
| 203 | case runnerParams.WorkflowJobEvent: |
| 204 | a.handleWorkflowJobEvent(ctx, w, r) |
| 205 | case runnerParams.PingEvent: |
| 206 | // Ignore ping event. We may want to save the ping in the github entity table in the future. |
| 207 | default: |
| 208 | slog.DebugContext(ctx, "ignoring unknown event", "gh_event", util.SanitizeLogEntry(string(event))) |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | func (a *APIController) EventsHandler(w http.ResponseWriter, r *http.Request) { |
| 213 | ctx := r.Context() |
nothing calls this directly
no test coverage detected