--- title: "ADR 0040: GitLab project IDs travel to the watcher through PipelineRun annotations" --- * Status: accepted * Code: [`pkg/provider/gitlab/gitlab.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/gitlab/gitlab.go), [`pkg/kubeinteraction/labels.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/kubeinteraction/labels.go), [`pkg/reconciler/event.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/reconciler/event.go) ## Context Two processes build the same `info.Event` for a GitLab merge request: * the controller, from the webhook payload, where `gl.ParseWebhook` fills `SourceProjectID` and `TargetProjectID`. * the watcher, which reconciles a `PipelineRun` it never saw the webhook for. It reconstructs the event from the `PipelineRun`'s annotations and creates a fresh provider through `SetClient`. The source project is not derivable from the target project. On a fork merge request they are different projects, and `gitlab.com/org/repo` cannot be turned into `gitlab.com/fork-owner/repo` by rewriting an ID. Without the source ID the watcher cannot post a status to the fork, cannot read the fork's `.tekton` directory, and cannot report "source repository inaccessible" against the right project. ## Decision * `pkg/kubeinteraction/labels.go` writes `pipelinesascode.tekton.dev/source-project-id` on the `PipelineRun` whenever `event.SourceProjectID` is non-zero. * `pkg/reconciler/event.go` reads that annotation back into `event.SourceProjectID` when it rebuilds the event. * `SetClient` copies `runevent.SourceProjectID` and `runevent.TargetProjectID` into the provider only when its own field is still zero (`v.sourceProjectID == 0 && runevent.SourceProjectID > 0`). A value set during webhook handling wins over the annotation, and re-initialising the same provider does not overwrite it. ## Consequences * The watcher depends on an annotation being present. A `PipelineRun` created before the annotation existed, or created by something other than PAC, has no source ID and the watcher falls back to the target project. * The annotation is written only for non-zero source IDs, so a GitLab event whose source project is unknown looks the same as a same-project merge request. * Any new provider field that the watcher needs must be given the same treatment: written to an annotation at creation, restored from it, and assigned in `SetClient` only when unset. The `if v.field == 0` guard is what makes the two paths agree.