From 371a98895050bdb13506f112e8297793deacaf30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saray=20Cabrera=20Padr=C3=B3n?= Date: Wed, 15 Sep 2021 18:42:18 +0200 Subject: [PATCH 1/2] Replace source_project by project in ConfigureRepositoriesStep As a consequence, the 'source_project_name' is no longer required for the three types of steps (BranchPackageStep, LinkPackageStep, ConfigureRepositoriesStep). So the validation and definition of the method are moved to the two first steps. On the third one, a new method 'project_name' and its validation is defined inside ConfigureRepositoriesStep. --- src/api/app/models/workflow/step.rb | 5 ----- .../workflow/step/branch_package_step.rb | 6 ++++++ .../workflow/step/configure_repositories.rb | 7 ++++++- .../models/workflow/step/link_package_step.rb | 6 ++++++ .../step/configure_repositories_spec.rb | 20 +++++++++---------- src/api/spec/models/workflow_spec.rb | 8 ++++---- 6 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/api/app/models/workflow/step.rb b/src/api/app/models/workflow/step.rb index 3257034404a..90d8eddc587 100644 --- a/src/api/app/models/workflow/step.rb +++ b/src/api/app/models/workflow/step.rb @@ -1,7 +1,6 @@ class Workflow::Step include ActiveModel::Model - validates :source_project_name, presence: true validate :validate_step_instructions attr_accessor :scm_webhook, :step_instructions, :token @@ -44,10 +43,6 @@ def validate_step_instructions end end - def source_project_name - step_instructions[:source_project] - end - def source_package_name step_instructions[:source_package] end diff --git a/src/api/app/models/workflow/step/branch_package_step.rb b/src/api/app/models/workflow/step/branch_package_step.rb index 68115e704eb..b298acda904 100644 --- a/src/api/app/models/workflow/step/branch_package_step.rb +++ b/src/api/app/models/workflow/step/branch_package_step.rb @@ -1,5 +1,7 @@ class Workflow::Step::BranchPackageStep < ::Workflow::Step REQUIRED_KEYS = [:source_project, :source_package].freeze + + validates :source_project_name, presence: true validates :source_package_name, presence: true def call(options = {}) @@ -9,6 +11,10 @@ def call(options = {}) branch_package(workflow_filters) end + def source_project_name + step_instructions[:source_project] + end + private def branch_package(workflow_filters = {}) diff --git a/src/api/app/models/workflow/step/configure_repositories.rb b/src/api/app/models/workflow/step/configure_repositories.rb index 1b1f4cb796f..2b24db4476d 100644 --- a/src/api/app/models/workflow/step/configure_repositories.rb +++ b/src/api/app/models/workflow/step/configure_repositories.rb @@ -1,7 +1,8 @@ class Workflow::Step::ConfigureRepositories < Workflow::Step - REQUIRED_KEYS = [:source_project, :repositories].freeze + REQUIRED_KEYS = [:project, :repositories].freeze REQUIRED_REPOSITORY_KEYS = [:architectures, :name, :target_project, :target_repository].freeze + validates :project_name, presence: true validate :validate_repositories validate :validate_architectures @@ -22,6 +23,10 @@ def call(_options = {}) end end + def project_name + step_instructions[:project] + end + private def validate_repositories diff --git a/src/api/app/models/workflow/step/link_package_step.rb b/src/api/app/models/workflow/step/link_package_step.rb index bea003e7468..ba4a2f4d0ac 100644 --- a/src/api/app/models/workflow/step/link_package_step.rb +++ b/src/api/app/models/workflow/step/link_package_step.rb @@ -1,5 +1,7 @@ class Workflow::Step::LinkPackageStep < ::Workflow::Step REQUIRED_KEYS = [:source_project, :source_package].freeze + + validates :source_project_name, presence: true validates :source_package_name, presence: true def call(options = {}) @@ -9,6 +11,10 @@ def call(options = {}) link_package(workflow_filters) end + def source_project_name + step_instructions[:source_project] + end + private def link_package(workflow_filters = {}) diff --git a/src/api/spec/models/workflow/step/configure_repositories_spec.rb b/src/api/spec/models/workflow/step/configure_repositories_spec.rb index f94f937b608..492c919e2fc 100644 --- a/src/api/spec/models/workflow/step/configure_repositories_spec.rb +++ b/src/api/spec/models/workflow/step/configure_repositories_spec.rb @@ -12,7 +12,7 @@ let(:target_project) { create(:project, name: target_project_name) } let(:step_instructions) do { - source_project: 'OBS:Server:Unstable', + project: 'OBS:Server:Unstable', repositories: [ { @@ -83,7 +83,7 @@ context 'and there is no source project in the configuration file' do let(:step_instructions) do { - project: 'OBS:Server:Unstable', + fake_project: 'OBS:Server:Unstable', repositories: [ { @@ -109,16 +109,16 @@ expect { subject.call({}) }.not_to change(Architecture, :count) end - it 'a validation fails complaining about a missing source project' do + it 'a validation fails complaining about a missing project' do subject.call - expect(subject.errors.full_messages).to include("Source project name can't be blank") + expect(subject.errors.full_messages).to include("Project name can't be blank") end end context 'and there is no target project defined in the repository definition' do let(:step_instructions) do { - source_project: 'OBS:Server:Unstable', + project: 'OBS:Server:Unstable', repositories: [ { @@ -143,7 +143,7 @@ context 'and there is no target repository in the repository definition' do let(:step_instructions) do { - source_project: 'OBS:Server:Unstable', + project: 'OBS:Server:Unstable', repositories: [ { @@ -168,7 +168,7 @@ context 'and the target repository already exist in the database' do let(:step_instructions) do { - source_project: 'OBS:Server:Unstable', + project: 'OBS:Server:Unstable', repositories: [ { @@ -196,7 +196,7 @@ context 'and there are no architectures in the repository definition' do let(:step_instructions) do { - source_project: 'OBS:Server:Unstable', + project: 'OBS:Server:Unstable', repositories: [ { @@ -218,7 +218,7 @@ context "and the architectures in the repository definition don't exist" do let(:step_instructions) do { - source_project: 'OBS:Server:Unstable', + project: 'OBS:Server:Unstable', repositories: [ { @@ -254,7 +254,7 @@ context 'when there is no target project in the database' do let(:step_instructions) do { - source_project: 'OBS:Server:Unstable', + project: 'OBS:Server:Unstable', repositories: [ { diff --git a/src/api/spec/models/workflow_spec.rb b/src/api/spec/models/workflow_spec.rb index 35c0017a2ea..b828c15316a 100644 --- a/src/api/spec/models/workflow_spec.rb +++ b/src/api/spec/models/workflow_spec.rb @@ -142,8 +142,8 @@ it 'sets validation errors' do expect(subject.errors.full_messages).to match_array( - ["Invalid workflow step definition: Source project name can't be blank, The 'source_project' key is missing, The 'source_package' key is missing, \ -and Source package name can't be blank"] + ["Invalid workflow step definition: The 'source_project' key is missing, The 'source_package' key is missing, \ +Source project name can't be blank, and Source package name can't be blank"] ) end end @@ -169,8 +169,8 @@ it 'sets validation errors' do expect(subject.errors.full_messages).to match_array( - ["Invalid workflow step definition: unsupported_step_1 is not a supported step, Source project name can't be blank, \ -The 'source_package' key is missing, and Source package name can't be blank"] + ["Invalid workflow step definition: unsupported_step_1 is not a supported step, The 'source_package' key is missing, \ +Source project name can't be blank, and Source package name can't be blank"] ) end end From 5f3dd0977da91e68c42425d3ec2b2ce51c6e5605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saray=20Cabrera=20Padr=C3=B3n?= Date: Wed, 15 Sep 2021 18:49:34 +0200 Subject: [PATCH 2/2] Overwite target_project_name for ConfigureRepositoriesStep As the method 'target_project_name' is based on the 'source_project_name' only for BranchPackageStep and LinkPackageStep but not for ConfigureRepositories, the method is now re-defined inside ConfigureRepositoriesStep. --- src/api/app/models/workflow/step/configure_repositories.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/api/app/models/workflow/step/configure_repositories.rb b/src/api/app/models/workflow/step/configure_repositories.rb index 2b24db4476d..f1387c9102d 100644 --- a/src/api/app/models/workflow/step/configure_repositories.rb +++ b/src/api/app/models/workflow/step/configure_repositories.rb @@ -27,6 +27,10 @@ def project_name step_instructions[:project] end + def target_project_name + "home:#{@token.user.login}:#{project_name}:PR-#{scm_webhook.payload[:pr_number]}" + end + private def validate_repositories