Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 04:45:44 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 04:45:44 +0300
commit85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch)
tree9160f299afd8c80c038f08e1545be119f5e3f1e1 /lib/gitlab/static_site_editor
parent15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff)
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'lib/gitlab/static_site_editor')
-rw-r--r--lib/gitlab/static_site_editor/config.rb63
-rw-r--r--lib/gitlab/static_site_editor/config/file_config.rb15
-rw-r--r--lib/gitlab/static_site_editor/config/generated_config.rb70
3 files changed, 85 insertions, 63 deletions
diff --git a/lib/gitlab/static_site_editor/config.rb b/lib/gitlab/static_site_editor/config.rb
deleted file mode 100644
index d335a434335..00000000000
--- a/lib/gitlab/static_site_editor/config.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module StaticSiteEditor
- class Config
- SUPPORTED_EXTENSIONS = %w[.md].freeze
-
- def initialize(repository, ref, file_path, return_url)
- @repository = repository
- @ref = ref
- @file_path = file_path
- @return_url = return_url
- @commit_id = repository.commit(ref)&.id if ref
- end
-
- def payload
- {
- branch: ref,
- path: file_path,
- commit_id: commit_id,
- project_id: project.id,
- project: project.path,
- namespace: project.namespace.full_path,
- return_url: sanitize_url(return_url),
- is_supported_content: supported_content?.to_s,
- base_url: Gitlab::Routing.url_helpers.project_show_sse_path(project, full_path)
- }
- end
-
- private
-
- attr_reader :repository, :ref, :file_path, :return_url, :commit_id
-
- delegate :project, to: :repository
-
- def supported_content?
- master_branch? && extension_supported? && file_exists?
- end
-
- def master_branch?
- ref == 'master'
- end
-
- def extension_supported?
- return true if file_path.end_with?('.md.erb') && Feature.enabled?(:sse_erb_support, project)
-
- SUPPORTED_EXTENSIONS.any? { |ext| file_path.end_with?(ext) }
- end
-
- def file_exists?
- commit_id.present? && !repository.blob_at(commit_id, file_path).nil?
- end
-
- def full_path
- "#{ref}/#{file_path}"
- end
-
- def sanitize_url(url)
- url if Gitlab::UrlSanitizer.valid_web?(url)
- end
- end
- end
-end
diff --git a/lib/gitlab/static_site_editor/config/file_config.rb b/lib/gitlab/static_site_editor/config/file_config.rb
new file mode 100644
index 00000000000..f647c85e1c8
--- /dev/null
+++ b/lib/gitlab/static_site_editor/config/file_config.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module StaticSiteEditor
+ module Config
+ class FileConfig
+ def data
+ {
+ static_site_generator: 'middleman'
+ }
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/static_site_editor/config/generated_config.rb b/lib/gitlab/static_site_editor/config/generated_config.rb
new file mode 100644
index 00000000000..f3dce74a32f
--- /dev/null
+++ b/lib/gitlab/static_site_editor/config/generated_config.rb
@@ -0,0 +1,70 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module StaticSiteEditor
+ module Config
+ class GeneratedConfig
+ SUPPORTED_EXTENSIONS = %w[.md].freeze
+
+ def initialize(repository, ref, path, return_url)
+ @repository = repository
+ @ref = ref
+ @path = path
+ @return_url = return_url
+ end
+
+ def data
+ merge_requests_illustration_path = ActionController::Base.helpers.image_path('illustrations/merge_requests.svg')
+ {
+ branch: ref,
+ path: path,
+ commit_id: commit_id,
+ project_id: project.id,
+ project: project.path,
+ namespace: project.namespace.full_path,
+ return_url: sanitize_url(return_url),
+ is_supported_content: supported_content?.to_s,
+ base_url: Gitlab::Routing.url_helpers.project_show_sse_path(project, full_path),
+ merge_requests_illustration_path: merge_requests_illustration_path
+ }
+ end
+
+ private
+
+ attr_reader :repository, :ref, :path, :return_url
+
+ delegate :project, to: :repository
+
+ def commit_id
+ repository.commit(ref)&.id if ref
+ end
+
+ def supported_content?
+ master_branch? && extension_supported? && file_exists?
+ end
+
+ def master_branch?
+ ref == 'master'
+ end
+
+ def extension_supported?
+ return true if path.end_with?('.md.erb') && Feature.enabled?(:sse_erb_support, project)
+
+ SUPPORTED_EXTENSIONS.any? { |ext| path.end_with?(ext) }
+ end
+
+ def file_exists?
+ commit_id.present? && !repository.blob_at(commit_id, path).nil?
+ end
+
+ def full_path
+ "#{ref}/#{path}"
+ end
+
+ def sanitize_url(url)
+ url if Gitlab::UrlSanitizer.valid_web?(url)
+ end
+ end
+ end
+ end
+end