diff options
author | drew cimino <dcimino@gitlab.com> | 2019-07-30 00:36:47 +0300 |
---|---|---|
committer | drew cimino <dcimino@gitlab.com> | 2019-07-30 00:36:47 +0300 |
commit | fe58cf598d60a8a64aa19315350c3ed552ca4f06 (patch) | |
tree | e70a631d75e23d462b8f02f5e863b801cc9a76a8 | |
parent | 88c8f0ba1dbed894fff32a650052e6d840e9a1e3 (diff) |
Break out refs keyword matching into separate methods of Build::Policy::Refs
-rw-r--r-- | lib/gitlab/ci/build/policy/refs.rb | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/gitlab/ci/build/policy/refs.rb b/lib/gitlab/ci/build/policy/refs.rb index c3005303fd8..55aaa36f835 100644 --- a/lib/gitlab/ci/build/policy/refs.rb +++ b/lib/gitlab/ci/build/policy/refs.rb @@ -27,11 +27,26 @@ module Gitlab end def matches_pattern?(pattern, pipeline) - return true if pipeline.tag? && pattern == 'tags' - return true if pipeline.branch? && pattern == 'branches' - return true if sanitized_source_name(pipeline) == pattern - return true if sanitized_source_name(pipeline)&.pluralize == pattern + matches_tags_keyword?(pattern, pipeline) || + matches_branches_keyword?(pattern, pipeline) || + matches_pipeline_source?(pattern, pipeline) || + matches_single_ref?(pattern, pipeline) + end + + def matches_tags_keyword?(pattern, pipeline) + pipeline.tag? && pattern == 'tags' + end + + def matches_branches_keyword?(pattern, pipeline) + pipeline.branch? && pattern == 'branches' + end + + def matches_pipeline_source?(pattern, pipeline) + sanitized_source_name(pipeline) == pattern || + sanitized_source_name(pipeline)&.pluralize == pattern + end + def matches_single_ref?(pattern, pipeline) # patterns can be matched only when branch or tag is used # the pattern matching does not work for merge requests pipelines if pipeline.branch? || pipeline.tag? @@ -44,6 +59,8 @@ module Gitlab end def sanitized_source_name(pipeline) + # TODO Memoizing this doesn't seem to make sense with + # pipelines being passed in to #satsified_by? as a param. @sanitized_source_name ||= pipeline&.source&.delete_suffix('_event') end end |