Skip to content

Persist source sha and target sha for merge pipelines

What does this MR do?

This MR let CreatePipelineService persist target_sha and source_sha. target_sha stores the SHA of the HEAD of the target branch of the merge request. source_sha stores the SHA of the HEAD of the source branch of the merge request.

This MR also introduces a few helper methods with these values.

Test in EE => https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/9739

Expected usage

## How to create a detached pipeline?
CreatePipelineService.new(project, user, ref: "refs/merge-requests/iid/head", checkout_sha: merge_request.source_branch_sha)
                     .execute(:merge_request, merge_request: merge_request)

## How to create a merge pipeline?
CreatePipelineService.new(project, user, ref: "refs/merge-requests/iid/merge", checkout_sha: merge_sha, source_sha: merge_request.diff_head_sha, target_sha: merge_request.target_branch_sha)
                     .execute(:merge_request, merge_request: merge_request)

## How to evaluate if it's a detached pipeline?
pipeline.merge_request? && pipeline.target_sha.nil?

## How to evaluate if it's a merge pipeline?
pipeline.merge_request? && pipeline.target_sha.present?

## How to evaluate if the merge pipeline uses HEAD of target branch (If false, don't merge)?
pipeline.merge_request? && pipeline.target_sha == merge_request.target_branch_sha

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

Loading