Skip to content

Commit

Permalink
Fix scmsync tag creation for packages with query/fragment in the url
Browse files Browse the repository at this point in the history
The SCM workflow creates bogus scmsync URLs when the branched package contains
any query or fragment in its url, because neither the query nor the fragment are
ever removed/modified. Only the new commit is appended as a fragment which can
lead to duplication of the query & fragment.
To fix this, we use the addressable module to override the fragment and set the
`subdir` query via the URI parser instead of doing this ourselves.

This fixes #13290
  • Loading branch information
dcermak committed Nov 3, 2022
1 parent 6a2a92d commit 74e6b15
Show file tree
Hide file tree
Showing 8 changed files with 3,920 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/api/app/models/concerns/scm_sync_enabled_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ module ScmSyncEnabledStep
extend ActiveSupport::Concern

def set_scmsync_on_target_package
updated_scmsync_url = if scmsync_url.include?('subdir=') || scm_synced_project?
"#{scmsync_url}?subdir=#{source_package_name}##{scm_webhook.payload[:commit_sha]}"
else
"#{scmsync_url}##{scm_webhook.payload[:commit_sha]}"
end
target_package.update(scmsync: updated_scmsync_url)
# only change the fragment here and leave the query alone!
parsed_scmsync_url = Addressable::URI.parse(scmsync_url)
parsed_scmsync_url.fragment = scm_webhook.payload[:commit_sha]

# if we use scmsync to sync a whole project, then each package will be
# fetched from a subdirectory
if scm_synced_project?
query = parsed_scmsync_url.query_values || {}
query['subdir'] = source_package_name
parsed_scmsync_url.query_values = query
end

target_package.update(scmsync: parsed_scmsync_url.to_s)
end

def scm_synced?
Expand Down

0 comments on commit 74e6b15

Please sign in to comment.