Skip to content

Commit

Permalink
Make .call readable
Browse files Browse the repository at this point in the history
.call is where the action happens, no need to move some of it into
a separate methods. Only makes this harder to follow.
  • Loading branch information
hennevogel committed Aug 29, 2023
1 parent 814ffe2 commit 434ee2e
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/api/app/models/workflow/step/link_package_step.rb
Expand Up @@ -14,21 +14,17 @@ def call
destroy_target_project
elsif scm_webhook.reopened_pull_request?
restore_target_project
else
link_package
elsif scm_webhook.new_commit_event?
create_target_package
create_link
Workflows::ScmEventSubscriptionCreator.new(token, workflow_run, scm_webhook, target_package).call

target_package
end
end

private

def link_package
create_target_package if webhook_event_for_linking_or_branching?

Workflows::ScmEventSubscriptionCreator.new(token, workflow_run, scm_webhook, target_package).call

target_package
end

def target_project_base_name
step_instructions[:target_project]
end
Expand All @@ -38,17 +34,10 @@ def target_project
end

def create_target_package
create_project_and_package
return if scm_synced?
return if target_package.present?

create_link
end

def create_project_and_package
check_source_access

raise PackageAlreadyExists, "Can not link package. The package #{target_package_name} already exists." if target_package.present?

if target_project.nil?
project = Project.new(name: target_project_name)
Pundit.authorize(@token.executor, project, :create?)
Expand All @@ -75,8 +64,6 @@ def create_link
target_package_name,
@token.executor,
link_xml(project: source_project_name, package: source_package_name))

target_package
end

def link_xml(opts = {})
Expand Down

0 comments on commit 434ee2e

Please sign in to comment.