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
6bac823a
Commit
6bac823a
authored
Apr 21, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update CommitRangeReferenceFilter to use CommitRange class
Also matches CommitReferenceFilter's new behavior of always using short SHAs in the link text.
parent
a8e66564
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
37 deletions
+20
-37
commit_range_reference_filter.rb
lib/gitlab/markdown/commit_range_reference_filter.rb
+10
-33
commit_range_reference_filter_spec.rb
...lib/gitlab/markdown/commit_range_reference_filter_spec.rb
+10
-4
No files found.
lib/gitlab/markdown/commit_range_reference_filter.rb
View file @
6bac823a
...
...
@@ -32,11 +32,8 @@ module Gitlab
# Pattern used to extract commit range references from text
#
# The beginning and ending SHA1 sums can be between 6 and 40 hex
# characters, and the range selection can be double- or triple-dot.
#
# This pattern supports cross-project references.
COMMIT_RANGE_PATTERN
=
/(
#{
PROJECT_PATTERN
}
@)?(?<commit_range>
\h{6,40}\.{2,3}\h{6,40
})/
COMMIT_RANGE_PATTERN
=
/(
#{
PROJECT_PATTERN
}
@)?(?<commit_range>
#{
CommitRange
::
PATTERN
}
)/
def
call
replace_text_nodes_matching
(
COMMIT_RANGE_PATTERN
)
do
|
content
|
...
...
@@ -53,54 +50,34 @@ module Gitlab
# links have `gfm` and `gfm-commit_range` class names attached for
# styling.
def
commit_range_link_filter
(
text
)
self
.
class
.
references_in
(
text
)
do
|
match
,
commit_range
,
project_ref
|
self
.
class
.
references_in
(
text
)
do
|
match
,
id
,
project_ref
|
project
=
self
.
project_from_ref
(
project_ref
)
from_id
,
to_id
=
split_commit_range
(
commit_range
)
range
=
CommitRange
.
new
(
id
,
project
)
if
valid_range?
(
project
,
from_id
,
to_id
)
push_result
(
:commit_range
,
[
commit
(
from_id
),
commit
(
to_id
)]
)
if
range
.
valid_commits?
push_result
(
:commit_range
,
range
.
to_a
)
url
=
url_for_commit_range
(
project
,
from_id
,
to_id
)
url
=
url_for_commit_range
(
project
,
range
)
title
=
"Commits
#{
from_id
}
through
#{
to_id
}
"
title
=
range
.
reference_title
klass
=
reference_class
(
:commit_range
)
project_ref
+=
'@'
if
project_ref
%(<a href="#{url}"
title="#{title}"
class="#{klass}">#{project_ref}#{
commit_
range}</a>)
class="#{klass}">#{project_ref}#{range}</a>)
else
match
end
end
end
def
split_commit_range
(
range
)
from_id
,
to_id
=
range
.
split
(
/\.{2,3}/
,
2
)
from_id
<<
"^"
if
range
!~
/\.{3}/
[
from_id
,
to_id
]
end
def
commit
(
id
)
unless
@commit_map
[
id
]
@commit_map
[
id
]
=
project
.
commit
(
id
)
end
@commit_map
[
id
]
end
def
valid_range?
(
project
,
from_id
,
to_id
)
project
&&
project
.
valid_repo?
&&
commit
(
from_id
)
&&
commit
(
to_id
)
end
def
url_for_commit_range
(
project
,
from_id
,
to_id
)
def
url_for_commit_range
(
project
,
range
)
h
=
Rails
.
application
.
routes
.
url_helpers
h
.
namespace_project_compare_url
(
project
.
namespace
,
project
,
from:
from_id
,
to:
to_id
,
only_path:
context
[
:only_path
])
range
.
to_param
.
merge
(
only_path:
context
[
:only_path
]))
end
end
end
...
...
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
View file @
6bac823a
...
...
@@ -42,13 +42,17 @@ module Gitlab::Markdown
reference
=
"
#{
commit1
.
short_id
}
...
#{
commit2
.
id
}
"
reference2
=
"
#{
commit1
.
id
}
...
#{
commit2
.
short_id
}
"
expect
(
filter
(
"See
#{
reference
}
"
).
css
(
'a'
).
first
.
text
).
to
eq
reference
expect
(
filter
(
"See
#{
reference2
}
"
).
css
(
'a'
).
first
.
text
).
to
eq
reference2
exp
=
commit1
.
short_id
+
'...'
+
commit2
.
short_id
expect
(
filter
(
"See
#{
reference
}
"
).
css
(
'a'
).
first
.
text
).
to
eq
exp
expect
(
filter
(
"See
#{
reference2
}
"
).
css
(
'a'
).
first
.
text
).
to
eq
exp
end
it
'links with adjacent text'
do
doc
=
filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
Regexp
.
escape
(
reference
)
}
<\/a>\.\)/
)
exp
=
Regexp
.
escape
(
"
#{
commit1
.
short_id
}
...
#{
commit2
.
short_id
}
"
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
exp
}
<\/a>\.\)/
)
end
it
'ignores invalid commit IDs'
do
...
...
@@ -107,7 +111,9 @@ module Gitlab::Markdown
it
'links with adjacent text'
do
doc
=
filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
Regexp
.
escape
(
reference
)
}
<\/a>\.\)/
)
exp
=
Regexp
.
escape
(
"
#{
project2
.
path_with_namespace
}
@
#{
commit1
.
short_id
}
...
#{
commit2
.
short_id
}
"
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
exp
}
<\/a>\.\)/
)
end
it
'ignores invalid commit IDs on the referenced project'
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