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
0
Merge Requests
0
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
iv
gitlab-ce
Commits
3c493c24
Commit
3c493c24
authored
Feb 26, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add reference unfold pipeline used when moving issue
parent
efd82517
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
4 deletions
+121
-4
app/services/issues/move_service.rb
app/services/issues/move_service.rb
+7
-4
lib/banzai/filter/reference_unfold_filter.rb
lib/banzai/filter/reference_unfold_filter.rb
+46
-0
lib/banzai/pipeline/reference_unfold_pipeline.rb
lib/banzai/pipeline/reference_unfold_pipeline.rb
+9
-0
spec/lib/banzai/pipeline/reference_unfold_pipeline_spec.rb
spec/lib/banzai/pipeline/reference_unfold_pipeline_spec.rb
+59
-0
No files found.
app/services/issues/move_service.rb
View file @
3c493c24
...
...
@@ -86,10 +86,13 @@ module Issues
:snippets
,
:commits
,
:commit_ranges
]
cross_project_mentionables
.
each
do
|
type
|
references
.
public_send
(
type
).
each
do
|
mentionable
|
new_content
.
gsub!
(
mentionable
.
to_reference
,
mentionable
.
to_reference
(
@project_new
))
end
referables
=
references
.
public_send
(
type
)
context
=
{
objects:
referables
,
project:
@project_new
,
pipeline: :reference_unfold
}
new_content
=
Banzai
.
render_result
(
new_content
,
context
)
new_content
=
new_content
[
:output
].
to_s
end
new_content
...
...
lib/banzai/filter/reference_unfold_filter.rb
0 → 100644
View file @
3c493c24
module
Banzai
module
Filter
##
# Filter than unfolds local references.
#
# Replaces all local references with project cross reference version
# in all objects passed to this filter in context.
#
# Requires objects array with each element implementing `Referable`.
#
class
ReferenceUnfoldFilter
<
ReferenceFilter
def
initialize
(
*
)
super
@objects
=
context
[
:objects
]
@project
=
context
[
:project
]
unless
@objects
.
all?
{
|
object
|
object
.
respond_to?
(
:to_reference
)
}
raise
StandardError
,
"No `to_reference` method implemented in one of the objects !"
end
unless
@project
.
kind_of?
(
Project
)
raise
StandardError
,
'No valid project passed in context!'
end
end
def
call
@objects
.
each
do
|
object
|
pattern
=
/
#{
Regexp
.
escape
(
object
.
to_reference
)
}
/
replace_text_nodes_matching
(
pattern
)
do
|
content
|
content
.
gsub
(
pattern
,
object
.
to_reference
(
@project
))
end
end
doc
end
private
def
validate
needs
:project
needs
:objects
end
end
end
end
lib/banzai/pipeline/reference_unfold_pipeline.rb
0 → 100644
View file @
3c493c24
module
Banzai
module
Pipeline
class
ReferenceUnfoldPipeline
<
BasePipeline
def
self
.
filters
[
Filter
::
ReferenceUnfoldFilter
]
end
end
end
end
spec/lib/banzai/pipeline/reference_unfold_pipeline_spec.rb
0 → 100644
View file @
3c493c24
require
'spec_helper'
describe
Banzai
::
Pipeline
::
ReferenceUnfoldPipeline
do
let
(
:text
)
{
'some text'
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:objects
)
{
[]
}
let
(
:result
)
do
described_class
.
to_html
(
text
,
project:
project
,
objects:
objects
)
end
context
'invalid initializers'
do
subject
{
->
{
result
}
}
context
'project context is invalid'
do
let
(
:project
)
{
nil
}
it
{
is_expected
.
to
raise_error
StandardError
,
/No valid project/
}
end
context
'objects context is invalid'
do
let
(
:objects
)
{
[
'issue'
]
}
it
{
is_expected
.
to
raise_error
StandardError
,
/No `to_reference` method/
}
end
end
context
'multiple issues and merge requests referenced'
do
subject
{
result
}
let
(
:main_project
)
{
create
(
:project
)
}
let
(
:issue_first
)
{
create
(
:issue
,
project:
main_project
)
}
let
(
:issue_second
)
{
create
(
:issue
,
project:
main_project
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
main_project
)
}
let
(
:objects
)
{
[
issue_first
,
issue_second
,
merge_request
]
}
context
'plain text description'
do
let
(
:text
)
{
'Description that references #1, #2 and !1'
}
it
{
is_expected
.
to
include
issue_first
.
to_reference
(
project
)
}
it
{
is_expected
.
to
include
issue_second
.
to_reference
(
project
)
}
it
{
is_expected
.
to
include
merge_request
.
to_reference
(
project
)
}
end
context
'description with ignored elements'
do
let
(
:text
)
do
<<-
EOF
Hi. This references #1, but not `#2`
<pre>and not !1</pre>
EOF
end
it
{
is_expected
.
to
include
issue_first
.
to_reference
(
project
)
}
it
{
is_expected
.
to_not
include
issue_second
.
to_reference
(
project
)
}
it
{
is_expected
.
to_not
include
merge_request
.
to_reference
(
project
)
}
end
end
end
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