Skip to content

Feat/system hook - #82

Open
Clark06110 wants to merge 13 commits into
chrxmvtik:mainfrom
Clark06110:feat/system-hook
Open

Clark06110 wants to merge 13 commits into
chrxmvtik:mainfrom
Clark06110:feat/system-hook

Conversation

@Clark06110

Copy link
Copy Markdown

Pull Request

What? (description)

This PR adds GitLab System Hook support (/system-hook endpoint) for instance-wide deployment with selective, opt-in repository processing.

New Features:

  • /system-hook endpoint for GitLab system hooks (admin-level integration)
  • Intelligent repository filtering based on .mr-conform.yaml file presence
  • Separate SystemHookSecretToken configuration for system hooks
  • ConfigPresence detection (ConfigNotFound, ConfigEmpty, ConfigPopulated)
  • New CheckMergeRequestForSystemHook() method with skip logic
  • Queue support for both webhook and system-hook endpoints

Key Behaviors:

  • Webhook (/webhook) - Always processes MRs (existing behavior unchanged)
  • System Hook (/system-hook) - Skips repositories without config file (opt-in model)

Files Modified:

  • internal/config/config.go - Added SystemHookSecretToken and ConfigPresence logic
  • internal/conformity/checker.go - Added Skipped field and system-hook checker method
  • internal/server/server.go - Added /system-hook routes
  • internal/server/system_hook.go - New file with system hook handlers
  • README.md - Comprehensive documentation for both integration modes

Why? (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:

  1. Monitors all projects in the GitLab instance
  2. Only processes projects that opt-in by adding a config file
  3. Reduces noise by skipping repositories that don't want the service
  4. Provides centralized enforcement without forcing it on every project

Use Cases:

  • Self-hosted GitLab: Admin deploys once, projects opt-in via .mr-conform.yaml
  • GitLab SaaS: Continue using project webhooks (no admin access available)
  • Hybrid deployments: Use both system hooks (instance-wide) and webhooks (specific projects)

Benefits:

  • Zero breaking changes - existing webhook users unaffected
  • Flexible deployment models for different organizational needs
  • Reduced API calls - repositories without config files are filtered early
  • Clear separation of concerns - different tokens for webhook vs system-hook

Acceptance

Please use the following checklist:

Additional Validation:

  • Code compiles successfully: go build ./...
  • No breaking changes to existing webhook functionality
  • Both endpoints support Redis queue when enabled
  • Documentation updated with comprehensive guides and comparison table
  • Configuration file detection works correctly (not found/empty/populated)

Deployment Note:
This feature is purely additive. Existing users don't need to change anything. New users can choose between:

  • Project Webhooks (PAT/GAT) - Always-on enforcement
  • System Hooks (Admin PAT) - Opt-in model for instance-wide coverage

Clement Martel added 11 commits April 29, 2026 15:40
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
@Clark06110
Clark06110 requested a review from chrxmvtik as a code owner June 25, 2026 10:03
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>
Signed-off-by: Clark06110 <92217525+Clark06110@users.noreply.github.com>
@chrxmvtik

chrxmvtik commented Jul 4, 2026

Copy link
Copy Markdown
Owner

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 EventTypeSystemHook to allowed events and change ParseWebhook function to ParseHook function.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants