Merge request should fetch base pipeline from target branch
Summary
A Merge Request fetches the base pipeline, which is the pipeline executed on the base commit sha, to gather informations from the target branch and compare them with the corresponding ones from the source branch.
For example, the Security Reports or Test Reports are comparing results between target and source branch to display relevant information in merge requests widgets, like how many vulnerabilities where added or fixed.
Though, current implementation of base_pipeline
looks for the latest pipeline executed for the base commit sha, but without caring about the ref
. In some cases this can lead to fetch a base pipeline from a different branch than the target branch of the merge request.
Steps to reproduce
-
master
is at commitA
. Pipeline1
runs for commitA
. - create a branch
feature_one
frommaster
, create a new commitB
and push. Pipeline2
runs for commitB
. - create a Merge Request to merge
feature
intomaster
.base_pipeline
is1
, which is correct. - create a branch
feature_two
frommaster
, push it without any other commit, pipeline3
runs for commitA
. - now
base_pipeline
is3
for the Merge Request.
Example Project
https://staging.gitlab.com/secure-team-test/spring-app-secure/merge_requests/1
What is the current bug behavior?
Merge Request base_pipeline
returns the latest pipeline (highest ID) executed for the base commit sha.
What is the expected correct behavior?
Merge Request base_pipeline
returns the latest pipeline (highest ID) executed for the base commit sha and for the target_branch.
Output of checks
This bug happens on GitLab.com
Possible fixes
Add a where clause to fetch only pipelines from the target branch.