debian-mirror-gitlab/lib/bulk_imports/common/pipelines/wiki_pipeline.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.5 KiB
Ruby
Raw Normal View History

2021-12-11 22:18:48 +05:30
# frozen_string_literal: true
module BulkImports
module Common
module Pipelines
class WikiPipeline
include Pipeline
def extract(*)
2022-01-26 12:08:38 +05:30
url = url_from_parent_path(context.entity.source_full_path) if source_wiki_exists?
BulkImports::Pipeline::ExtractedData.new(data: { url: url })
2021-12-11 22:18:48 +05:30
end
def transform(_, data)
data&.slice(:url)
end
def load(context, data)
2022-01-26 12:08:38 +05:30
return unless data&.dig(:url)
2021-12-11 22:18:48 +05:30
2022-01-26 12:08:38 +05:30
wiki = context.portable.wiki
2021-12-11 22:18:48 +05:30
url = data[:url].sub("://", "://oauth2:#{context.configuration.access_token}@")
Gitlab::UrlBlocker.validate!(url, allow_local_network: allow_local_requests?, allow_localhost: allow_local_requests?)
2022-01-26 12:08:38 +05:30
wiki.ensure_repository
wiki.repository.fetch_as_mirror(url)
2021-12-11 22:18:48 +05:30
end
private
def url_from_parent_path(parent_path)
wiki_path = parent_path + ".wiki.git"
root = context.configuration.url
Gitlab::Utils.append_path(root, wiki_path)
end
def allow_local_requests?
Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
end
2022-01-26 12:08:38 +05:30
def source_wiki_exists?
wikis = client.get(context.entity.wikis_url_path).parsed_response
wikis.any?
end
def client
BulkImports::Clients::HTTP.new(url: context.configuration.url, token: context.configuration.access_token)
end
2021-12-11 22:18:48 +05:30
end
end
end
end