--- title: "ADR 0039: Fetching a GitLab merge request diff when the API truncates it" --- * Status: accepted * Code: [`pkg/provider/gitlab/gitlab.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/gitlab/gitlab.go), `mergeRequestFilesChanged`, `isMergeRequestDiffTruncated` ## Context GitLab caps how many changes it returns for a merge request. When the cap is hit, `GET /merge_requests/:id` stops returning an exact count and reports `changes_count` with a `+` suffix. That suffix is the only signal the API gives that the diff is incomplete, and it is a convention of the response body, not a flag, not an error, and not a header. PAC needs the complete file list: it drives `on-path` / `on-event` CEL filters and the changed-files variables. A truncated list silently drops files, so a `PipelineRun` that should have matched does not run. Two endpoints can produce the list: * `ListMergeRequestDiffs` is paginated, so it is cheap per request and cannot blow up memory, but it is subject to the same truncation. * `Repositories.Compare` returns the entire set of changes without paging. Nothing is truncated, and a large merge request therefore returns a response proportional to its size, in one allocation. ## Decision * `isMergeRequestDiffTruncated` asks for the merge request, reads `changes_count`, and treats a trailing `+` as truncation. The count without the suffix seeds the capacity of the `All` slice. * The default path is the paginated `ListMergeRequestDiffs`. The compare API is used **only** when the suffix says the paginated endpoint will return an incomplete set. * When compare is used it compares `BaseBranch` against the event SHA, and the resulting `Diffs` are classified into added/deleted/renamed/modified by the same rules as the paginated path. ## Consequences * Unconditional use of compare would be simpler and would remove the extra merge-request call, but it pays a memory cost on every event, up to the size of the whole diff, including for the overwhelmingly common case of a small merge request. The truncation check is what prevents that cost on the events that do not need it. * The check costs one extra API call per event and depends on a string convention: if GitLab changes the suffix, truncation is never detected, and the file list is silently short. The failure mode is a missed PipelineRun, not an error. * Both paths must keep classifying files identically, or the same merge request gets a different file list depending on its size.