Add excluded_relations option to project export API

What does this MR do and why?

When a project is used as a template (via POST /projects with template_project_id), the full export archive is replicated into the new project, including all merge requests, issues, and other relations, regardless of their state or relevance.

This means closed or stale merge requests from the template project are silently copied into every project created from it, which is confusing and clutters the new project.

These issues, MR, ... can still have value for maintainers of the template, they just don't belong in the projects starting from them.

This MR adds an excluded_relations parameter to POST /projects/:id/export, allowing the caller to explicitly exclude specific top-level relations (e.g. merge_requests, issues) from the export archive. The parameter flows through TreeSaver into StreamingSerializer, which skips the relation entirely (nothing is written to the archive for that relation).

Example:

shell curl --request POST \
--header "PRIVATE-TOKEN: $TOKEN" \
--data '{"excluded_relations": \["merge_requests", "issues"\]}' \
"https://gitlab.example.com/api/v4/projects/123/export" 

This is the first of two MRs:

  • This MR: export side: POST /projects/:id/export respects excluded_relations
  • Follow-up MR: POST /projects (create from template) will accept excluded_relations and pass it through to the underlying export call, so template maintainers can control which relations are included when projects are created from their template

References

Screenshots or screen recordings

N/A (API-only change)

How to set up and validate locally

  1. Export a project that has merge requests:
curl --request POST \ 
--header "PRIVATE-TOKEN: $TOKEN" \ 
--data '{"excluded_relations": ["merge_requests"]}' \ 
"http://localhost:3000/api/v4/projects/export"
  1. Poll GET /projects/export until export_status is finished.
  2. Download the archive and inspect tree/project/merge_requests.ndjson : it should not exist.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Edited by Mattias Michaux

Merge request reports

Loading
Loading