feat: Add GitLab integration for project-level repository linking#7028
Draft
feat: Add GitLab integration for project-level repository linking#7028
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
99872ab to
2185d42
Compare
207da17 to
b27e98f
Compare
410a6dd to
77ec317
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7028 +/- ##
==========================================
- Coverage 98.32% 98.29% -0.03%
==========================================
Files 1335 1356 +21
Lines 49850 51492 +1642
==========================================
+ Hits 49013 50615 +1602
- Misses 837 877 +40 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
b4874c1 to
f3e5794
Compare
40afbbc to
555bae5
Compare
2f9a2dd to
181fda0
Compare
af2677d to
619885f
Compare
199d6d5 to
4cfe5eb
Compare
Add GitLab integration to Flagsmith, allowing users to link GitLab issues and merge requests to feature flags. Supports both GitLab.com and self-managed instances via Group/Project Access Tokens. ## Backend - New Django app `integrations/gitlab/` with models, views, client, webhook handling, async tasks, and serialisers - `GitLabConfiguration` model (per-project) stores instance URL, access token, webhook secret, and linked GitLab project - Webhook receiver at `/api/v1/gitlab-webhook/<project_id>/` handles merge request and issue events for automatic feature tagging - Comment posting to GitLab issues/MRs when feature flags change - Extend `FeatureExternalResource` with GITLAB_ISSUE and GITLAB_MR resource types, with lifecycle hooks dispatching to GitHub or GitLab - Add `GITLAB` to `TagType` enum for feature tagging ## Frontend - RTK Query services for GitLab integration and resource browsing - GitLabSetupPage component with credentials form, repo selection, tagging toggle, and webhook URL display with copy-to-clipboard - GitLabResourcesSelect for linking issues/MRs to feature flags - Extend IntegrationList, ExternalResourcesLinkTab, and ExternalResourcesTable to support GitLab alongside GitHub Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7c60f2e to
b2edbfd
Compare
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey team! 👋
So... your PM got hold of Claude Code, wanted to test the Superpowers skill, and thought "how hard can it be to add GitLab support?" Famous last words, I know.
Before you reach for the pitchforks: yes, this is AI-generated code. Yes, your PM directed it. No, I don't expect this to be merge-ready without proper engineering review. Think of this as a very detailed, functional, tested PoC that happens to be written in actual code instead of a Google Doc with screenshots.
I'd genuinely appreciate your review — not just "does it work" but "would you architect it this way." The AI follows patterns well but doesn't have your taste. Tear it apart constructively and let's make it production-worthy together.
Product Summary
What: GitLab integration for Flagsmith — the same thing we have for GitHub, but for GitLab.
Why: Our enterprise customers keep asking for it. Many use self-managed GitLab instances and need the same feature flag ↔ issue/MR linking workflow that GitHub customers enjoy.
How it works (user flow):
https://gitlab.com), a Group/Project Access Token (apiscope, Developer role), and an optional webhook secretKey design decisions:
Technical Details for Reviewers
Backend (Django)
New Django app:
api/integrations/gitlab/models.pyGitLabConfiguration— ForeignKey to Project (not Organisation), stores instance URL, access token, webhook secret, linked GitLab project ID/name, tagging toggle. Conditional unique constraint respecting soft-delete.client.pyPRIVATE-TOKENheader.gitlab.pycall_gitlab_taskfor async dispatch.tasks.py@register_task_handlerfor async comment posting. Parses GitLab URLs to extract project path + resource IID.views.pyGitLabConfigurationViewSet(nested under projects), function-based views for resource browsing (issues, MRs, projects, members), cleanup issue creation, webhook receiver.serializers.pyhelpers.pypermissions.pyModified files:
features/feature_external_resources/models.pyGITLAB_ISSUE/GITLAB_MRtoResourceType. RefactoredAFTER_SAVE/BEFORE_DELETEhooks to dispatch by type prefix (GitHub vs GitLab). Supportswork_itemsURL format (GitLab's new issue URL scheme).features/feature_external_resources/views.pylist(live metadata fetch from GitLab API) andcreate(URL validation, label application) for GitLab resource types.features/models.pyFeature.create_github_commentandFeatureSegment.create_github_commenthooks.features/serializers.py+features/versioning/serializers.pycall_gitlab_taskalongsidecall_github_taskfor flag update events.projects/tags/models.pyGITLABtoTagTypeenum.projects/urls.pyapi/urls/v1.pygitlab-webhook/<project_pk>/Webhook URL format:
/api/v1/gitlab-webhook/<project_id>/— project ID in the URL so we can look up the config directly (no iterating over all configs to match the secret).GitLab URL quirk: GitLab recently changed issue URLs from
/-/issues/Nto/-/work_items/N. The code handles both formats with(?:issues|work_items)regex patterns.Frontend (React/TypeScript)
New files:
services/useGitlabIntegration.ts— RTK Query CRUD for configurationservices/useGitlab.ts— RTK Query for project/issue/MR browsingGitLabSetupPage.tsx— Setup modal with credentials form → repo selection → webhook displayGitLabResourcesSelect.tsx— Issue/MR search component for the Links tabModified files:
IntegrationList.tsx— GitLab uses custom modal (not the standardCreateEditIntegrationModal) because it needs repo selection + webhook displayExternalResourcesLinkTab.tsx— GitHub/GitLab toggle when both are configuredExternalResourcesTable.tsx— Handles GitLab resource typescreate-feature/index.js— Checks for GitLab integration to show Links tabdefault-flags.ts— GitLab integration entry with form fieldsutils.tsx—getIntegrationData()now merges defaults so new integrations appear before the remote flag is updatedCreateEditIntegrationModal.tsx— Populates default field values on init (fixes pre-existing bug where defaults showed but weren't submitted)Tests
test_unit_gitlab_client.py— 6 tests for API client functionstest_unit_gitlab_gitlab.py— 1 test for webhook taggingtest_unit_gitlab_views.py— 14 tests for views (config CRUD, webhook, resource browsing)Migration
Single migration
0001_initial.py— createsGitLabConfigurationtable with ForeignKey to Project and conditional unique constraint.What I know needs more work
mypy --stricthasn't been run. There are likely# type: ignorecomments that need proper typing.make lintneeds a full run in the proper environment.getIntegrationDatamerge in utils.tsx — this is a general improvement (new integrations appear before the remote flag is updated) but might have side effects worth discussing./static/images/integrations/gitlab.svgwhich doesn't exist yet.integration_dataflag needs thegitlabentry added for production.How to test locally
You'll need a GitLab access token with
apiscope (Developer role) to test the full flow. For webhooks, use ngrok:ngrok http 8000.Built with Claude Code by a PM who promises to buy the reviewing engineers coffee. Or beer. Probably beer. 🍺