Flagsmith / Flagsmith/flagsmith
Code References: Add GitLab as a VCS provider (backend)
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 567
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 121
Description
Context: https://github.com/Flagsmith/flagsmith/issues/7000
The backend only supports `"github"` as a VCS provider. The upload serialiser doesn't even expose the `vcs_provider` field — it relies on the model default. The permalink generator raises `NotImplementedError` for anything else, and the feature-list annotation omits the provider entirely.
### Scope
Accept, store, and serve GitLab code references with correct permalinks. Expose `vcs_provider` in the feature-list API so the frontend can show the right icon.
### Changes
**`api/projects/code_references/types.py`:** Add `GITLAB = "gitlab", "GitLab"` to `VCSProvider`. Add `vcs_provider: str` to `CodeReferencesRepositoryCount`.
**`api/projects/code_references/services.py`:** Add a `VCSProvider.GITLAB` case to `_get_permalink()`. GitLab's [file permalink format](https://docs.gitlab.com/user/project/repository/files/#create-permalinks) uses `/-/blob/`: `{repo_url}/-/blob/{revision}/{file_path}#L{line_number}`. Also add `vcs_provider=F("vcs_provider")` to the `JSONObject` in `annotate_feature_queryset_with_code_references_summary()`.
**`api/projects/code_references/serializers.py`:** Expose `"vcs_provider"` in the upload serialiser's `fields`. Add `vcs_provider` to the count serialiser.
**`api/projects/code_references/models.py`:** Keep `default=VCSProvider.GITHUB` for backward compatibility — existing CI clients don't send the field.
**Migration:** Auto-generate with `make docker-up django-make-migrations`.
### Tests
Services: permalink generation for GitLab URLs (public and self-hosted, with and without trailing slash).
Views: upload with `vcs_provider: "gitlab"` returns 201; upload with invalid provider returns 400; detail view for a GitLab scan returns `/-/blob/` permalinks.
Features views: existing `code_references_counts` test asserts `vcs_provider` is present.
### Acceptance criteria
- [ ] `POST .../code-references/` accepts `vcs_provider: "gitlab"`
- [ ] Omitting `vcs_provider` defaults to `"github"`
- [ ] GitLab permalinks use `/-/blob/` format
- [ ] Feature list API includes `vcs_provider` in `code_references_counts`
- [ ] 100% diff test coverage
- [ ] `make lint && make typecheck` pass
Contributor guide
Assessment
This issue has not been assessed yet.