Skip to content

Commit

Permalink
Replace source_project by project in ConfigureRepositoriesStep
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
saraycp committed Sep 16, 2021
1 parent ee90b19 commit 371a988
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
5 changes: 0 additions & 5 deletions src/api/app/models/workflow/step.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/api/app/models/workflow/step/branch_package_step.rb
Original file line number Diff line number Diff line change
@@ -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 = {})
Expand All @@ -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 = {})
Expand Down
7 changes: 6 additions & 1 deletion src/api/app/models/workflow/step/configure_repositories.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -22,6 +23,10 @@ def call(_options = {})
end
end

def project_name
step_instructions[:project]
end

private

def validate_repositories
Expand Down
6 changes: 6 additions & 0 deletions src/api/app/models/workflow/step/link_package_step.rb
Original file line number Diff line number Diff line change
@@ -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 = {})
Expand All @@ -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 = {})
Expand Down
20 changes: 10 additions & 10 deletions src/api/spec/models/workflow/step/configure_repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
[
{
Expand Down Expand Up @@ -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:
[
{
Expand All @@ -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:
[
{
Expand All @@ -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:
[
{
Expand All @@ -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:
[
{
Expand Down Expand Up @@ -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:
[
{
Expand All @@ -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:
[
{
Expand Down Expand Up @@ -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:
[
{
Expand Down
8 changes: 4 additions & 4 deletions src/api/spec/models/workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 371a988

Please sign in to comment.