summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-10-14 09:09:13 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-14 09:09:13 +0000
commitefcfe56681dc8bd586e6ef56d1dc7df05a93197d (patch)
treefa828ffc634b986aad47ed7ea71adb7b838bc0df /app
parente761659df2e0bced8ccb707c87aa350c9d30f18d (diff)
downloadgitlab-ce-efcfe56681dc8bd586e6ef56d1dc7df05a93197d.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/reports/components/report_section.vue5
-rw-r--r--app/controllers/concerns/wiki_actions.rb6
-rw-r--r--app/helpers/wiki_helper.rb4
-rw-r--r--app/models/concerns/has_wiki.rb2
-rw-r--r--app/models/wiki.rb116
-rw-r--r--app/models/wiki_page.rb2
-rw-r--r--app/views/projects/work_items/index.html.haml2
-rw-r--r--app/views/search/results/_wiki_blob.html.haml2
-rw-r--r--app/views/shared/wikis/pages.html.haml5
9 files changed, 55 insertions, 89 deletions
diff --git a/app/assets/javascripts/reports/components/report_section.vue b/app/assets/javascripts/reports/components/report_section.vue
index d9059e126f2..bb86695b9a3 100644
--- a/app/assets/javascripts/reports/components/report_section.vue
+++ b/app/assets/javascripts/reports/components/report_section.vue
@@ -190,7 +190,10 @@ export default {
<div class="media" :class="{ 'gl-cursor-pointer': isCollapsible }" @click="toggleCollapsed">
<status-icon :status="statusIconName" :size="24" class="align-self-center" />
<div class="media-body gl-display-flex gl-align-items-flex-start gl-flex-direction-row!">
- <div data-testid="report-section-code-text" class="js-code-text code-text">
+ <div
+ data-testid="report-section-code-text"
+ class="js-code-text code-text gl-align-self-center gl-flex-grow-1"
+ >
<div class="gl-display-flex gl-align-items-center">
<p class="gl-line-height-normal gl-m-0">{{ headerText }}</p>
<slot :name="slotName"></slot>
diff --git a/app/controllers/concerns/wiki_actions.rb b/app/controllers/concerns/wiki_actions.rb
index 83447744013..2b781c528ad 100644
--- a/app/controllers/concerns/wiki_actions.rb
+++ b/app/controllers/concerns/wiki_actions.rb
@@ -209,9 +209,7 @@ module WikiActions
def wiki
strong_memoize(:wiki) do
wiki = Wiki.for_container(container, current_user)
-
- # Call #wiki to make sure the Wiki Repo is initialized
- wiki.wiki
+ wiki.create_wiki_repository
wiki
end
@@ -242,7 +240,7 @@ module WikiActions
def wiki_pages
strong_memoize(:wiki_pages) do
Kaminari.paginate_array(
- wiki.list_pages(sort: params[:sort], direction: params[:direction])
+ wiki.list_pages(direction: params[:direction])
).page(params[:page])
end
end
diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb
index bded1b3a566..017a1861905 100644
--- a/app/helpers/wiki_helper.rb
+++ b/app/helpers/wiki_helper.rb
@@ -59,15 +59,13 @@ module WikiHelper
end
end
- def wiki_sort_controls(wiki, sort, direction)
- sort ||= Wiki::TITLE_ORDER
+ def wiki_sort_controls(wiki, direction)
link_class = 'gl-button btn btn-default btn-icon has-tooltip reverse-sort-btn qa-reverse-sort rspec-reverse-sort'
reversed_direction = direction == 'desc' ? 'asc' : 'desc'
icon_class = direction == 'desc' ? 'highest' : 'lowest'
title = direction == 'desc' ? _('Sort direction: Descending') : _('Sort direction: Ascending')
link_options = { action: :pages, direction: reversed_direction }
- link_options[:sort] = sort unless wiki.disable_sorting?
link_to(wiki_path(wiki, **link_options),
type: 'button', class: link_class, title: title) do
diff --git a/app/models/concerns/has_wiki.rb b/app/models/concerns/has_wiki.rb
index 89bcabafb84..53016ce62f4 100644
--- a/app/models/concerns/has_wiki.rb
+++ b/app/models/concerns/has_wiki.rb
@@ -8,7 +8,7 @@ module HasWiki
end
def create_wiki
- wiki.wiki
+ wiki.create_wiki_repository
true
rescue Wiki::CouldNotCreateWikiError
errors.add(:base, _('Failed to create wiki'))
diff --git a/app/models/wiki.rb b/app/models/wiki.rb
index 02d13836559..b718c3a096f 100644
--- a/app/models/wiki.rb
+++ b/app/models/wiki.rb
@@ -9,6 +9,8 @@ class Wiki
extend ActiveModel::Naming
+ DuplicatePageError = Class.new(StandardError)
+
MARKUPS = { # rubocop:disable Style/MultilineIfModifier
markdown: {
name: 'Markdown',
@@ -114,6 +116,29 @@ class Wiki
title = Pathname.new(title).relative_path_from('/').to_s
title.tr(' ', '-')
end
+
+ def canonicalize_filename(filename)
+ ::File.basename(filename, ::File.extname(filename)).tr('-', ' ')
+ end
+
+ def cname(name, char_white_sub = '-', char_other_sub = '-')
+ name.to_s.gsub(/\s/, char_white_sub).gsub(/[<>+]/, char_other_sub)
+ end
+
+ def preview_slug(title, format)
+ ext = format == :markdown ? "md" : format.to_s
+ name = cname(title) + '.' + ext
+ canonical_name = canonicalize_filename(name)
+
+ path =
+ if name.include?('/')
+ name.sub(%r{/[^/]+$}, '/')
+ else
+ ''
+ end
+
+ path + cname(canonical_name, '-', '-')
+ end
end
def initialize(container, user = nil)
@@ -145,14 +170,6 @@ class Wiki
container.path + '.wiki'
end
- # Returns the Gitlab::Git::Wiki object.
- def wiki
- strong_memoize(:wiki) do
- create_wiki_repository
- Gitlab::Git::Wiki.new(repository.raw)
- end
- end
-
def create_wiki_repository
repository.create_if_not_exists(default_branch)
@@ -190,13 +207,9 @@ class Wiki
#
# Returns an Array of GitLab WikiPage instances or an
# empty Array if this Wiki has no pages.
- def list_pages(limit: 0, sort: nil, direction: DIRECTION_ASC, load_content: false)
- if list_pages_with_repository_rpcs?
- create_wiki_repository unless repository_exists?
- list_pages_with_repository_rpcs(limit: limit, sort: sort, direction: direction, load_content: load_content)
- else
- list_pages_with_legacy_wiki_service(limit: limit, sort: sort, direction: direction, load_content: load_content)
- end
+ def list_pages(limit: 0, direction: DIRECTION_ASC, load_content: false)
+ create_wiki_repository unless repository_exists?
+ list_pages_with_repository_rpcs(limit: limit, direction: direction, load_content: load_content)
end
def sidebar_entries(limit: Gitlab::WikiPages::MAX_SIDEBAR_PAGES, **options)
@@ -215,12 +228,8 @@ class Wiki
#
# Returns an initialized WikiPage instance or nil
def find_page(title, version = nil, load_content: true)
- if find_page_with_repository_rpcs?
- create_wiki_repository unless repository_exists?
- find_page_with_repository_rpcs(title, version, load_content: load_content)
- else
- find_page_with_legacy_wiki_service(title, version, load_content: load_content)
- end
+ create_wiki_repository unless repository_exists?
+ find_page_with_repository_rpcs(title, version, load_content: load_content)
end
def find_sidebar(version = nil)
@@ -254,7 +263,7 @@ class Wiki
raise_duplicate_page_error!
end
end
- rescue Gitlab::Git::Wiki::DuplicatePageError => e
+ rescue DuplicatePageError => e
@error_message = _("Duplicate page: %{error_message}" % { error_message: e.message })
false
@@ -270,6 +279,7 @@ class Wiki
extension = page.format != format.to_sym ? default_extension : File.extname(page.path).downcase[1..]
capture_git_error(:updated) do
+ create_wiki_repository unless repository_exists?
repository.update_file(
user,
sluggified_full_path(title, extension),
@@ -288,6 +298,7 @@ class Wiki
return unless page
capture_git_error(:deleted) do
+ create_wiki_repository unless repository_exists?
repository.delete_file(user, page.path, **multi_commit_options(:deleted, message, page.title))
after_wiki_activity
@@ -304,8 +315,10 @@ class Wiki
[title, title_array.join("/")]
end
+ # TODO: This method is redundant. Should be replaced by create_wiki_repository
def ensure_repository
- raise CouldNotCreateWikiError unless wiki.repository_exists?
+ create_wiki_repository
+ raise CouldNotCreateWikiError unless repository_exists?
end
def hook_attrs
@@ -341,7 +354,7 @@ class Wiki
override :default_branch
def default_branch
- super || Gitlab::Git::Wiki.default_ref(container)
+ super || Gitlab::DefaultBranch.value(object: container)
end
def wiki_base_path
@@ -381,10 +394,6 @@ class Wiki
false
end
- def disable_sorting?
- list_pages_with_repository_rpcs?
- end
-
private
def multi_commit_options(action, message = nil, title = nil)
@@ -429,7 +438,7 @@ class Wiki
end
def raise_duplicate_page_error!
- raise Gitlab::Git::Wiki::DuplicatePageError, _('A page with that title already exists')
+ raise ::Wiki::DuplicatePageError, _('A page with that title already exists')
end
def sluggified_full_path(title, extension)
@@ -441,15 +450,7 @@ class Wiki
end
def canonicalize_filename(filename)
- Gitlab::Git::Wiki::GollumSlug.canonicalize_filename(filename)
- end
-
- def find_page_with_legacy_wiki_service(title, version, load_content: false)
- page_title, page_dir = page_title_and_dir(title)
-
- if page = wiki.page(title: page_title, version: version, dir: page_dir, load_content: load_content)
- WikiPage.new(self, page)
- end
+ self.class.canonicalize_filename(filename)
end
def find_matched_file(title, version)
@@ -494,17 +495,6 @@ class Wiki
WikiPage.new(self, page)
end
- def find_page_with_repository_rpcs?
- group =
- if container.is_a?(::Group)
- container
- else
- container.group
- end
-
- Feature.enabled?(:wiki_find_page_with_normal_repository_rpcs, group, type: :development)
- end
-
def file_extension_regexp
# We could not use ALLOWED_EXTENSIONS_REGEX constant or similar regexp with
# Regexp.union. The result combination complicated modifiers:
@@ -519,17 +509,6 @@ class Wiki
path.sub(/\.[^.]+\z/, "")
end
- def list_pages_with_repository_rpcs?
- group =
- if container.is_a?(::Group)
- container
- else
- container.group
- end
-
- Feature.enabled?(:wiki_list_pages_with_normal_repository_rpcs, group, type: :development)
- end
-
def list_page_paths
return [] if repository.empty?
@@ -537,7 +516,7 @@ class Wiki
repository.search_files_by_regexp(path_regexp, default_branch)
end
- def list_pages_with_repository_rpcs(limit:, sort:, direction:, load_content:)
+ def list_pages_with_repository_rpcs(limit:, direction:, load_content:)
paths = list_page_paths
return [] if paths.empty?
@@ -553,29 +532,18 @@ class Wiki
)
WikiPage.new(self, page)
end
- sort_pages!(pages, sort, direction)
+ sort_pages!(pages, direction)
pages = pages.take(limit) if limit > 0
fetch_pages_content!(pages) if load_content
pages
end
- def list_pages_with_legacy_wiki_service(limit:, sort:, direction:, load_content:)
- wiki.list_pages(
- limit: limit,
- sort: sort,
- direction_desc: direction == DIRECTION_DESC,
- load_content: load_content
- ).map do |page|
- WikiPage.new(self, page)
- end
- end
-
# After migrating to normal repository RPCs, it's very expensive to sort the
# pages by created_at. We have to either ListLastCommitsForTree RPC call or
# N+1 LastCommitForPath. Either are efficient for a large repository.
# Therefore, we decide to sort the title only.
- def sort_pages!(pages, _sort, direction)
+ def sort_pages!(pages, direction)
# Sort by path to ensure the files inside a sub-folder are grouped and sorted together
pages.sort_by!(&:path)
pages.reverse! if direction == DIRECTION_DESC
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index ad07e0269f6..24b0b94eeb7 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -73,7 +73,7 @@ class WikiPage
# The escaped URL path of this page.
def slug
- attributes[:slug].presence || wiki.wiki.preview_slug(title, format)
+ attributes[:slug].presence || ::Wiki.preview_slug(title, format)
end
alias_method :id, :slug # required to use build_stubbed
diff --git a/app/views/projects/work_items/index.html.haml b/app/views/projects/work_items/index.html.haml
index 8575fd10ad3..69597aab7ef 100644
--- a/app/views/projects/work_items/index.html.haml
+++ b/app/views/projects/work_items/index.html.haml
@@ -1,5 +1,7 @@
- page_title s_('WorkItem|Work Items')
- add_page_specific_style 'page_bundles/work_items'
+- @gfm_form = true
+- @noteable_type = 'WorkItem'
#js-work-items{ data: work_items_index_data(@project) }
= render 'projects/invite_members_modal', project: @project
diff --git a/app/views/search/results/_wiki_blob.html.haml b/app/views/search/results/_wiki_blob.html.haml
index b59275c35df..d6900c397a0 100644
--- a/app/views/search/results/_wiki_blob.html.haml
+++ b/app/views/search/results/_wiki_blob.html.haml
@@ -4,6 +4,6 @@
%div{ class: 'search-result-row gl-pb-3! gl-mt-5 gl-mb-0!' }
%span.gl-display-flex.gl-align-items-center
= link_to wiki_blob_link, data: { track_action: 'click_text', track_label: "wiki_title", track_property: 'search_result' }, class: 'gl-w-full' do
- %span.term.str-truncated.gl-font-weight-bold= ::Gitlab::Git::Wiki::GollumSlug.canonicalize_filename(wiki_blob.path)
+ %span.term.str-truncated.gl-font-weight-bold= ::Wiki.canonicalize_filename(wiki_blob.path)
.description.term.col-sm-10.gl-px-0
= simple_search_highlight_and_truncate(wiki_blob.data, @search_term)
diff --git a/app/views/shared/wikis/pages.html.haml b/app/views/shared/wikis/pages.html.haml
index 79c5bb62f28..e1252e91c10 100644
--- a/app/views/shared/wikis/pages.html.haml
+++ b/app/views/shared/wikis/pages.html.haml
@@ -2,7 +2,6 @@
- breadcrumb_title s_("Wiki|Pages")
- page_title s_("Wiki|Pages"), _("Wiki")
- add_page_specific_style 'page_bundles/wiki'
-- wiki_sort_options = [{ text: s_("Wiki|Title"), value: 'title', href: wiki_path(@wiki, action: :pages, sort: Wiki::TITLE_ORDER)}, { text: s_("Wiki|Created date"), value: 'created_at', href: wiki_path(@wiki, action: :pages, sort: Wiki::CREATED_AT_ORDER) }]
.wiki-page-header.top-area.flex-column.flex-lg-row
%h1.page-title.gl-font-size-h-display.gl-flex-grow-1
@@ -15,9 +14,7 @@
.dropdown.inline.wiki-sort-dropdown
.btn-group{ role: 'group' }
- - unless @wiki.disable_sorting?
- = gl_redirect_listbox_tag wiki_sort_options, params[:sort], data: { right: true }
- = wiki_sort_controls(@wiki, params[:sort], params[:direction])
+ = wiki_sort_controls(@wiki, params[:direction])
%ul.wiki-pages-list.content-list
= render @wiki_entries, context: 'pages'