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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
4dd1f906
Commit
4dd1f906
authored
Apr 06, 2018
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for patch link extension for commit links on GFM
parent
166b4575
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
1 deletion
+44
-1
app/models/commit.rb
app/models/commit.rb
+4
-1
changelogs/unreleased/17939-osw-patch-support-gfm.yml
changelogs/unreleased/17939-osw-patch-support-gfm.yml
+5
-0
lib/banzai/filter/abstract_reference_filter.rb
lib/banzai/filter/abstract_reference_filter.rb
+4
-0
spec/lib/banzai/filter/commit_reference_filter_spec.rb
spec/lib/banzai/filter/commit_reference_filter_spec.rb
+31
-0
No files found.
app/models/commit.rb
View file @
4dd1f906
...
@@ -30,6 +30,8 @@ class Commit
...
@@ -30,6 +30,8 @@ class Commit
MIN_SHA_LENGTH
=
Gitlab
::
Git
::
Commit
::
MIN_SHA_LENGTH
MIN_SHA_LENGTH
=
Gitlab
::
Git
::
Commit
::
MIN_SHA_LENGTH
COMMIT_SHA_PATTERN
=
/\h{
#{
MIN_SHA_LENGTH
}
,40}/
.
freeze
COMMIT_SHA_PATTERN
=
/\h{
#{
MIN_SHA_LENGTH
}
,40}/
.
freeze
# Used by GFM to match and present link extensions on node texts and hrefs.
LINK_EXTENSION_PATTERN
=
/(patch)/
.
freeze
def
banzai_render_context
(
field
)
def
banzai_render_context
(
field
)
pipeline
=
field
==
:description
?
:commit_description
:
:single_line
pipeline
=
field
==
:description
?
:commit_description
:
:single_line
...
@@ -143,7 +145,8 @@ class Commit
...
@@ -143,7 +145,8 @@ class Commit
end
end
def
self
.
link_reference_pattern
def
self
.
link_reference_pattern
@link_reference_pattern
||=
super
(
"commit"
,
/(?<commit>
#{
COMMIT_SHA_PATTERN
}
)/
)
@link_reference_pattern
||=
super
(
"commit"
,
/(?<commit>
#{
COMMIT_SHA_PATTERN
}
)?(\.(?<extension>
#{
LINK_EXTENSION_PATTERN
}
))?/
)
end
end
def
to_reference
(
from
=
nil
,
full:
false
)
def
to_reference
(
from
=
nil
,
full:
false
)
...
...
changelogs/unreleased/17939-osw-patch-support-gfm.yml
0 → 100644
View file @
4dd1f906
---
title
:
Add support for patch link extension for commit links on GitLab Flavored Markdown
merge_request
:
author
:
type
:
added
lib/banzai/filter/abstract_reference_filter.rb
View file @
4dd1f906
...
@@ -213,6 +213,10 @@ module Banzai
...
@@ -213,6 +213,10 @@ module Banzai
extras
<<
"comment
#{
$1
}
"
extras
<<
"comment
#{
$1
}
"
end
end
extension
=
matches
[
:extension
]
if
matches
.
names
.
include?
(
"extension"
)
extras
<<
extension
if
extension
extras
extras
end
end
...
...
spec/lib/banzai/filter/commit_reference_filter_spec.rb
View file @
4dd1f906
...
@@ -207,4 +207,35 @@ describe Banzai::Filter::CommitReferenceFilter do
...
@@ -207,4 +207,35 @@ describe Banzai::Filter::CommitReferenceFilter do
expect
(
reference_filter
(
act
).
to_html
).
to
match
(
%r{<a.+>
#{
Regexp
.
escape
(
invalidate_reference
(
reference
))
}
</a>}
)
expect
(
reference_filter
(
act
).
to_html
).
to
match
(
%r{<a.+>
#{
Regexp
.
escape
(
invalidate_reference
(
reference
))
}
</a>}
)
end
end
end
end
context
'URL reference for a commit patch'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
:repository
,
namespace:
namespace
)
}
let
(
:commit
)
{
project2
.
commit
}
let
(
:link
)
{
urls
.
project_commit_url
(
project2
,
commit
.
id
)
}
let
(
:extension
)
{
'.patch'
}
let
(
:reference
)
{
link
+
extension
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
))
.
to
eq
reference
end
it
'has valid text'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
text
).
to
eq
(
"See
#{
commit
.
reference_link_text
(
project
)
}
(patch)"
)
end
it
'does not link to patch when extension match is after the path'
do
invalidate_commit_reference
=
reference_filter
(
"
#{
link
}
/builds.patch"
)
doc
=
reference_filter
(
"See (
#{
invalidate_commit_reference
}
)"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
"
#{
link
}
/builds"
expect
(
doc
.
text
).
to
eq
(
"See (
#{
commit
.
reference_link_text
(
project
)
}
(builds).patch)"
)
end
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