1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# frozen_string_literal: true
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)
case editor
when :simple
blob_url(resource)
when :webide
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
|