Skip to content

Fix the relationship between merge request and pipelines

Shinya Maeda requested to merge refactor-merge-request-pipeline-relations into master

What does this MR do?

This MR fixes the relationship between merge request and pipelines by explicitly defining association and scope names.

Today, there are many ambiguous relation names in Ci::Pipeline and Ci::Build. You would have no idea if you don't see the comments on each association.

Ci::Pipeline#merge_request ... Returns a merge request as the merge request pipeline
Ci::Pipeline#merge_requests ... Returns merge requests as the head pipeline
Ci::Pipeline#all_merge_requests ... Returns merge requests referred to the indeterministic pipeline
Ci::Pipeline.for_merge_request ... Returns pipelines for the merge request
Ci::Build#merge_request ... Returns a merge request referred to the indeterministic pipeline (Duplicated)

And, actually, some of them are misbehaving. For example, Ci::Pipeline#merge_request and Ci::Build#merge_request returns totally different thing.

This MR also lets the for_merge_request scope to support merge request pipelines. Thus, https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/9622 can simply focus on the pipeline creation without concerning these scopes and head pipeline update process.

What are the relevant issue numbers?

Related: https://gitlab.com/gitlab-org/gitlab-ee/issues/7380

Does this MR meet the acceptance criteria?

Edited by Shinya Maeda

Merge request reports