Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
686b1c8e
Commit
686b1c8e
authored
Mar 13, 2022
by
Luke Duncalfe
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '353926' into 'master'
Remove wiki_front_matter FF See merge request gitlab-org/gitlab!81833
parents
70fdf3a0
8045da79
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
8 additions
and
107 deletions
+8
-107
app/models/wiki_page.rb
app/models/wiki_page.rb
+1
-2
config/feature_flags/development/wiki_front_matter.yml
config/feature_flags/development/wiki_front_matter.yml
+0
-8
lib/gitlab/wiki_pages/front_matter_parser.rb
lib/gitlab/wiki_pages/front_matter_parser.rb
+3
-15
spec/lib/gitlab/wiki_pages/front_matter_parser_spec.rb
spec/lib/gitlab/wiki_pages/front_matter_parser_spec.rb
+1
-28
spec/models/wiki_page_spec.rb
spec/models/wiki_page_spec.rb
+3
-54
No files found.
app/models/wiki_page.rb
View file @
686b1c8e
...
...
@@ -316,7 +316,6 @@ class WikiPage
end
def
update_front_matter
(
attrs
)
return
unless
Gitlab
::
WikiPages
::
FrontMatterParser
.
enabled?
(
container
)
return
unless
attrs
.
has_key?
(
:front_matter
)
fm_yaml
=
serialize_front_matter
(
attrs
[
:front_matter
])
...
...
@@ -327,7 +326,7 @@ class WikiPage
def
parsed_content
strong_memoize
(
:parsed_content
)
do
Gitlab
::
WikiPages
::
FrontMatterParser
.
new
(
raw_content
,
container
).
parse
Gitlab
::
WikiPages
::
FrontMatterParser
.
new
(
raw_content
).
parse
end
end
...
...
config/feature_flags/development/wiki_front_matter.yml
deleted
100644 → 0
View file @
70fdf3a0
---
name
:
wiki_front_matter
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27706
rollout_issue_url
:
milestone
:
'
12.10'
type
:
development
group
:
group::editor
default_enabled
:
false
lib/gitlab/wiki_pages/front_matter_parser.rb
View file @
686b1c8e
...
...
@@ -3,8 +3,6 @@
module
Gitlab
module
WikiPages
class
FrontMatterParser
FEATURE_FLAG
=
:wiki_front_matter
# We limit the maximum length of text we are prepared to parse as YAML, to
# avoid exploitations and attempts to consume memory and CPU. We allow for:
# - a title line
...
...
@@ -30,18 +28,12 @@ module Gitlab
end
# @param [String] wiki_content
# @param [FeatureGate] feature_gate The scope for feature availability
def
initialize
(
wiki_content
,
feature_gate
)
def
initialize
(
wiki_content
)
@wiki_content
=
wiki_content
@feature_gate
=
feature_gate
end
def
self
.
enabled?
(
gate
=
nil
)
Feature
.
enabled?
(
FEATURE_FLAG
,
gate
)
end
def
parse
return
empty_result
unless
enabled?
&&
wiki_content
.
present?
return
empty_result
unless
wiki_content
.
present?
return
empty_result
(
block
.
error
)
unless
block
.
valid?
Result
.
new
(
front_matter:
block
.
data
,
content:
strip_front_matter_block
)
...
...
@@ -94,16 +86,12 @@ module Gitlab
private
attr_reader
:wiki_content
,
:feature_gate
attr_reader
:wiki_content
def
empty_result
(
reason
=
nil
,
error
=
nil
)
Result
.
new
(
content:
wiki_content
,
reason:
reason
,
error:
error
)
end
def
enabled?
self
.
class
.
enabled?
(
feature_gate
)
end
def
block
@block
||=
parse_front_matter_block
end
...
...
spec/lib/gitlab/wiki_pages/front_matter_parser_spec.rb
View file @
686b1c8e
...
...
@@ -3,11 +3,10 @@
require
'spec_helper'
RSpec
.
describe
Gitlab
::
WikiPages
::
FrontMatterParser
do
subject
(
:parser
)
{
described_class
.
new
(
raw_content
,
gate
)
}
subject
(
:parser
)
{
described_class
.
new
(
raw_content
)
}
let
(
:content
)
{
'This is the content'
}
let
(
:end_divider
)
{
'---'
}
let
(
:gate
)
{
stub_feature_flag_gate
(
'Gate'
)
}
let
(
:with_front_matter
)
do
<<~
MD
...
...
@@ -62,32 +61,6 @@ RSpec.describe Gitlab::WikiPages::FrontMatterParser do
it
{
is_expected
.
to
have_attributes
(
reason: :no_match
)
}
end
context
'the feature flag is disabled'
do
let
(
:raw_content
)
{
with_front_matter
}
before
do
stub_feature_flags
(
Gitlab
::
WikiPages
::
FrontMatterParser
::
FEATURE_FLAG
=>
false
)
end
it
{
is_expected
.
to
have_attributes
(
front_matter:
be_empty
,
content:
raw_content
)
}
end
context
'the feature flag is enabled for the gated object'
do
let
(
:raw_content
)
{
with_front_matter
}
before
do
stub_feature_flags
(
Gitlab
::
WikiPages
::
FrontMatterParser
::
FEATURE_FLAG
=>
gate
)
end
it
do
is_expected
.
to
have_attributes
(
front_matter:
have_correct_front_matter
,
content:
content
+
"
\n
"
,
reason:
be_nil
)
end
end
context
'the end divider is ...'
do
let
(
:end_divider
)
{
'...'
}
let
(
:raw_content
)
{
with_front_matter
}
...
...
spec/models/wiki_page_spec.rb
View file @
686b1c8e
...
...
@@ -24,14 +24,6 @@ RSpec.describe WikiPage do
container
.
wiki
end
def
disable_front_matter
stub_feature_flags
(
Gitlab
::
WikiPages
::
FrontMatterParser
::
FEATURE_FLAG
=>
false
)
end
def
enable_front_matter_for
(
thing
)
stub_feature_flags
(
Gitlab
::
WikiPages
::
FrontMatterParser
::
FEATURE_FLAG
=>
thing
)
end
# Use for groups of tests that do not modify their `subject`.
#
# include_context 'subject is persisted page', title: 'my title'
...
...
@@ -48,12 +40,6 @@ RSpec.describe WikiPage do
it
{
expect
(
wiki_page
).
to
have_attributes
(
front_matter:
{},
content:
content
)
}
end
shared_examples
'a page with front-matter'
do
let
(
:front_matter
)
{
{
title:
'Foo'
,
slugs:
%w[slug_a slug_b]
}
}
it
{
expect
(
wiki_page
.
front_matter
).
to
eq
(
front_matter
)
}
end
context
'the wiki page has front matter'
do
let
(
:content
)
do
<<~
MD
...
...
@@ -68,27 +54,13 @@ RSpec.describe WikiPage do
MD
end
it_behaves_like
'a page with front-matter'
it
'has front-matter'
do
expect
(
wiki_page
.
front_matter
).
to
eq
({
title:
'Foo'
,
slugs:
%w[slug_a slug_b]
})
end
it
'strips the front matter from the content'
do
expect
(
wiki_page
.
content
.
strip
).
to
eq
(
'My actual content'
)
end
context
'the feature flag is off'
do
before
do
disable_front_matter
end
it_behaves_like
'a page without front-matter'
context
'but enabled for the container'
do
before
do
enable_front_matter_for
(
container
)
end
it_behaves_like
'a page with front-matter'
end
end
end
context
'the wiki page does not have front matter'
do
...
...
@@ -471,29 +443,6 @@ RSpec.describe WikiPage do
end
end
context
'the front-matter feature flag is not enabled'
do
before
do
disable_front_matter
end
it
'does not update the front-matter'
do
content
=
subject
.
content
subject
.
update
(
front_matter:
{
slugs:
[
'x'
]
})
page
=
wiki
.
find_page
(
subject
.
title
)
expect
([
subject
,
page
]).
to
all
(
have_attributes
(
front_matter:
be_empty
,
content:
content
))
end
context
'but it is enabled for the container'
do
before
do
enable_front_matter_for
(
container
)
end
it_behaves_like
'able to update front-matter'
end
end
it
'updates the wiki-page front-matter and content together'
do
content
=
'totally new content'
subject
.
update
(
content:
content
,
front_matter:
{
slugs:
[
'x'
]
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment