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

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAchilleas Pipinellis <axil@gitlab.com>2022-06-22 15:53:38 +0300
committerAchilleas Pipinellis <axil@gitlab.com>2022-06-22 15:53:38 +0300
commit5d5fe32fd1c68f182acfe889038af859d381c911 (patch)
tree54a521b01d5e39aae7b72c1f176a80a2a293ba73 /lib/helpers/edit_on_gitlab.rb
parent7825d0a148c3650885377de1d3126274e44fcef7 (diff)
parent98162b5fe38fdbb8533f32a23e9332ffee53b143 (diff)
Merge branch 'bwill/refactor-edit-on-gitlab' into 'main'
Refactor edit_on_gitlab helper See merge request gitlab-org/gitlab-docs!2845
Diffstat (limited to 'lib/helpers/edit_on_gitlab.rb')
-rw-r--r--lib/helpers/edit_on_gitlab.rb93
1 files changed, 56 insertions, 37 deletions
diff --git a/lib/helpers/edit_on_gitlab.rb b/lib/helpers/edit_on_gitlab.rb
index 7188cd1e..7f2c36bd 100644
--- a/lib/helpers/edit_on_gitlab.rb
+++ b/lib/helpers/edit_on_gitlab.rb
@@ -2,51 +2,70 @@
module Nanoc::Helpers
module EditOnGitLab
+ PRODUCT_REPOS = {
+ "omnibus" => {
+ project: "gitlab-org/omnibus-gitlab",
+ default_branch_name: "master"
+ },
+ "runner" => {
+ project: "gitlab-org/gitlab-runner",
+ default_branch_name: "main"
+ },
+ "charts" => {
+ project: "gitlab-org/charts/gitlab",
+ default_branch_name: "master"
+ },
+ "operator" => {
+ project: "gitlab-org/cloud-native/gitlab-operator",
+ default_branch_name: "master"
+ },
+ "ee" => {
+ project: "gitlab-org/gitlab",
+ default_branch_name: "master"
+ }
+ }.freeze
+
def edit_on_gitlab(item, editor: :simple)
- # Make an array out of the content's source path.
- content_filename_array = @item.identifier.to_s.split('/')
- # remove first empty item
- content_filename_array.shift
- # Get the product name.
- product = content_filename_array.shift
- # This should be the path from the doc/ directory for a given file.
- docs_content_filename = content_filename_array.join("/")
-
- case product
- when "omnibus"
- # omnibus-gitlab repo
- gitlab_url = "https://gitlab.com/gitlab-org/#{product}-gitlab/blob/master/doc/#{docs_content_filename}"
- gitlab_ide_url = "https://gitlab.com/-/ide/project/gitlab-org/#{product}-gitlab/edit/master/-/doc/#{docs_content_filename}"
- when "runner"
- # gitlab-runner repo
- gitlab_url = "https://gitlab.com/gitlab-org/gitlab-#{product}/blob/main/docs/#{docs_content_filename}"
- gitlab_ide_url = "https://gitlab.com/-/ide/project/gitlab-org/gitlab-#{product}/edit/main/-/docs/#{docs_content_filename}"
- when "charts"
- # GitLab Helm chart repo
- gitlab_url = "https://gitlab.com/gitlab-org/#{product}/gitlab/blob/master/doc/#{docs_content_filename}"
- gitlab_ide_url = "https://gitlab.com/-/ide/project/gitlab-org/#{product}/gitlab/edit/master/-/doc/#{docs_content_filename}"
- when "operator"
- # GitLab Operator repo
- gitlab_url = "https://gitlab.com/gitlab-org/cloud-native/gitlab-#{product}/blob/master/doc/#{docs_content_filename}"
- gitlab_ide_url = "https://gitlab.com/-/ide/project/gitlab-org/cloud-native/gitlab-#{product}/edit/master/-/doc/#{docs_content_filename}"
- when "ee"
- # gitlab-foss and gitlab repos
- gitlab_url = "https://gitlab.com/gitlab-org/gitlab/blob/master/doc/#{docs_content_filename}"
- gitlab_ide_url = "https://gitlab.com/-/ide/project/gitlab-org/gitlab/edit/master/-/doc/#{docs_content_filename}"
- else
- # gitlab-docs pages
- gitlab_url = "https://gitlab.com/gitlab-org/gitlab-docs/blob/main/#{@item[:content_filename]}"
- gitlab_ide_url = "https://gitlab.com/-/ide/project/gitlab-org/gitlab-docs/edit/main/-/#{@item[:content_filename]}"
- end
+ resource = resource_from_item(item)
case editor
when :simple
- gitlab_url
+ blob_url(resource)
when :webide
- gitlab_ide_url
+ ide_url(resource)
else
raise "Unknown editor: #{editor}"
end
end
+
+ private
+
+ def resource_from_item(item)
+ # The item identifier is the file path of the current docs page.
+ # Ex: "/ee/user/ssh.md"
+ #
+ # We can use the first path segement to determine which project the docs
+ # reside in. If it's not a known project, then we'll assume that it's a
+ # content file inside gitlab-docs.
+ identifier_path = item.identifier.to_s.delete_prefix("/")
+ product, _, repo_doc_path = identifier_path.partition("/")
+ if repo = PRODUCT_REPOS[product]
+ return repo.merge({ file_path: "doc/#{repo_doc_path}" })
+ end
+
+ {
+ project: "gitlab-org/gitlab-docs",
+ default_branch_name: "main",
+ file_path: item[:content_filename]
+ }
+ end
+
+ def blob_url(resource)
+ "https://gitlab.com/#{resource[:project]}/-/blob/#{resource[:default_branch_name]}/#{resource[:file_path]}"
+ end
+
+ def ide_url(resource)
+ "https://gitlab.com/-/ide/project/#{resource[:project]}/edit/#{resource[:default_branch_name]}/-/#{resource[:file_path]}"
+ end
end
end