-
Notifications
You must be signed in to change notification settings - Fork 501
Backend: Add GitLab as a VCS provider for Code References #7134
Description
Context: #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 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/acceptsvcs_provider: "gitlab" - Omitting
vcs_providerdefaults to"github" - GitLab permalinks use
/-/blob/format - Feature list API includes
vcs_providerincode_references_counts - 100% diff test coverage
-
make lint && make typecheckpass