BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
21 deletions
+21
-21
move_service.rb
app/services/issues/move_service.rb
+2
-2
reference_rewriter.rb
lib/gitlab/gfm/reference_rewriter.rb
+16
-16
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
end
def
unfold_references
(
content
)
unfolder
=
Gitlab
::
Gfm
::
ReferenceUnfold
er
.
new
(
content
,
@old_project
,
rewriter
=
Gitlab
::
Gfm
::
ReferenceRewrit
er
.
new
(
content
,
@old_project
,
@current_user
)
unfolder
.
unfold
(
@new_project
)
rewriter
.
rewrite
(
@new_project
)
end
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
# 'Merge request for issue gitlab-org/gitlab-ce#1234, se also link:
# http://gitlab.com/some/link/#1234, and code `puts #1234`'
#
class
Reference
Unfold
er
def
initialize
(
text
,
project
,
user
)
class
Reference
Rewrit
er
def
initialize
(
text
,
source_project
,
current_
user
)
@text
=
text
@
project
=
project
@
user
=
user
@original
=
markdown
(
text
)
@
source_project
=
source_
project
@
current_user
=
current_
user
@original
_html
=
markdown
(
text
)
end
def
unfold
(
from
_project
)
def
rewrite
(
target
_project
)
pattern
=
Gitlab
::
ReferenceExtractor
.
references_pattern
return
@text
unless
@text
=~
pattern
@text
.
gsub
(
pattern
)
do
|
reference
|
unfold_reference
(
reference
,
Regexp
.
last_match
,
from
_project
)
unfold_reference
(
reference
,
Regexp
.
last_match
,
target
_project
)
end
end
private
def
unfold_reference
(
reference
,
match
,
from
_project
)
def
unfold_reference
(
reference
,
match
,
target
_project
)
before
=
@text
[
0
...
match
.
begin
(
0
)]
after
=
@text
[
match
.
end
(
0
)
..
.
@text
.
length
]
referable
=
find_referable
(
reference
)
after
=
@text
[
match
.
end
(
0
)
..
-
1
]
referable
=
find_
local_
referable
(
reference
)
return
reference
unless
referable
cross_reference
=
referable
.
to_reference
(
from
_project
)
cross_reference
=
referable
.
to_reference
(
target
_project
)
new_text
=
before
+
cross_reference
+
after
substitution_valid?
(
new_text
)
?
cross_reference
:
reference
...
...
@@ -62,21 +61,22 @@ module Gitlab
def
referables
return
@referables
if
@referables
extractor
=
Gitlab
::
ReferenceExtractor
.
new
(
@project
,
@user
)
extractor
=
Gitlab
::
ReferenceExtractor
.
new
(
@source_project
,
@current_user
)
extractor
.
analyze
(
@text
)
@referables
=
extractor
.
all
end
def
find_referable
(
reference
)
def
find_
local_
referable
(
reference
)
referables
.
find
{
|
ref
|
ref
.
to_reference
==
reference
}
end
def
substitution_valid?
(
substituted
)
@original
==
markdown
(
substituted
)
@original
_html
==
markdown
(
substituted
)
end
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
...
...
spec/lib/gitlab/gfm/reference_
unfold
er_spec.rb
→
spec/lib/gitlab/gfm/reference_
rewrit
er_spec.rb
View file @
323d328c
require
'spec_helper'
describe
Gitlab
::
Gfm
::
Reference
Unfold
er
do
describe
Gitlab
::
Gfm
::
Reference
Rewrit
er
do
let
(
:text
)
{
'some text'
}
let
(
:old_project
)
{
create
(
:project
)
}
let
(
:new_project
)
{
create
(
:project
)
}
...
...
@@ -8,9 +8,9 @@ describe Gitlab::Gfm::ReferenceUnfolder do
before
{
old_project
.
team
<<
[
user
,
:guest
]
}
describe
'#
unfold
'
do
describe
'#
rewrite
'
do
subject
do
described_class
.
new
(
text
,
old_project
,
user
).
unfold
(
new_project
)
described_class
.
new
(
text
,
old_project
,
user
).
rewrite
(
new_project
)
end
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