-
Aufar Gilbran authored
Resolves https://gitlab.com/gitlab-org/gitlab-ee/issues/14064. On commit status creation, the controller tries to find pipeline that matches the specified parameters. If 'ref' not is given as parameters, 'ref' will be assigned to branch name that contains 'sha' and pipeline for 'ref' will be searched. If there is an existing pipeline for 'ref', commit status stage is created and appended at the end of the pipeline. Otherwise, it will create a new pipeline for 'ref'. The above behavior is not desirable when the only pipelines available are not for branch. One example of other 'ref' is merge request ref. For these pipelines, the expected value of 'ref' is supposed to be the merge request ref name. For example, merge request with ID 42 will have /refs/merge-requests/42/head as its ref name. Thus, if there are only pipelines for merge requests, unless we pass 'ref' explicitly, it will create a new pipeline for the branch that contains the 'sha' instead of adding the created stage to the existing pipeline for merge requests. This commit change the logic so commit status can be created on any pipelines by default. The goal can be achieved by changing the logic when existing pipeline is searched using the given parameters. First, if 'pipeline_id' is specified, search for pipeline that has the same id as 'pipeline_id'. When 'pipeline_id' is not given, but 'ref' is given, search for pipeline that has the same 'ref' and 'sha' value. Note that 'sha' will always be given. Otherwise, search the latest pipeline that has the same 'sha', which will only returns nil if there is no pipeline created for that particular 'sha'.
f65eda80