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
Boxiang Sun
gitlab-ce
Commits
6eb31056
Commit
6eb31056
authored
Mar 20, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Find referable for each ref found in references rewriter
parent
323d328c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
10 deletions
+19
-10
lib/gitlab/gfm/reference_rewriter.rb
lib/gitlab/gfm/reference_rewriter.rb
+4
-10
spec/lib/gitlab/gfm/reference_rewriter_spec.rb
spec/lib/gitlab/gfm/reference_rewriter_spec.rb
+15
-0
No files found.
lib/gitlab/gfm/reference_rewriter.rb
View file @
6eb31056
...
@@ -49,7 +49,7 @@ module Gitlab
...
@@ -49,7 +49,7 @@ module Gitlab
def
unfold_reference
(
reference
,
match
,
target_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
)
..-
1
]
after
=
@text
[
match
.
end
(
0
)
..-
1
]
referable
=
find_
local_
referable
(
reference
)
referable
=
find_referable
(
reference
)
return
reference
unless
referable
return
reference
unless
referable
cross_reference
=
referable
.
to_reference
(
target_project
)
cross_reference
=
referable
.
to_reference
(
target_project
)
...
@@ -58,17 +58,11 @@ module Gitlab
...
@@ -58,17 +58,11 @@ module Gitlab
substitution_valid?
(
new_text
)
?
cross_reference
:
reference
substitution_valid?
(
new_text
)
?
cross_reference
:
reference
end
end
def
referables
def
find_referable
(
reference
)
return
@referables
if
@referables
extractor
=
Gitlab
::
ReferenceExtractor
.
new
(
@source_project
,
extractor
=
Gitlab
::
ReferenceExtractor
.
new
(
@source_project
,
@current_user
)
@current_user
)
extractor
.
analyze
(
@text
)
extractor
.
analyze
(
reference
)
@referables
=
extractor
.
all
extractor
.
all
.
first
end
def
find_local_referable
(
reference
)
referables
.
find
{
|
ref
|
ref
.
to_reference
==
reference
}
end
end
def
substitution_valid?
(
substituted
)
def
substitution_valid?
(
substituted
)
...
...
spec/lib/gitlab/gfm/reference_rewriter_spec.rb
View file @
6eb31056
...
@@ -61,6 +61,21 @@ describe Gitlab::Gfm::ReferenceRewriter do
...
@@ -61,6 +61,21 @@ describe Gitlab::Gfm::ReferenceRewriter do
it
{
is_expected
.
to
eq
"
#{
ref
}
, `#1`,
#{
ref
}
, `#1`"
}
it
{
is_expected
.
to
eq
"
#{
ref
}
, `#1`,
#{
ref
}
, `#1`"
}
end
end
context
'description with labels'
do
let!
(
:label
)
{
create
(
:label
,
id:
123
,
name:
'test'
,
project:
old_project
)
}
let
(
:project_ref
)
{
old_project
.
to_reference
}
context
'label referenced by id'
do
let
(
:text
)
{
'#1 and ~123'
}
it
{
is_expected
.
to
eq
%Q{
#{
project_ref
}
#1 and
#{
project_ref
}
~123}
}
end
context
'label referenced by text'
do
let
(
:text
)
{
'#1 and ~"test"'
}
it
{
is_expected
.
to
eq
%Q{
#{
project_ref
}
#1 and
#{
project_ref
}
~123}
}
end
end
end
end
context
'reference contains milestone'
do
context
'reference contains milestone'
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