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
62c14ba2
Commit
62c14ba2
authored
Dec 01, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Render commit reference using short sha, but include full sha in comment.
parent
bd4ab21c
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
58 additions
and
11 deletions
+58
-11
app/models/commit.rb
app/models/commit.rb
+8
-0
app/models/commit_range.rb
app/models/commit_range.rb
+8
-0
app/models/concerns/referable.rb
app/models/concerns/referable.rb
+4
-0
lib/gitlab/markdown/abstract_reference_filter.rb
lib/gitlab/markdown/abstract_reference_filter.rb
+1
-1
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
...lib/gitlab/markdown/commit_range_reference_filter_spec.rb
+3
-3
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
+1
-1
spec/models/commit_range_spec.rb
spec/models/commit_range_spec.rb
+19
-3
spec/models/commit_spec.rb
spec/models/commit_spec.rb
+14
-3
No files found.
app/models/commit.rb
View file @
62c14ba2
...
...
@@ -86,6 +86,14 @@ class Commit
end
def
to_reference
(
from_project
=
nil
)
if
cross_project_reference?
(
from_project
)
project
.
to_reference
+
self
.
class
.
reference_prefix
+
self
.
id
else
self
.
id
end
end
def
reference_link_text
(
from_project
=
nil
)
if
cross_project_reference?
(
from_project
)
project
.
to_reference
+
self
.
class
.
reference_prefix
+
self
.
short_id
else
...
...
app/models/commit_range.rb
View file @
62c14ba2
...
...
@@ -95,6 +95,14 @@ class CommitRange
alias_method
:id
,
:to_s
def
to_reference
(
from_project
=
nil
)
if
cross_project_reference?
(
from_project
)
reference
=
project
.
to_reference
+
self
.
class
.
reference_prefix
+
self
.
id
else
self
.
id
end
end
def
reference_link_text
(
from_project
=
nil
)
reference
=
ref_from
+
notation
+
ref_to
if
cross_project_reference?
(
from_project
)
...
...
app/models/concerns/referable.rb
View file @
62c14ba2
...
...
@@ -21,6 +21,10 @@ module Referable
''
end
def
reference_link_text
(
from_project
=
nil
)
to_reference
(
from_project
)
end
module
ClassMethods
# The character that prefixes the actual reference identifier
#
...
...
lib/gitlab/markdown/abstract_reference_filter.rb
View file @
62c14ba2
...
...
@@ -82,7 +82,7 @@ module Gitlab
data
=
data_attribute
(
project:
project
.
id
,
object_sym
=>
object
.
id
,
original:
match
)
url
=
matches
[
:url
]
||
url_for_object
(
object
,
project
)
text
=
object
.
to_reference
(
context
[
:project
])
text
=
object
.
reference_link_text
(
context
[
:project
])
extras
=
object_link_text_extras
(
object
,
matches
)
text
+=
" (
#{
extras
.
join
(
", "
)
}
)"
if
extras
.
any?
...
...
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
View file @
62c14ba2
...
...
@@ -53,7 +53,7 @@ module Gitlab::Markdown
it
'links with adjacent text'
do
doc
=
filter
(
"See (
#{
reference
}
.)"
)
exp
=
Regexp
.
escape
(
range
.
to_reference
)
exp
=
Regexp
.
escape
(
range
.
reference_link_text
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
exp
}
<\/a>\.\)/
)
end
...
...
@@ -125,7 +125,7 @@ module Gitlab::Markdown
it
'links with adjacent text'
do
doc
=
filter
(
"Fixed (
#{
reference
}
.)"
)
exp
=
Regexp
.
escape
(
"
#{
project2
.
to_reference
}
@
#{
range
.
to_reference
}
"
)
exp
=
Regexp
.
escape
(
"
#{
project2
.
to_reference
}
@
#{
range
.
reference_link_text
}
"
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
exp
}
<\/a>\.\)/
)
end
...
...
@@ -163,7 +163,7 @@ module Gitlab::Markdown
it
'links with adjacent text'
do
doc
=
filter
(
"Fixed (
#{
reference
}
.)"
)
exp
=
Regexp
.
escape
(
range
.
to_reference
(
project
))
exp
=
Regexp
.
escape
(
range
.
reference_link_text
(
project
))
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
exp
}
<\/a>\.\)/
)
end
...
...
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
View file @
62c14ba2
...
...
@@ -148,7 +148,7 @@ module Gitlab::Markdown
it
'links with adjacent text'
do
doc
=
filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
commit
.
to_reference
(
project
)
}
<\/a>\.\)/
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
commit
.
reference_link_text
(
project
)
}
<\/a>\.\)/
)
end
it
'ignores invalid commit IDs on the referenced project'
do
...
...
spec/models/commit_range_spec.rb
View file @
62c14ba2
...
...
@@ -38,15 +38,31 @@ describe CommitRange do
let
(
:cross
)
{
create
(
:project
)
}
it
'returns a String reference to the object'
do
expect
(
range
.
to_reference
).
to
eq
"
#{
sha_from
}
...
#{
sha_to
}
"
expect
(
range
.
to_reference
).
to
eq
"
#{
full_sha_from
}
...
#{
full_
sha_to
}
"
end
it
'returns a String reference to the object'
do
expect
(
range2
.
to_reference
).
to
eq
"
#{
sha_from
}
..
#{
sha_to
}
"
expect
(
range2
.
to_reference
).
to
eq
"
#{
full_sha_from
}
..
#{
full_
sha_to
}
"
end
it
'supports a cross-project reference'
do
expect
(
range
.
to_reference
(
cross
)).
to
eq
"
#{
project
.
to_reference
}
@
#{
sha_from
}
...
#{
sha_to
}
"
expect
(
range
.
to_reference
(
cross
)).
to
eq
"
#{
project
.
to_reference
}
@
#{
full_sha_from
}
...
#{
full_sha_to
}
"
end
end
describe
'#reference_link_text'
do
let
(
:cross
)
{
create
(
:project
)
}
it
'returns a String reference to the object'
do
expect
(
range
.
reference_link_text
).
to
eq
"
#{
sha_from
}
...
#{
sha_to
}
"
end
it
'returns a String reference to the object'
do
expect
(
range2
.
reference_link_text
).
to
eq
"
#{
sha_from
}
..
#{
sha_to
}
"
end
it
'supports a cross-project reference'
do
expect
(
range
.
reference_link_text
(
cross
)).
to
eq
"
#{
project
.
to_reference
}
@
#{
sha_from
}
...
#{
sha_to
}
"
end
end
...
...
spec/models/commit_spec.rb
View file @
62c14ba2
...
...
@@ -15,12 +15,23 @@ describe Commit do
describe
'#to_reference'
do
it
'returns a String reference to the object'
do
expect
(
commit
.
to_reference
).
to
eq
commit
.
short_
id
expect
(
commit
.
to_reference
).
to
eq
commit
.
id
end
it
'supports a cross-project reference'
do
cross
=
double
(
'project'
)
expect
(
commit
.
to_reference
(
cross
)).
to
eq
"
#{
project
.
to_reference
}
@
#{
commit
.
short_id
}
"
expect
(
commit
.
to_reference
(
cross
)).
to
eq
"
#{
project
.
to_reference
}
@
#{
commit
.
id
}
"
end
end
describe
'#reference_link_text'
do
it
'returns a String reference to the object'
do
expect
(
commit
.
reference_link_text
).
to
eq
commit
.
short_id
end
it
'supports a cross-project reference'
do
cross
=
double
(
'project'
)
expect
(
commit
.
reference_link_text
(
cross
)).
to
eq
"
#{
project
.
to_reference
}
@
#{
commit
.
short_id
}
"
end
end
...
...
@@ -88,7 +99,7 @@ eos
subject
{
create
(
:project
).
commit
}
let
(
:author
)
{
create
(
:user
,
email:
subject
.
author_email
)
}
let
(
:backref_text
)
{
"commit
#{
subject
.
short_
id
}
"
}
let
(
:backref_text
)
{
"commit
#{
subject
.
id
}
"
}
let
(
:set_mentionable_text
)
do
->
(
txt
)
{
allow
(
subject
).
to
receive
(
:safe_message
).
and_return
(
txt
)
}
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