Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/api/app/services/workflows/yaml_to_workflows_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def parse_workflow_configuration(workflow_configuration)

# Mapping the placeholder variables to their values from the webhook event payload
placeholder_variables = SUPPORTED_PLACEHOLDER_VARIABLES.zip([scm_organization_name, scm_repository_name, pr_number, commit_sha, label]).to_h
begin
format(workflow_configuration, placeholder_variables)
rescue ArgumentError => e
raise Token::Errors::WorkflowsYamlFormatError, e.message
# Explicit substitution via gsub allows safe use of placeholders
workflow_configuration.gsub(/%\{([A-Za-z0-9_]+)\}/) do |match|
key = Regexp.last_match(1).to_sym
placeholder_variables.fetch(key, match)
end
end

Expand Down
10 changes: 10 additions & 0 deletions src/api/spec/fixtures/files/workflows_with_percent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
workflow_percent:
steps:
- branch_package:
source_project: "test-project:percent"
source_package: "test-package:54%f"
target_project: "test-target-project"
filters:
branches:
only:
- 'main'
15 changes: 13 additions & 2 deletions src/api/spec/services/workflows/yaml_to_workflows_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,19 @@
let(:workflows_yml_file) { file_fixture('unparsable_workflows_placeholders.yml') }
let(:request_payload) { workflow_run_github_payload }

it 'raises a user-friendly error' do
expect { subject }.to raise_error(Token::Errors::WorkflowsYamlNotParsable, 'Unable to parse .obs/workflows.yml: malformed format string - %S')
it 'keeps the original string' do
expect { subject }.not_to raise_error
expect(subject.first.workflow_instructions[:steps].first[:branch_package][:source_package]).to eq('test-package:%u')
end
end

context 'with %f in content' do
let(:workflows_yml_file) { file_fixture('workflows_with_percent.yml') }
let(:request_payload) { workflow_run_github_payload }

it 'does not crash and preserves the %f' do
expect { subject }.not_to raise_error
expect(subject.first.workflow_instructions[:steps].first[:branch_package][:source_package]).to eq('test-package:54%f')
end
end
end
Expand Down