Skip to content
Snippets Groups Projects
Commit 9170aab9 authored by Satish Perala's avatar Satish Perala Committed by Sean McGivern
Browse files

Passing absolute image urls in the markdown content in the webhooks

parent b349c01c
No related branches found
No related tags found
1 merge request!10495Merge Requests - Assignee
Loading
Loading
@@ -202,7 +202,9 @@ class Note < ActiveRecord::Base
end
 
def hook_attrs
attributes
attributes.merge({
"note" => MarkdownUtils.absolute_image_urls(self.note)
})
end
 
def for_commit?
Loading
Loading
Loading
Loading
@@ -59,7 +59,9 @@ class WikiPage
attr_accessor :attributes
 
def hook_attrs
attributes
attributes.merge({
"content" => MarkdownUtils.absolute_image_urls(self.content)
})
end
 
def initialize(wiki, page = nil, persisted = false)
Loading
Loading
Loading
Loading
@@ -38,6 +38,7 @@ module Gitlab
 
def build
attrs = {
description: MarkdownUtils.absolute_image_urls(issue.description),
url: Gitlab::UrlBuilder.build(issue),
total_time_spent: issue.total_time_spent,
human_total_time_spent: issue.human_total_time_spent,
Loading
Loading
Loading
Loading
@@ -43,6 +43,7 @@ module Gitlab
 
def build
attrs = {
description: MarkdownUtils.absolute_image_urls(issue.description),
url: Gitlab::UrlBuilder.build(merge_request),
source: merge_request.source_project.try(:hook_attrs),
target: merge_request.target_project.hook_attrs,
Loading
Loading
# 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
Loading
Loading
@@ -40,5 +40,14 @@ describe Gitlab::HookData::IssueBuilder do
expect(data).to include(:human_total_time_spent)
expect(data).to include(:assignee_ids)
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
Loading
Loading
@@ -2357,4 +2357,12 @@ describe MergeRequest do
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
Loading
Loading
@@ -829,4 +829,12 @@ describe Note do
note.destroy!
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
Loading
Loading
@@ -554,6 +554,18 @@ describe WikiPage do
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
 
def remove_temp_repo(path)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment