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
9170aab9
Commit
9170aab9
authored
Aug 25, 2016
by
Satish Perala
Committed by
Sean McGivern
Jun 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Passing absolute image urls in the markdown content in the webhooks
parent
b349c01c
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
53 additions
and
2 deletions
+53
-2
app/models/note.rb
app/models/note.rb
+3
-1
app/models/wiki_page.rb
app/models/wiki_page.rb
+3
-1
lib/gitlab/hook_data/issue_builder.rb
lib/gitlab/hook_data/issue_builder.rb
+1
-0
lib/gitlab/hook_data/merge_request_builder.rb
lib/gitlab/hook_data/merge_request_builder.rb
+1
-0
lib/markdown_utils.rb
lib/markdown_utils.rb
+8
-0
spec/lib/gitlab/hook_data/issue_builder_spec.rb
spec/lib/gitlab/hook_data/issue_builder_spec.rb
+9
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+8
-0
spec/models/note_spec.rb
spec/models/note_spec.rb
+8
-0
spec/models/wiki_page_spec.rb
spec/models/wiki_page_spec.rb
+12
-0
No files found.
app/models/note.rb
View file @
9170aab9
...
@@ -202,7 +202,9 @@ class Note < ActiveRecord::Base
...
@@ -202,7 +202,9 @@ class Note < ActiveRecord::Base
end
end
def
hook_attrs
def
hook_attrs
attributes
attributes
.
merge
({
"note"
=>
MarkdownUtils
.
absolute_image_urls
(
self
.
note
)
})
end
end
def
for_commit?
def
for_commit?
...
...
app/models/wiki_page.rb
View file @
9170aab9
...
@@ -59,7 +59,9 @@ class WikiPage
...
@@ -59,7 +59,9 @@ class WikiPage
attr_accessor
:attributes
attr_accessor
:attributes
def
hook_attrs
def
hook_attrs
attributes
attributes
.
merge
({
"content"
=>
MarkdownUtils
.
absolute_image_urls
(
self
.
content
)
})
end
end
def
initialize
(
wiki
,
page
=
nil
,
persisted
=
false
)
def
initialize
(
wiki
,
page
=
nil
,
persisted
=
false
)
...
...
lib/gitlab/hook_data/issue_builder.rb
View file @
9170aab9
...
@@ -38,6 +38,7 @@ module Gitlab
...
@@ -38,6 +38,7 @@ module Gitlab
def
build
def
build
attrs
=
{
attrs
=
{
description:
MarkdownUtils
.
absolute_image_urls
(
issue
.
description
),
url:
Gitlab
::
UrlBuilder
.
build
(
issue
),
url:
Gitlab
::
UrlBuilder
.
build
(
issue
),
total_time_spent:
issue
.
total_time_spent
,
total_time_spent:
issue
.
total_time_spent
,
human_total_time_spent:
issue
.
human_total_time_spent
,
human_total_time_spent:
issue
.
human_total_time_spent
,
...
...
lib/gitlab/hook_data/merge_request_builder.rb
View file @
9170aab9
...
@@ -43,6 +43,7 @@ module Gitlab
...
@@ -43,6 +43,7 @@ module Gitlab
def
build
def
build
attrs
=
{
attrs
=
{
description:
MarkdownUtils
.
absolute_image_urls
(
issue
.
description
),
url:
Gitlab
::
UrlBuilder
.
build
(
merge_request
),
url:
Gitlab
::
UrlBuilder
.
build
(
merge_request
),
source:
merge_request
.
source_project
.
try
(
:hook_attrs
),
source:
merge_request
.
source_project
.
try
(
:hook_attrs
),
target:
merge_request
.
target_project
.
hook_attrs
,
target:
merge_request
.
target_project
.
hook_attrs
,
...
...
lib/markdown_utils.rb
0 → 100644
View file @
9170aab9
# Class to have all utility functions related to markdown
class
MarkdownUtils
# Convert image urls in the markdown text to absolute urls
def
self
.
absolute_image_urls
(
markdown_text
)
markdown_text
.
gsub
(
/!\[(.*?)\]\((.*?)\)/
,
"![
\\
1](
#{
Settings
.
gitlab
.
url
}
\\
2)"
)
end
end
spec/lib/gitlab/hook_data/issue_builder_spec.rb
View file @
9170aab9
...
@@ -40,5 +40,14 @@ describe Gitlab::HookData::IssueBuilder do
...
@@ -40,5 +40,14 @@ describe Gitlab::HookData::IssueBuilder do
expect
(
data
).
to
include
(
:human_total_time_spent
)
expect
(
data
).
to
include
(
:human_total_time_spent
)
expect
(
data
).
to
include
(
:assignee_ids
)
expect
(
data
).
to
include
(
:assignee_ids
)
end
end
context
'when the issue has an image in the description'
do
let
(
:issue_with_description
)
{
create
(
:issue
,
description:
'test![Issue_Image](/uploads/abc/Issue_Image.png)'
)
}
let
(
:builder
)
{
described_class
.
new
(
issue_with_description
)
}
it
'adds absolute urls for images in the description'
do
expect
(
data
[
:description
]).
to
eq
(
"test![Issue_Image](
#{
Settings
.
gitlab
.
url
}
/uploads/abc/Issue_Image.png)"
)
end
end
end
end
end
end
spec/models/merge_request_spec.rb
View file @
9170aab9
...
@@ -2357,4 +2357,12 @@ describe MergeRequest do
...
@@ -2357,4 +2357,12 @@ describe MergeRequest do
end
end
end
end
end
end
describe
'#hook_attrs'
do
let
(
:mr_with_description
)
{
create
(
:merge_request
,
description:
'test![Mr_Image](/uploads/abc/Mr_Image.png)'
)
}
it
'adds absolute urls for images in the description'
do
expect
(
mr_with_description
.
hook_attrs
[
'description'
]).
to
eq
(
"test![Mr_Image](
#{
Settings
.
gitlab
.
url
}
/uploads/abc/Mr_Image.png)"
)
end
end
end
end
spec/models/note_spec.rb
View file @
9170aab9
...
@@ -829,4 +829,12 @@ describe Note do
...
@@ -829,4 +829,12 @@ describe Note do
note
.
destroy!
note
.
destroy!
end
end
end
end
describe
'#hook_attrs'
do
let
(
:note
)
{
create
(
:note
,
note:
'test![Note_Image](/uploads/abc/Note_Image.png)'
)
}
it
'adds absolute urls for images in the description'
do
expect
(
note
.
hook_attrs
[
'note'
]).
to
eq
(
"test![Note_Image](
#{
Settings
.
gitlab
.
url
}
/uploads/abc/Note_Image.png)"
)
end
end
end
end
spec/models/wiki_page_spec.rb
View file @
9170aab9
...
@@ -554,6 +554,18 @@ describe WikiPage do
...
@@ -554,6 +554,18 @@ describe WikiPage do
end
end
end
end
describe
'#hook_attrs'
do
before
do
create_page
(
"test page"
,
"test![WikiPage_Image](/uploads/abc/WikiPage_Image.png)"
)
@page
=
wiki
.
wiki
.
paged
(
"test page"
)
@wiki_page
=
WikiPage
.
new
(
wiki
,
@page
,
true
)
end
it
'adds absolute urls for images in the content'
do
expect
(
@wiki_page
.
hook_attrs
[
'content'
]).
to
eq
(
"test![WikiPage_Image](
#{
Settings
.
gitlab
.
url
}
/uploads/abc/WikiPage_Image.png)"
)
end
end
private
private
def
remove_temp_repo
(
path
)
def
remove_temp_repo
(
path
)
...
...
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