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
fc1910dd
Commit
fc1910dd
authored
8 years ago
by
Douwe Maan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'adambutler/gitlab-ce-feature/support-diff-of-issue-title-rename'
# Conflicts: # app/services/system_note_service.rb
parents
63f53730
5341b16f
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
192 additions
and
38 deletions
+192
-38
CHANGELOG
CHANGELOG
+2
-0
app/assets/stylesheets/framework/files.scss
app/assets/stylesheets/framework/files.scss
+0
-16
app/assets/stylesheets/framework/typography.scss
app/assets/stylesheets/framework/typography.scss
+8
-0
app/assets/stylesheets/framework/variables.scss
app/assets/stylesheets/framework/variables.scss
+1
-0
app/helpers/diff_helper.rb
app/helpers/diff_helper.rb
+2
-2
app/services/system_note_service.rb
app/services/system_note_service.rb
+8
-1
app/views/projects/diffs/_file.html.haml
app/views/projects/diffs/_file.html.haml
+2
-4
doc/markdown/markdown.md
doc/markdown/markdown.md
+14
-0
lib/banzai/filter/inline_diff_filter.rb
lib/banzai/filter/inline_diff_filter.rb
+22
-0
lib/banzai/pipeline/gfm_pipeline.rb
lib/banzai/pipeline/gfm_pipeline.rb
+2
-1
lib/gitlab/diff/inline_diff_marker.rb
lib/gitlab/diff/inline_diff_marker.rb
+29
-7
spec/features/markdown_spec.rb
spec/features/markdown_spec.rb
+4
-0
spec/fixtures/markdown.md.erb
spec/fixtures/markdown.md.erb
+13
-0
spec/helpers/diff_helper_spec.rb
spec/helpers/diff_helper_spec.rb
+2
-2
spec/lib/banzai/filter/inline_diff_filter_spec.rb
spec/lib/banzai/filter/inline_diff_filter_spec.rb
+68
-0
spec/services/issues/update_service_spec.rb
spec/services/issues/update_service_spec.rb
+2
-2
spec/services/merge_requests/update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+2
-2
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+1
-1
spec/support/matchers/markdown_matchers.rb
spec/support/matchers/markdown_matchers.rb
+10
-0
No files found.
CHANGELOG
View file @
fc1910dd
...
...
@@ -9,6 +9,8 @@ v 8.8.0 (unreleased)
- Use a case-insensitive comparison in sanitizing URI schemes
- Toggle sign-up confirmation emails in application settings
- Make it possible to prevent tagged runner from picking untagged jobs
- Added `InlineDiffFilter` to the markdown parser. (Adam Butler)
- Added inline diff styling for `change_title` system notes. (Adam Butler)
- Project#open_branches has been cleaned up and no longer loads entire records into memory.
- Escape HTML in commit titles in system note messages
- Fix creation of Ci::Commit object which can lead to pending, failed in some scenarios
...
...
This diff is collapsed.
Click to expand it.
app/assets/stylesheets/framework/files.scss
View file @
fc1910dd
...
...
@@ -36,22 +36,6 @@
}
}
.filename
{
&
.old
{
display
:
inline-block
;
span
.idiff
{
background-color
:
#f8cbcb
;
}
}
&
.new
{
display
:
inline-block
;
span
.idiff
{
background-color
:
#a6f3a6
;
}
}
}
a
:not
(
.btn
)
{
color
:
$gl-dark-link-color
;
}
...
...
This diff is collapsed.
Click to expand it.
app/assets/stylesheets/framework/typography.scss
View file @
fc1910dd
...
...
@@ -269,3 +269,11 @@ h1, h2, h3, h4 {
text-align
:
right
;
}
}
.idiff.deletion
{
background
:
$line-removed-dark
;
}
.idiff.addition
{
background
:
$line-added-dark
;
}
This diff is collapsed.
Click to expand it.
app/assets/stylesheets/framework/variables.scss
View file @
fc1910dd
...
...
@@ -178,6 +178,7 @@ $table-border-gray: #f0f0f0;
$line-target-blue
:
#eaf3fc
;
$line-select-yellow
:
#fcf8e7
;
$line-select-yellow-dark
:
#f0e2bd
;
/*
* Fonts
*/
...
...
This diff is collapsed.
Click to expand it.
app/helpers/diff_helper.rb
View file @
fc1910dd
...
...
@@ -2,8 +2,8 @@ module DiffHelper
def
mark_inline_diffs
(
old_line
,
new_line
)
old_diffs
,
new_diffs
=
Gitlab
::
Diff
::
InlineDiff
.
new
(
old_line
,
new_line
).
inline_diffs
marked_old_line
=
Gitlab
::
Diff
::
InlineDiffMarker
.
new
(
old_line
).
mark
(
old_diffs
)
marked_new_line
=
Gitlab
::
Diff
::
InlineDiffMarker
.
new
(
new_line
).
mark
(
new_diffs
)
marked_old_line
=
Gitlab
::
Diff
::
InlineDiffMarker
.
new
(
old_line
).
mark
(
old_diffs
,
mode: :deletion
)
marked_new_line
=
Gitlab
::
Diff
::
InlineDiffMarker
.
new
(
new_line
).
mark
(
new_diffs
,
mode: :addition
)
[
marked_old_line
,
marked_new_line
]
end
...
...
This diff is collapsed.
Click to expand it.
app/services/system_note_service.rb
View file @
fc1910dd
...
...
@@ -169,7 +169,14 @@ class SystemNoteService
#
# Returns the created Note object
def
self
.
change_title
(
noteable
,
project
,
author
,
old_title
)
body
=
"Title changed from **
#{
old_title
}
** to **
#{
noteable
.
title
}
**"
new_title
=
noteable
.
title
.
dup
old_diffs
,
new_diffs
=
Gitlab
::
Diff
::
InlineDiff
.
new
(
old_title
,
new_title
).
inline_diffs
marked_old_title
=
Gitlab
::
Diff
::
InlineDiffMarker
.
new
(
old_title
).
mark
(
old_diffs
,
mode: :deletion
,
markdown:
true
)
marked_new_title
=
Gitlab
::
Diff
::
InlineDiffMarker
.
new
(
new_title
).
mark
(
new_diffs
,
mode: :addition
,
markdown:
true
)
body
=
"Changed title: **
#{
marked_old_title
}
** → **
#{
marked_new_title
}
**"
create_note
(
noteable:
noteable
,
project:
project
,
author:
author
,
note:
body
)
end
...
...
This diff is collapsed.
Click to expand it.
app/views/projects/diffs/_file.html.haml
View file @
fc1910dd
...
...
@@ -11,11 +11,9 @@
=
link_to
"#diff-
#{
i
}
"
do
-
if
diff_file
.
renamed_file
-
old_path
,
new_path
=
mark_inline_diffs
(
diff_file
.
old_path
,
diff_file
.
new_path
)
.filename.old
=
old_path
=
old_path
→
.filename.new
=
new_path
=
new_path
-
else
%span
=
diff_file
.
new_path
...
...
This diff is collapsed.
Click to expand it.
doc/markdown/markdown.md
View file @
fc1910dd
...
...
@@ -8,6 +8,7 @@
*
[
Multiple underscores in words
](
#multiple-underscores-in-words
)
*
[
URL auto-linking
](
#url-auto-linking
)
*
[
Code and Syntax Highlighting
](
#code-and-syntax-highlighting
)
*
[
Inline Diff
](
#inline-diff
)
*
[
Emoji
](
#emoji
)
*
[
Special GitLab references
](
#special-gitlab-references
)
*
[
Task lists
](
#task-lists
)
...
...
@@ -153,6 +154,19 @@ s = "There is no highlighting for this."
But let's throw in a
<b>
tag
</b>
.
```
## Inline Diff
With inline diffs tags you can display {+ additions +} or [- deletions -].
The wrapping tags can be either curly braces or square brackets [+ additions +] or {- deletions -}.
However the wrapping tags cannot be mixed as such:
- {+ additions +]
- [+ additions +}
- {- deletions -]
- [- deletions -}
## Emoji
Sometimes you want to :monkey: around a bit and add some :star2: to your :speech_balloon:. Well we have a gift for you:
...
...
This diff is collapsed.
Click to expand it.
lib/banzai/filter/inline_diff_filter.rb
0 → 100644
View file @
fc1910dd
module
Banzai
module
Filter
class
InlineDiffFilter
<
HTML
::
Pipeline
::
Filter
IGNORED_ANCESTOR_TAGS
=
%w(pre code tt)
.
to_set
def
call
search_text_nodes
(
doc
).
each
do
|
node
|
next
if
has_ancestor?
(
node
,
IGNORED_ANCESTOR_TAGS
)
content
=
node
.
to_html
content
=
content
.
gsub
(
/(?:\[\-(.*?)\-\]|\{\-(.*?)\-\})/
,
'<span class="idiff left right deletion">\1\2</span>'
)
content
=
content
.
gsub
(
/(?:\[\+(.*?)\+\]|\{\+(.*?)\+\})/
,
'<span class="idiff left right addition">\1\2</span>'
)
next
if
html
==
content
node
.
replace
(
content
)
end
doc
end
end
end
end
This diff is collapsed.
Click to expand it.
lib/banzai/pipeline/gfm_pipeline.rb
View file @
fc1910dd
...
...
@@ -23,7 +23,8 @@ module Banzai
Filter
::
LabelReferenceFilter
,
Filter
::
MilestoneReferenceFilter
,
Filter
::
TaskListFilter
Filter
::
TaskListFilter
,
Filter
::
InlineDiffFilter
]
end
...
...
This diff is collapsed.
Click to expand it.
lib/gitlab/diff/inline_diff_marker.rb
View file @
fc1910dd
module
Gitlab
module
Diff
class
InlineDiffMarker
MARKDOWN_SYMBOLS
=
{
addition:
"+"
,
deletion:
"-"
}
attr_accessor
:raw_line
,
:rich_line
def
initialize
(
raw_line
,
rich_line
=
raw_line
)
...
...
@@ -8,7 +13,7 @@ module Gitlab
@rich_line
=
ERB
::
Util
.
html_escape
(
rich_line
)
end
def
mark
(
line_inline_diffs
)
def
mark
(
line_inline_diffs
,
mode:
nil
,
markdown:
false
)
return
rich_line
unless
line_inline_diffs
marker_ranges
=
[]
...
...
@@ -20,13 +25,22 @@ module Gitlab
end
offset
=
0
# Mark each range
marker_ranges
.
each_with_index
do
|
range
,
i
|
class_names
=
[
"idiff"
]
class_names
<<
"left"
if
i
==
0
class_names
<<
"right"
if
i
==
marker_ranges
.
length
-
1
offset
=
insert_around_range
(
rich_line
,
range
,
"<span class='
#{
class_names
.
join
(
" "
)
}
'>"
,
"</span>"
,
offset
)
# Mark each range
marker_ranges
.
each_with_index
do
|
range
,
index
|
before_content
=
if
markdown
"{
#{
MARKDOWN_SYMBOLS
[
mode
]
}
"
else
"<span class='
#{
html_class_names
(
marker_ranges
,
mode
,
index
)
}
'>"
end
after_content
=
if
markdown
"
#{
MARKDOWN_SYMBOLS
[
mode
]
}
}"
else
"</span>"
end
offset
=
insert_around_range
(
rich_line
,
range
,
before_content
,
after_content
,
offset
)
end
rich_line
.
html_safe
...
...
@@ -34,6 +48,14 @@ module Gitlab
private
def
html_class_names
(
marker_ranges
,
mode
,
index
)
class_names
=
[
"idiff"
]
class_names
<<
"left"
if
index
==
0
class_names
<<
"right"
if
index
==
marker_ranges
.
length
-
1
class_names
<<
mode
if
mode
class_names
.
join
(
" "
)
end
# Mapping of character positions in the raw line, to the rich (highlighted) line
def
position_mapping
@position_mapping
||=
begin
...
...
This diff is collapsed.
Click to expand it.
spec/features/markdown_spec.rb
View file @
fc1910dd
...
...
@@ -278,6 +278,10 @@ describe 'GitLab Markdown', feature: true do
it
'includes GollumTagsFilter'
do
expect
(
doc
).
to
parse_gollum_tags
end
it
'includes InlineDiffFilter'
do
expect
(
doc
).
to
parse_inline_diffs
end
end
# Fake a `current_user` helper
...
...
This diff is collapsed.
Click to expand it.
spec/fixtures/markdown.md.erb
View file @
fc1910dd
...
...
@@ -243,3 +243,16 @@ References should be parseable even inside _<%= merge_request.to_reference %>_ e
- [[link-text|http://example.com/pdfs/gollum.pdf]]
- [[images/example.jpg]]
- [[http://example.com/images/example.jpg]]
### Inline Diffs
With inline diffs tags you can display {+ additions +} or [- deletions -].
The wrapping tags can be either curly braces or square brackets [+ additions +] or {- deletions -}.
However the wrapping tags can not be mixed as such -
- {+ additions +]
- [+ additions +}
- {- delletions -]
- [- delletions -}
This diff is collapsed.
Click to expand it.
spec/helpers/diff_helper_spec.rb
View file @
fc1910dd
...
...
@@ -93,9 +93,9 @@ describe DiffHelper do
it
"returns strings with marked inline diffs"
do
marked_old_line
,
marked_new_line
=
mark_inline_diffs
(
old_line
,
new_line
)
expect
(
marked_old_line
).
to
eq
(
"abc <span class='idiff left right'>'def'</span>"
)
expect
(
marked_old_line
).
to
eq
(
"abc <span class='idiff left right
deletion
'>'def'</span>"
)
expect
(
marked_old_line
).
to
be_html_safe
expect
(
marked_new_line
).
to
eq
(
"abc <span class='idiff left right'>"def"</span>"
)
expect
(
marked_new_line
).
to
eq
(
"abc <span class='idiff left right
addition
'>"def"</span>"
)
expect
(
marked_new_line
).
to
be_html_safe
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/lib/banzai/filter/inline_diff_filter_spec.rb
0 → 100644
View file @
fc1910dd
require
'spec_helper'
describe
Banzai
::
Filter
::
InlineDiffFilter
,
lib:
true
do
include
FilterSpecHelper
it
'adds inline diff span tags for deletions when using square brackets'
do
doc
=
"START [-something deleted-] END"
expect
(
filter
(
doc
).
to_html
).
to
eq
(
'START <span class="idiff left right deletion">something deleted</span> END'
)
end
it
'adds inline diff span tags for deletions when using curley braces'
do
doc
=
"START {-something deleted-} END"
expect
(
filter
(
doc
).
to_html
).
to
eq
(
'START <span class="idiff left right deletion">something deleted</span> END'
)
end
it
'does not add inline diff span tags when a closing tag is not provided'
do
doc
=
"START [- END"
expect
(
filter
(
doc
).
to_html
).
to
eq
(
doc
)
end
it
'adds inline span tags for additions when using square brackets'
do
doc
=
"START [+something added+] END"
expect
(
filter
(
doc
).
to_html
).
to
eq
(
'START <span class="idiff left right addition">something added</span> END'
)
end
it
'adds inline span tags for additions when using curley braces'
do
doc
=
"START {+something added+} END"
expect
(
filter
(
doc
).
to_html
).
to
eq
(
'START <span class="idiff left right addition">something added</span> END'
)
end
it
'does not add inline diff span tags when a closing addition tag is not provided'
do
doc
=
"START {+ END"
expect
(
filter
(
doc
).
to_html
).
to
eq
(
doc
)
end
it
'does not add inline diff span tags when the tags do not match'
do
examples
=
[
"{+ additions +]"
,
"[+ additions +}"
,
"{- delletions -]"
,
"[- delletions -}"
]
examples
.
each
do
|
doc
|
expect
(
filter
(
doc
).
to_html
).
to
eq
(
doc
)
end
end
it
'prevents user-land html being injected'
do
doc
=
"START {+<script>alert('I steal cookies')</script>+} END"
expect
(
filter
(
doc
).
to_html
).
to
eq
(
"START <span class=
\"
idiff left right addition
\"
><script>alert('I steal cookies')</script></span> END"
)
end
it
'preserves content inside pre tags'
do
doc
=
"<pre>START {+something added+} END</pre>"
expect
(
filter
(
doc
).
to_html
).
to
eq
(
doc
)
end
it
'preserves content inside code tags'
do
doc
=
"<code>START {+something added+} END</code>"
expect
(
filter
(
doc
).
to_html
).
to
eq
(
doc
)
end
it
'preserves content inside tt tags'
do
doc
=
"<tt>START {+something added+} END</tt>"
expect
(
filter
(
doc
).
to_html
).
to
eq
(
doc
)
end
end
This diff is collapsed.
Click to expand it.
spec/services/issues/update_service_spec.rb
View file @
fc1910dd
...
...
@@ -75,10 +75,10 @@ describe Issues::UpdateService, services: true do
end
it
'creates system note about title change'
do
note
=
find_note
(
'
Title changed
'
)
note
=
find_note
(
'
Changed title:
'
)
expect
(
note
).
not_to
be_nil
expect
(
note
.
note
).
to
eq
'
Title changed from **Old title** to **New
title**'
expect
(
note
.
note
).
to
eq
'
Changed title: **{-Old-} title** → **{+New+}
title**'
end
it
'creates system note about confidentiality change'
do
...
...
This diff is collapsed.
Click to expand it.
spec/services/merge_requests/update_service_spec.rb
View file @
fc1910dd
...
...
@@ -90,10 +90,10 @@ describe MergeRequests::UpdateService, services: true do
end
it
'creates system note about title change'
do
note
=
find_note
(
'
Title changed
'
)
note
=
find_note
(
'
Changed title:
'
)
expect
(
note
).
not_to
be_nil
expect
(
note
.
note
).
to
eq
'
Title changed from **Old title** to **New
title**'
expect
(
note
.
note
).
to
eq
'
Changed title: **{-Old-} title** → **{+New+}
title**'
end
it
'creates system note about branch change'
do
...
...
This diff is collapsed.
Click to expand it.
spec/services/system_note_service_spec.rb
View file @
fc1910dd
...
...
@@ -241,7 +241,7 @@ describe SystemNoteService, services: true do
it
'sets the note text'
do
expect
(
subject
.
note
).
to
eq
"
Title changed from **Old title** to **
#{
noteable
.
title
}
**"
to
eq
"
Changed title: **{-Old title-}** → **{+
#{
noteable
.
title
}
+
}**"
end
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/support/matchers/markdown_matchers.rb
View file @
fc1910dd
...
...
@@ -168,6 +168,16 @@ module MarkdownMatchers
expect
(
actual
).
to
have_selector
(
'input[checked]'
,
count:
3
)
end
end
# InlineDiffFilter
matcher
:parse_inline_diffs
do
set_default_markdown_messages
match
do
|
actual
|
expect
(
actual
).
to
have_selector
(
'span.idiff.addition'
,
count:
2
)
expect
(
actual
).
to
have_selector
(
'span.idiff.deletion'
,
count:
2
)
end
end
end
# Monkeypatch the matcher DSL so that we can reduce some noisy duplication for
...
...
This diff is collapsed.
Click to expand it.
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