Feat/system hook - #82
Clark06110 wants to merge 13 commits into
Conversation
Chore/optim pipe See merge request dev/audes/placide/outillage/gitlab-mr-conform!1
Rendu conditionnel si le yaml est présent à la racine du repo ou pas, vide ou pas
Feat/system hooks yaml config See merge request dev/audes/placide/outillage/gitlab-mr-conform!2
perf: add Redis cache layer and queue optimizations for large-scale deployments See merge request dev/audes/placide/outillage/gitlab-mr-conform!3
perf: add Redis cache layer and queue optimizations for large-scale deployments See merge request dev/audes/placide/outillage/gitlab-mr-conform!4
Add GitLab system hook support for instance-wide deployment with selective repository processing based on configuration file presence. ## Changes ### Core Features - Add /system-hook endpoint (POST) for GitLab system hooks - Implement ConfigPresence detection (ConfigNotFound, ConfigEmpty, ConfigPopulated) - Add SystemHookSecretToken configuration field - Create CheckMergeRequestForSystemHook() method with skip logic - Add Skipped field to CheckResult struct ### Behavior Differences **Webhook (/webhook):** - Always processes merge requests - Uses repository config if .placide-mr-conform.yaml exists - Falls back to default config if file is missing or invalid **System Hook (/system-hook):** - Skips repositories without .placide-mr-conform.yaml file - Uses default config if file exists but is empty - Uses repository config if file contains rules - Enables opt-in model for instance-wide deployment ### Queue Support - Both endpoints support Redis queue when enabled - Queue-less operation mode maintained for both endpoints ### Documentation - Add comprehensive comparison between webhook and system-hook - Document PAT/GAT token usage for webhooks - Document admin PAT requirement for system hooks - Add behavior matrix for different configuration file states - Update API reference table ### Technical Details - Implement peekObjectKind() optimization for early event filtering - Add isRelevantMergeAction() filter (open, reopen, update) - Preserve existing webhook behavior (no breaking changes) - No Redis cache layer or pprof additions from main branch Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fdea47a to
8115073
Compare
Signed-off-by: Clark06110 <92217525+Clark06110@users.noreply.github.com>
|
Hi @Clark06110 , first of all - thanks for your time and contribution! I analyzed proposed change and verified with current gitlab client-go module. Not sure if we really need to split system hook and webhook. Gitlab client offers parser that verifies if hook is a system hook or webhook, so we could simply add I tested this solution and it works fine for both - system hooks and webhooks and requires just 3 LoC changes. The only thing I think about is if SystemHook should really skip repositories that don't have .mr-conform.yaml file defined in default branch. If your organization decide to use system hook then rules should apply to all projects without exemptions. If someone don't want any checks, they could simply disable those in their repo. |
Pull Request
What? (description)
This PR adds GitLab System Hook support (
/system-hookendpoint) for instance-wide deployment with selective, opt-in repository processing.New Features:
/system-hookendpoint for GitLab system hooks (admin-level integration).mr-conform.yamlfile presenceSystemHookSecretTokenconfiguration for system hooksConfigPresencedetection (ConfigNotFound, ConfigEmpty, ConfigPopulated)CheckMergeRequestForSystemHook()method with skip logicKey Behaviors:
/webhook) - Always processes MRs (existing behavior unchanged)/system-hook) - Skips repositories without config file (opt-in model)Files Modified:
internal/config/config.go- Added SystemHookSecretToken and ConfigPresence logicinternal/conformity/checker.go- Added Skipped field and system-hook checker methodinternal/server/server.go- Added/system-hookroutesinternal/server/system_hook.go- New file with system hook handlersREADME.md- Comprehensive documentation for both integration modesWhy? (reasoning)
Problem:
Currently, the project only supports project-level webhooks, which require manual setup per project. For organizations with self-hosted GitLab instances, there's no way to offer a centralized, opt-in conformity service across all projects.
Solution:
GitLab system hooks enable administrators to deploy a single service that:
Use Cases:
.mr-conform.yamlBenefits:
Acceptance
Please use the following checklist:
make build) - Build successfulmake test) - Tests pass (existing test coverage applies)Additional Validation:
go build ./...Deployment Note:
This feature is purely additive. Existing users don't need to change anything. New users can choose between: