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:
authorEvan Read <eread@gitlab.com>2022-06-23 03:28:35 +0300
committerClayton Cornell <ccornell@gitlab.com>2022-06-23 03:28:35 +0300
commitf7e3c0c1e4e096b14658e21d31eef4aa0c2f3c4a (patch)
treeff66d6ec0696c6bf778a7b12011ed655ea8f8cd8
parent5d5fe32fd1c68f182acfe889038af859d381c911 (diff)
Revert "Merge branch 'bwill/refactor-edit-on-gitlab' into 'main'"
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock15
-rw-r--r--lib/helpers/edit_on_gitlab.rb93
-rw-r--r--spec/helpers/edit_on_gitlab_spec.rb49
-rw-r--r--spec/spec_helper.rb1
5 files changed, 37 insertions, 122 deletions
diff --git a/Gemfile b/Gemfile
index 3959b330..d5b35a96 100644
--- a/Gemfile
+++ b/Gemfile
@@ -22,7 +22,6 @@ end
group :test, :development do
gem 'highline', '~> 2.0.0'
gem 'rspec', '~> 3.11.0'
- gem 'rspec-parameterized', '~> 0.5.1'
gem 'pry-byebug', '~> 3.9.0', require: false
gem 'gitlab-styles', '~> 7.1.0', require: false
end
diff --git a/Gemfile.lock b/Gemfile.lock
index c146cccb..7c387dd7 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -20,7 +20,6 @@ GEM
asciidoctor-plantuml (0.0.16)
asciidoctor (>= 2.0.17, < 3.0.0)
ast (2.4.2)
- binding_ninja (0.2.3)
builder (3.2.4)
byebug (11.1.3)
claide (1.1.0)
@@ -183,10 +182,6 @@ GEM
ast (~> 2.4.1)
pastel (0.8.0)
tty-color (~> 0.5)
- proc_to_ast (0.1.0)
- coderay
- parser
- unparser
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
@@ -221,12 +216,6 @@ GEM
rspec-mocks (3.11.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
- rspec-parameterized (0.5.1)
- binding_ninja (>= 0.2.3)
- parser
- proc_to_ast
- rspec (>= 2.13, < 4)
- unparser
rspec-support (3.11.0)
rubocop (0.93.1)
parallel (~> 1.10)
@@ -277,9 +266,6 @@ GEM
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (1.8.0)
- unparser (0.6.5)
- diff-lcs (~> 1.3)
- parser (>= 3.1.0)
zeitwerk (2.5.4)
PLATFORMS
@@ -296,7 +282,6 @@ DEPENDENCIES
pry-byebug (~> 3.9.0)
rake (~> 13.0.0)
rspec (~> 3.11.0)
- rspec-parameterized (~> 0.5.1)
sass (= 3.7.4)
sassc (~> 2.4.0)
diff --git a/lib/helpers/edit_on_gitlab.rb b/lib/helpers/edit_on_gitlab.rb
index 7f2c36bd..7188cd1e 100644
--- a/lib/helpers/edit_on_gitlab.rb
+++ b/lib/helpers/edit_on_gitlab.rb
@@ -2,70 +2,51 @@
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)
- resource = resource_from_item(item)
+ # 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
case editor
when :simple
- blob_url(resource)
+ gitlab_url
when :webide
- ide_url(resource)
+ gitlab_ide_url
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
diff --git a/spec/helpers/edit_on_gitlab_spec.rb b/spec/helpers/edit_on_gitlab_spec.rb
deleted file mode 100644
index e0cf14fa..00000000
--- a/spec/helpers/edit_on_gitlab_spec.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require 'nanoc'
-require 'helpers/edit_on_gitlab'
-
-RSpec.describe Nanoc::Helpers::EditOnGitLab do
- let(:mock_class) { Class.new { extend Nanoc::Helpers::EditOnGitLab } }
- let(:identifier) { "/content/404.html" }
- let(:content_filename) { "content/404.html" }
-
- let(:mock_item) do
- item = Struct.new(:identifier, :content_filename)
- item.new(identifier, content_filename)
- end
-
- subject { mock_class.edit_on_gitlab(mock_item, editor: editor) }
-
- describe '#edit_on_gitlab' do
- using RSpec::Parameterized::TableSyntax
-
- where(:identifier, :editor, :expected_url) do
- "/omnibus/index.md" | :simple | "https://gitlab.com/gitlab-org/omnibus-gitlab/-/blob/master/doc/index.md"
- "/omnibus/index.md" | :webide | "https://gitlab.com/-/ide/project/gitlab-org/omnibus-gitlab/edit/master/-/doc/index.md"
- "/runner/index.md" | :simple | "https://gitlab.com/gitlab-org/gitlab-runner/-/blob/main/doc/index.md"
- "/runner/index.md" | :webide | "https://gitlab.com/-/ide/project/gitlab-org/gitlab-runner/edit/main/-/doc/index.md"
- "/charts/index.md" | :simple | "https://gitlab.com/gitlab-org/charts/gitlab/-/blob/master/doc/index.md"
- "/charts/index.md" | :webide | "https://gitlab.com/-/ide/project/gitlab-org/charts/gitlab/edit/master/-/doc/index.md"
- "/operator/index.md" | :simple | "https://gitlab.com/gitlab-org/cloud-native/gitlab-operator/-/blob/master/doc/index.md"
- "/operator/index.md" | :webide | "https://gitlab.com/-/ide/project/gitlab-org/cloud-native/gitlab-operator/edit/master/-/doc/index.md"
- "/ee/user/ssh.md" | :simple | "https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/user/ssh.md"
- "/ee/user/ssh.md" | :webide | "https://gitlab.com/-/ide/project/gitlab-org/gitlab/edit/master/-/doc/user/ssh.md"
- "/content/404.html" | :simple | "https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/content/404.html"
- "/content/404.html" | :webide | "https://gitlab.com/-/ide/project/gitlab-org/gitlab-docs/edit/main/-/content/404.html"
- end
-
- with_them do
- it 'returns correct url for identifier and editor' do
- expect(subject).to eq(expected_url)
- end
- end
-
- context 'with unknown editor' do
- let(:editor) { :word }
-
- it { expect { subject }.to raise_error("Unknown editor: word") }
- end
- end
-end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 762c465b..43596af8 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -2,7 +2,6 @@
$LOAD_PATH << 'lib/'
-require 'rspec-parameterized'
require 'gitlab/docs'
RSpec.configure do |config|