Skip to content

Commit

Permalink
Merge pull request #11645 from krauselukas/workflows/support_target_p…
Browse files Browse the repository at this point in the history
…roject

Support target_project key for branch and link package step
  • Loading branch information
krauselukas committed Sep 24, 2021
2 parents 5d0ce41 + 7054e6a commit dcefc2d
Show file tree
Hide file tree
Showing 117 changed files with 12,186 additions and 14,795 deletions.
34 changes: 12 additions & 22 deletions src/api/.rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 100`
# on 2021-09-15 13:59:50 UTC using RuboCop version 1.20.0.
# on 2021-09-22 12:19:08 UTC using RuboCop version 1.21.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -128,7 +128,7 @@ Lint/UselessMethodDefinition:
- 'app/services/consistency_check_job_service/project_consistency_checker.rb'
- 'test/test_helper.rb'

# Offense count: 817
# Offense count: 820
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 235
Expand All @@ -147,7 +147,7 @@ Metrics/BlockNesting:
- 'lib/xpath_engine.rb'
- 'test/node_matcher.rb'

# Offense count: 80
# Offense count: 81
# Configuration parameters: CountComments, Max, CountAsOne.
Metrics/ClassLength:
Exclude:
Expand Down Expand Up @@ -198,6 +198,7 @@ Metrics/ClassLength:
- 'app/models/staging/workflow.rb'
- 'app/models/user.rb'
- 'app/models/user_ldap_strategy.rb'
- 'app/models/workflow/step.rb'
- 'app/services/user_service/involved.rb'
- 'lib/xpath_engine.rb'
- 'test/functional/attributes_test.rb'
Expand Down Expand Up @@ -323,7 +324,7 @@ Metrics/CyclomaticComplexity:
- 'test/functional/zzz_post_consistency_test.rb'
- 'test/node_matcher.rb'

# Offense count: 914
# Offense count: 912
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 227
Expand Down Expand Up @@ -465,17 +466,6 @@ Naming/HeredocDelimiterNaming:
- 'test/functional/source_controller_test.rb'
- 'test/unit/project_test.rb'

# Offense count: 14
# Configuration parameters: CheckIdentifiers, CheckConstants, CheckVariables, CheckStrings, CheckSymbols, CheckComments, CheckFilepaths, FlaggedTerms.
Naming/InclusiveLanguage:
Exclude:
- 'app/controllers/announcements_controller.rb'
- 'app/controllers/webui/attribute_controller.rb'
- 'app/lib/backend/connection_helper.rb'
- 'app/models/relationship.rb'
- 'config/initializers/airbrake.rb'
- 'db/migrate/20170821110838_remove_blacklist_tags.rb'

# Offense count: 2
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Expand Down Expand Up @@ -667,7 +657,7 @@ RSpec/AnyInstance:
- 'spec/models/project_spec.rb'
- 'spec/policies/package_policy_spec.rb'

# Offense count: 938
# Offense count: 955
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Expand Down Expand Up @@ -776,7 +766,7 @@ RSpec/IteratedExpectation:
Exclude:
- 'spec/models/user_spec.rb'

# Offense count: 322
# Offense count: 323
# Cop supports --auto-correct.
RSpec/LeadingSubject:
Enabled: false
Expand All @@ -789,7 +779,7 @@ RSpec/MessageSpies:
- 'spec/controllers/webui/apidocs_controller_spec.rb'
- 'spec/models/kiwi/image_spec.rb'

# Offense count: 1420
# Offense count: 1421
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 27
Expand Down Expand Up @@ -1094,7 +1084,7 @@ Style/ConditionalAssignment:
Exclude:
- 'app/models/bs_request_action_submit.rb'

# Offense count: 712
# Offense count: 715
# Configuration parameters: AllowedConstants.
Style/Documentation:
Enabled: false
Expand All @@ -1106,7 +1096,7 @@ Style/ExplicitBlockArgument:
- 'app/lib/backend/connection.rb'
- 'app/models/project.rb'

# Offense count: 1481
# Offense count: 1487
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Expand Down Expand Up @@ -1203,9 +1193,9 @@ Style/SymbolArray:
Style/WordArray:
Enabled: false

# Offense count: 1956
# Offense count: 1960
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 187
10 changes: 9 additions & 1 deletion src/api/app/models/workflow/step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ def call(_options)
end

def target_project_name
"home:#{@token.user.login}:#{source_project_name}:PR-#{scm_webhook.payload[:pr_number]}"
return step_instructions[:target_project] if scm_webhook.push_event?

pr_subproject_name = if scm_webhook.payload[:scm] == 'github'
scm_webhook.payload[:target_repository_full_name].tr('/', ':')
else
scm_webhook.payload[:path_with_namespace].tr('/', ':')
end

"#{step_instructions[:target_project]}:#{pr_subproject_name}:PR-#{scm_webhook.payload[:pr_number]}"
end

def target_package
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/workflow/step/branch_package_step.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Workflow::Step::BranchPackageStep < ::Workflow::Step
REQUIRED_KEYS = [:source_project, :source_package].freeze
REQUIRED_KEYS = [:source_project, :source_package, :target_project].freeze

def call(options = {})
return unless valid?
Expand Down
8 changes: 6 additions & 2 deletions src/api/app/models/workflow/step/link_package_step.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Workflow::Step::LinkPackageStep < ::Workflow::Step
REQUIRED_KEYS = [:source_project, :source_package].freeze
REQUIRED_KEYS = [:source_project, :source_package, :target_project].freeze

def call(options = {})
return unless valid?
Expand Down Expand Up @@ -35,12 +35,16 @@ def create_project_and_package
raise PackageAlreadyExists, "Can not link package. The package #{target_package_name} already exists." if target_package.present?

if target_project.nil?
project = Project.create!(name: target_project_name)
project = Project.new(name: target_project_name)
Pundit.authorize(@token.user, project, :create?)

project.save!
project.commit_user = User.session
project.relationships.create!(user: User.session, role: Role.find_by_title('maintainer'))
project.store
end

Pundit.authorize(@token.user, target_project, :update?)
target_project.packages.create(name: target_package_name)
end

Expand Down
Loading

0 comments on commit dcefc2d

Please sign in to comment.