From fa3e2b08cad9974d3e0d85f764588cfc311df36c Mon Sep 17 00:00:00 2001 From: Eduardo Navarro Date: Mon, 24 Feb 2025 18:41:15 +0100 Subject: [PATCH] Parse workflow's branch filters as strings --- src/api/app/models/workflow.rb | 16 ++++++++++++---- ...quest_payload_github_pull_request_opened.json | 2 +- src/api/spec/models/workflow_spec.rb | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/api/app/models/workflow.rb b/src/api/app/models/workflow.rb index bde96db3a71..e916d079f5c 100644 --- a/src/api/app/models/workflow.rb +++ b/src/api/app/models/workflow.rb @@ -104,15 +104,23 @@ def event_matches_event_filter? def branch_matches_branches_filter? return true unless supported_filters.key?(:branches) - branches_only = filters[:branches].fetch(:only, []) - branches_ignore = filters[:branches].fetch(:ignore, []) + return true if branch_matches_branches_only_filter? - return true if branches_only.present? && branches_only.include?(workflow_run.target_branch) - return true if branches_ignore.present? && branches_ignore.exclude?(workflow_run.target_branch) + return true if branch_matches_branches_ignore_filter? false end + def branch_matches_branches_only_filter? + branches_only = filters[:branches].fetch(:only, []).map(&:to_s) + branches_only.present? && branches_only.include?(workflow_run.target_branch) + end + + def branch_matches_branches_ignore_filter? + branches_ignore = filters[:branches].fetch(:ignore, []).map(&:to_s) + branches_ignore.present? && branches_ignore.exclude?(workflow_run.target_branch) + end + # rubocop:disable Metrics/CyclomaticComplexity # Execute only if labeled or unlabeled def label_matches_labels_filter? diff --git a/src/api/spec/fixtures/files/request_payload_github_pull_request_opened.json b/src/api/spec/fixtures/files/request_payload_github_pull_request_opened.json index 6769741cc34..97ccae1d458 100644 --- a/src/api/spec/fixtures/files/request_payload_github_pull_request_opened.json +++ b/src/api/spec/fixtures/files/request_payload_github_pull_request_opened.json @@ -5,7 +5,7 @@ "number": 1, "html_url": "http://github.com/something", "base": { - "ref": "master", + "ref": "16.0", "repo": { "full_name": "openSUSE/repo123" } diff --git a/src/api/spec/models/workflow_spec.rb b/src/api/spec/models/workflow_spec.rb index dbaaef5ecf4..42af29ca5d0 100644 --- a/src/api/spec/models/workflow_spec.rb +++ b/src/api/spec/models/workflow_spec.rb @@ -204,7 +204,7 @@ context 'when the webhook event is against one of the branches in the branches/only filters' do let(:yaml) do { 'steps' => [{ 'branch_package' => { 'source_project' => 'test-project', 'source_package' => 'test-package' } }], - 'filters' => { 'branches' => { 'only' => %w[master develop] } } } + 'filters' => { 'branches' => { 'only' => [16.0, 'develop'] } } } end let(:request_payload) { file_fixture('request_payload_github_pull_request_opened.json').read } let!(:workflow_run) { create(:workflow_run, scm_vendor: 'github', hook_event: 'pull_request', hook_action: 'opened', token: token, request_payload: request_payload) }