Skip to content

Ci::Pipeline factories for the various kinds of merge request pipelines

drew stachon requested to merge mr-pipeline-factory-traits into master

What does this MR do?

This MR creates FactoryBot traits for Ci::Pipeline allowing us to represent three kinds of merge request pipelines. There are currently MergeRequest factory traits that do this setup, and for a Ci::Pipeline a developer has to go through the MergeRequest factory, which can make constructing particular merge request pipelines difficult.

For example, it's not currently simple to create a Ci::Build in a merge request pipeline. We have a trait :with_job for pipelines, but it can't be used directly with merge request factories.

Instead of:

FactoryBot.create(:merge_request, :with_detached_merge_request_pipeline).yield_self |merge_request|
  FactoryBot.create(:ci_build, pipeline: pipeline, project: pipeline.project).tap do |ci_build|
    merge_request.all_pipelines.last.builds << ci_build
  end
end

we can simply write

FactoryBot.create(:ci_pipeline, :detached_merge_request, :with_job)

The existing MergeRequest factories continue to work in exactly the same way, but use the new Ci::Pipeline factory traits.

Given that this MR only refactors existing test factories, I made the changes and tested them by not changing any existing tests. All tests continue to pass as expected.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • ~~Label as security and @ mention @gitlab-com/gl-security/appsec~~
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by drew stachon

Merge request reports