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
323d328c
Commit
323d328c
authored
Mar 20, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename reference unfolder to rewriter, minor refactorings
parent
802b28e0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
21 deletions
+21
-21
app/services/issues/move_service.rb
app/services/issues/move_service.rb
+2
-2
lib/gitlab/gfm/reference_rewriter.rb
lib/gitlab/gfm/reference_rewriter.rb
+16
-16
spec/lib/gitlab/gfm/reference_rewriter_spec.rb
spec/lib/gitlab/gfm/reference_rewriter_spec.rb
+3
-3
No files found.
app/services/issues/move_service.rb
View file @
323d328c
...
@@ -77,9 +77,9 @@ module Issues
...
@@ -77,9 +77,9 @@ module Issues
end
end
def
unfold_references
(
content
)
def
unfold_references
(
content
)
unfolder
=
Gitlab
::
Gfm
::
ReferenceUnfold
er
.
new
(
content
,
@old_project
,
rewriter
=
Gitlab
::
Gfm
::
ReferenceRewrit
er
.
new
(
content
,
@old_project
,
@current_user
)
@current_user
)
unfolder
.
unfold
(
@new_project
)
rewriter
.
rewrite
(
@new_project
)
end
end
def
notify_participants
def
notify_participants
...
...
lib/gitlab/gfm/reference_
unfold
er.rb
→
lib/gitlab/gfm/reference_
rewrit
er.rb
View file @
323d328c
...
@@ -28,32 +28,31 @@ module Gitlab
...
@@ -28,32 +28,31 @@ module Gitlab
# 'Merge request for issue gitlab-org/gitlab-ce#1234, se also link:
# 'Merge request for issue gitlab-org/gitlab-ce#1234, se also link:
# http://gitlab.com/some/link/#1234, and code `puts #1234`'
# http://gitlab.com/some/link/#1234, and code `puts #1234`'
#
#
class
Reference
Unfold
er
class
Reference
Rewrit
er
def
initialize
(
text
,
project
,
user
)
def
initialize
(
text
,
source_project
,
current_
user
)
@text
=
text
@text
=
text
@
project
=
project
@
source_project
=
source_
project
@
user
=
user
@
current_user
=
current_
user
@original
=
markdown
(
text
)
@original
_html
=
markdown
(
text
)
end
end
def
unfold
(
from
_project
)
def
rewrite
(
target
_project
)
pattern
=
Gitlab
::
ReferenceExtractor
.
references_pattern
pattern
=
Gitlab
::
ReferenceExtractor
.
references_pattern
return
@text
unless
@text
=~
pattern
@text
.
gsub
(
pattern
)
do
|
reference
|
@text
.
gsub
(
pattern
)
do
|
reference
|
unfold_reference
(
reference
,
Regexp
.
last_match
,
from
_project
)
unfold_reference
(
reference
,
Regexp
.
last_match
,
target
_project
)
end
end
end
end
private
private
def
unfold_reference
(
reference
,
match
,
from
_project
)
def
unfold_reference
(
reference
,
match
,
target
_project
)
before
=
@text
[
0
...
match
.
begin
(
0
)]
before
=
@text
[
0
...
match
.
begin
(
0
)]
after
=
@text
[
match
.
end
(
0
)
..
.
@text
.
length
]
after
=
@text
[
match
.
end
(
0
)
..
-
1
]
referable
=
find_referable
(
reference
)
referable
=
find_
local_
referable
(
reference
)
return
reference
unless
referable
return
reference
unless
referable
cross_reference
=
referable
.
to_reference
(
from
_project
)
cross_reference
=
referable
.
to_reference
(
target
_project
)
new_text
=
before
+
cross_reference
+
after
new_text
=
before
+
cross_reference
+
after
substitution_valid?
(
new_text
)
?
cross_reference
:
reference
substitution_valid?
(
new_text
)
?
cross_reference
:
reference
...
@@ -62,21 +61,22 @@ module Gitlab
...
@@ -62,21 +61,22 @@ module Gitlab
def
referables
def
referables
return
@referables
if
@referables
return
@referables
if
@referables
extractor
=
Gitlab
::
ReferenceExtractor
.
new
(
@project
,
@user
)
extractor
=
Gitlab
::
ReferenceExtractor
.
new
(
@source_project
,
@current_user
)
extractor
.
analyze
(
@text
)
extractor
.
analyze
(
@text
)
@referables
=
extractor
.
all
@referables
=
extractor
.
all
end
end
def
find_referable
(
reference
)
def
find_
local_
referable
(
reference
)
referables
.
find
{
|
ref
|
ref
.
to_reference
==
reference
}
referables
.
find
{
|
ref
|
ref
.
to_reference
==
reference
}
end
end
def
substitution_valid?
(
substituted
)
def
substitution_valid?
(
substituted
)
@original
==
markdown
(
substituted
)
@original
_html
==
markdown
(
substituted
)
end
end
def
markdown
(
text
)
def
markdown
(
text
)
Banzai
.
render
(
text
,
project:
@project
,
no_original_data:
true
)
Banzai
.
render
(
text
,
project:
@
source_
project
,
no_original_data:
true
)
end
end
end
end
end
end
...
...
spec/lib/gitlab/gfm/reference_
unfold
er_spec.rb
→
spec/lib/gitlab/gfm/reference_
rewrit
er_spec.rb
View file @
323d328c
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Gfm
::
Reference
Unfold
er
do
describe
Gitlab
::
Gfm
::
Reference
Rewrit
er
do
let
(
:text
)
{
'some text'
}
let
(
:text
)
{
'some text'
}
let
(
:old_project
)
{
create
(
:project
)
}
let
(
:old_project
)
{
create
(
:project
)
}
let
(
:new_project
)
{
create
(
:project
)
}
let
(
:new_project
)
{
create
(
:project
)
}
...
@@ -8,9 +8,9 @@ describe Gitlab::Gfm::ReferenceUnfolder do
...
@@ -8,9 +8,9 @@ describe Gitlab::Gfm::ReferenceUnfolder do
before
{
old_project
.
team
<<
[
user
,
:guest
]
}
before
{
old_project
.
team
<<
[
user
,
:guest
]
}
describe
'#
unfold
'
do
describe
'#
rewrite
'
do
subject
do
subject
do
described_class
.
new
(
text
,
old_project
,
user
).
unfold
(
new_project
)
described_class
.
new
(
text
,
old_project
,
user
).
rewrite
(
new_project
)
end
end
context
'multiple issues and merge requests referenced'
do
context
'multiple issues and merge requests referenced'
do
...
...
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