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
5e0edf57
Commit
5e0edf57
authored
Feb 02, 2018
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bypass commits title markdown on notes
parent
5b73e0eb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
23 deletions
+37
-23
app/services/system_note_service.rb
app/services/system_note_service.rb
+18
-4
changelogs/unreleased/osw-markdown-bypass-for-commit-messages.yml
...gs/unreleased/osw-markdown-bypass-for-commit-messages.yml
+5
-0
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+14
-19
No files found.
app/services/system_note_service.rb
View file @
5e0edf57
...
@@ -22,8 +22,7 @@ module SystemNoteService
...
@@ -22,8 +22,7 @@ module SystemNoteService
commits_text
=
"
#{
total_count
}
commit"
.
pluralize
(
total_count
)
commits_text
=
"
#{
total_count
}
commit"
.
pluralize
(
total_count
)
body
=
"added
#{
commits_text
}
\n\n
"
body
=
"added
#{
commits_text
}
\n\n
"
body
<<
existing_commit_summary
(
noteable
,
existing_commits
,
oldrev
)
body
<<
commits_list
(
noteable
,
new_commits
,
existing_commits
,
oldrev
)
body
<<
new_commit_summary
(
new_commits
).
join
(
"
\n
"
)
body
<<
"
\n\n
[Compare with previous version](
#{
diff_comparison_url
(
noteable
,
project
,
oldrev
)
}
)"
body
<<
"
\n\n
[Compare with previous version](
#{
diff_comparison_url
(
noteable
,
project
,
oldrev
)
}
)"
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'commit'
,
commit_count:
total_count
))
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'commit'
,
commit_count:
total_count
))
...
@@ -481,7 +480,7 @@ module SystemNoteService
...
@@ -481,7 +480,7 @@ module SystemNoteService
# Returns an Array of Strings
# Returns an Array of Strings
def
new_commit_summary
(
new_commits
)
def
new_commit_summary
(
new_commits
)
new_commits
.
collect
do
|
commit
|
new_commits
.
collect
do
|
commit
|
"*
#{
commit
.
short_id
}
-
#{
escape_html
(
commit
.
title
)
}
"
content_tag
(
'li'
,
"
#{
commit
.
short_id
}
-
#{
commit
.
title
}
"
)
end
end
end
end
...
@@ -604,6 +603,16 @@ module SystemNoteService
...
@@ -604,6 +603,16 @@ module SystemNoteService
"
#{
cross_reference_note_prefix
}#{
gfm_reference
}
"
"
#{
cross_reference_note_prefix
}#{
gfm_reference
}
"
end
end
# Builds a list of existing and new commits according to existing_commits and
# new_commits methods.
# Returns a String wrapped in `ul` and `li` tags.
def
commits_list
(
noteable
,
new_commits
,
existing_commits
,
oldrev
)
existing_commit_summary
=
existing_commit_summary
(
noteable
,
existing_commits
,
oldrev
)
new_commit_summary
=
new_commit_summary
(
new_commits
).
join
content_tag
(
'ul'
,
"
#{
existing_commit_summary
}#{
new_commit_summary
}
"
.
html_safe
)
end
# Build a single line summarizing existing commits being added in a merge
# Build a single line summarizing existing commits being added in a merge
# request
# request
#
#
...
@@ -640,7 +649,8 @@ module SystemNoteService
...
@@ -640,7 +649,8 @@ module SystemNoteService
branch
=
noteable
.
target_branch
branch
=
noteable
.
target_branch
branch
=
"
#{
noteable
.
target_project_namespace
}
:
#{
branch
}
"
if
noteable
.
for_fork?
branch
=
"
#{
noteable
.
target_project_namespace
}
:
#{
branch
}
"
if
noteable
.
for_fork?
"*
#{
commit_ids
}
-
#{
commits_text
}
from branch `
#{
branch
}
`
\n
"
branch_name
=
content_tag
(
'code'
,
branch
)
content_tag
(
'li'
,
"
#{
commit_ids
}
-
#{
commits_text
}
from branch
#{
branch_name
}
"
.
html_safe
)
end
end
def
escape_html
(
text
)
def
escape_html
(
text
)
...
@@ -661,4 +671,8 @@ module SystemNoteService
...
@@ -661,4 +671,8 @@ module SystemNoteService
start_sha:
oldrev
start_sha:
oldrev
)
)
end
end
def
content_tag
(
*
args
)
ActionController
::
Base
.
helpers
.
content_tag
(
*
args
)
end
end
end
changelogs/unreleased/osw-markdown-bypass-for-commit-messages.yml
0 → 100644
View file @
5e0edf57
---
title
:
Bypass commits title markdown on notes
merge_request
:
author
:
type
:
fixed
spec/services/system_note_service_spec.rb
View file @
5e0edf57
...
@@ -54,10 +54,11 @@ describe SystemNoteService do
...
@@ -54,10 +54,11 @@ describe SystemNoteService do
expect
(
note_lines
[
0
]).
to
eq
"added
#{
new_commits
.
size
}
commits"
expect
(
note_lines
[
0
]).
to
eq
"added
#{
new_commits
.
size
}
commits"
end
end
it
'adds a message line for each commit'
do
it
'adds a message for each commit'
do
new_commits
.
each_with_index
do
|
commit
,
i
|
decoded_note_content
=
HTMLEntities
.
new
.
decode
(
subject
.
note
)
# Skip the header
expect
(
HTMLEntities
.
new
.
decode
(
note_lines
[
i
+
1
])).
to
eq
"*
#{
commit
.
short_id
}
-
#{
commit
.
title
}
"
new_commits
.
each
do
|
commit
|
expect
(
decoded_note_content
).
to
include
(
"<li>
#{
commit
.
short_id
}
-
#{
commit
.
title
}
</li>"
)
end
end
end
end
end
end
...
@@ -69,7 +70,7 @@ describe SystemNoteService do
...
@@ -69,7 +70,7 @@ describe SystemNoteService do
let
(
:old_commits
)
{
[
noteable
.
commits
.
last
]
}
let
(
:old_commits
)
{
[
noteable
.
commits
.
last
]
}
it
'includes the existing commit'
do
it
'includes the existing commit'
do
expect
(
summary_line
).
to
eq
"*
#{
old_commits
.
first
.
short_id
}
- 1 commit from branch `feature`"
expect
(
summary_line
).
to
start_with
(
"<ul><li>
#{
old_commits
.
first
.
short_id
}
- 1 commit from branch <code>feature</code>"
)
end
end
end
end
...
@@ -79,22 +80,16 @@ describe SystemNoteService do
...
@@ -79,22 +80,16 @@ describe SystemNoteService do
context
'with oldrev'
do
context
'with oldrev'
do
let
(
:oldrev
)
{
noteable
.
commits
[
2
].
id
}
let
(
:oldrev
)
{
noteable
.
commits
[
2
].
id
}
it
'includes a commit range'
do
it
'includes a commit range and count'
do
expect
(
summary_line
).
to
start_with
"*
#{
Commit
.
truncate_sha
(
oldrev
)
}
...
#{
old_commits
.
last
.
short_id
}
"
expect
(
summary_line
)
end
.
to
start_with
(
"<ul><li>
#{
Commit
.
truncate_sha
(
oldrev
)
}
...
#{
old_commits
.
last
.
short_id
}
- 26 commits from branch <code>feature</code>"
)
it
'includes a commit count'
do
expect
(
summary_line
).
to
end_with
" - 26 commits from branch `feature`"
end
end
end
end
context
'without oldrev'
do
context
'without oldrev'
do
it
'includes a commit range'
do
it
'includes a commit range and count'
do
expect
(
summary_line
).
to
start_with
"*
#{
old_commits
[
0
].
short_id
}
..
#{
old_commits
[
-
1
].
short_id
}
"
expect
(
summary_line
)
end
.
to
start_with
(
"<ul><li>
#{
old_commits
[
0
].
short_id
}
..
#{
old_commits
[
-
1
].
short_id
}
- 26 commits from branch <code>feature</code>"
)
it
'includes a commit count'
do
expect
(
summary_line
).
to
end_with
" - 26 commits from branch `feature`"
end
end
end
end
...
@@ -104,7 +99,7 @@ describe SystemNoteService do
...
@@ -104,7 +99,7 @@ describe SystemNoteService do
end
end
it
'includes the project namespace'
do
it
'includes the project namespace'
do
expect
(
summary_line
).
to
end_with
"`
#{
noteable
.
target_project_namespace
}
:feature`"
expect
(
summary_line
).
to
include
(
"<code>
#{
noteable
.
target_project_namespace
}
:feature</code>"
)
end
end
end
end
end
end
...
@@ -693,7 +688,7 @@ describe SystemNoteService do
...
@@ -693,7 +688,7 @@ describe SystemNoteService do
describe
'.new_commit_summary'
do
describe
'.new_commit_summary'
do
it
'escapes HTML titles'
do
it
'escapes HTML titles'
do
commit
=
double
(
title:
'<pre>This is a test</pre>'
,
short_id:
'12345678'
)
commit
=
double
(
title:
'<pre>This is a test</pre>'
,
short_id:
'12345678'
)
escaped
=
'<pre>This is a test<
/
pre>'
escaped
=
'<pre>This is a test<
/
pre>'
expect
(
described_class
.
new_commit_summary
([
commit
])).
to
all
(
match
(
/-
#{
escaped
}
/
))
expect
(
described_class
.
new_commit_summary
([
commit
])).
to
all
(
match
(
/-
#{
escaped
}
/
))
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