Skip to content

Backend: Refactor Rules::Rule::Clause classes to avoid needing to pass down `context`

Summary

The following discussion from !148356 (merged) should be addressed:

  • @lma-git started a discussion: (+1 comment)

    I think these clause classes should be refactored so that they don't require passing down context everywhere (perhaps a follow-up issue?). But for now, I've continued with this pattern so that the code changes are as minimal as possible. Wdyt?

Proposal

Refactor Gitlab::Ci::Build::Rules::Rule::Clause classes so that instead of passing the context into satisfied_by?, we pass it into the initializer and set attr_reader: :context. This allows us to avoid passing down context into every downstream method.

Note: For Rules::Rule::Clause::Exists, instead of setting attr_reader: :context, we should define a def context private method because the context is modified at this line. def context should return either the original or modified context depending on whether @project_path is present, and it should be memoized.

Edited by Leaminn Ma