Commit f8b4f57e authored by James Ramsay's avatar James Ramsay
Browse files

Merge branch 'release-post-items-image-fixes' into 'master'

Release post items image fixes

See merge request !71717
parents e00116ab 6e03862f
Pipeline #239739930 passed with stages
in 14 minutes and 45 seconds
......@@ -175,17 +175,28 @@ module ReleasePosts
+"#{content.strip}\n"
end
 
# Verbatim image_url in the description
def image_url
return unless matches = raw_content.match(IMAGE_REGEX)
 
matches[:image].to_s
end
 
def image_binary
u = URI(web_url.split('/-/')[0])
def absolute_image_url
return unless image_url
return image_url if image_url =~ URI::DEFAULT_PARSER.make_regexp
# Assuming it's a relative link, construct a valid URL
namespace = web_url.split('/-/')[0]
u = URI(namespace)
u.path += '/-' if epic?
u.path += image_url
u.to_s
end
 
URI.open(u).read
def image_binary
URI.open(absolute_image_url).read
end
 
def image_base64
......
......@@ -244,10 +244,16 @@ module ReleasePosts
def image_commit_action
return unless @issue.image_url
 
{ action: 'create',
file_path: image_path,
content: @issue.image_base64,
encoding: 'base64' }
begin
return {
action: 'create',
file_path: image_path,
content: @issue.image_base64,
encoding: 'base64'
}
rescue StandardError => e
log_error("failed to fetch image #{@issue.image_url}", e.message)
end
end
 
def mr_description
......
......@@ -4,9 +4,10 @@ require_relative '../../lib/release_posts/issue'
describe ReleasePosts::Issue do
let(:complete) do
{
'project_id' => 123,
'idd' => 1,
'title' => 'Gitaly Cluster',
'description' => "## Release notes\nBig [problem](https://docs.gitlab.com/ee/administration/gitaly/praefect.html), simple solution! Example [ of strange `![]` characters.\n\n![](uploads/image.png)\n\nDocs: https://docs.gitlab.com/ee/administration/gitaly/praefect.html\n\n## Proposal\nwhat we're building\n",
'description' => "## Release notes\nBig [problem](https://docs.gitlab.com/ee/administration/gitaly/praefect.html), simple solution! Example [ of strange `![]` characters.\n\n![](/uploads/image.png)\n\nDocs: https://docs.gitlab.com/ee/administration/gitaly/praefect.html\n\n## Proposal\nwhat we're building\n",
'labels' => ['feature', 'group::gitaly', 'devops::create', 'category:Gitaly', 'GitLab Premium', 'GitLab Ultimate'],
'milestone' => {
'title' => '13.2',
......@@ -16,23 +17,45 @@ describe ReleasePosts::Issue do
{ 'username' => 'jramsay' },
{ 'username' => 'zj-gitlab' }
],
'web_url' => 'https://gitlab.com/gitlab-org/gitaly/issues/1'
'web_url' => 'https://gitlab.com/gitlab-org/gitaly/-/issues/1'
}
end
let(:empty) do
{
'project_id' => 123,
'idd' => 1,
'title' => 'Gitaly Cluster',
'description' => "empty",
'labels' => [],
'milestone' => {},
'assignees' => [],
'web_url' => 'https://gitlab.com/gitlab-org/gitaly/issues/1'
'web_url' => 'https://gitlab.com/gitlab-org/gitaly/-/issues/1'
}
end
let(:epic) { ReleasePosts::Issue.new(complete.tap { |k| k.delete('project_id') }, 'top') }
let(:issue) { ReleasePosts::Issue.new(complete, 'primary') }
let(:empty_issue) { ReleasePosts::Issue.new(empty, 'secondary') }
 
describe '#epic?' do
it 'returns true if the Issueable is an Epic' do
expect(epic.epic?).to be_truthy
end
it 'returns false if the Issueable is an Issue' do
expect(issue.epic?).to be_falsey
end
end
describe '#issue?' do
it 'returns true if the Issueable is an Issue' do
expect(issue.issue?).to be_truthy
end
it 'returns false if the Issueable is an Epic' do
expect(epic.issue?).to be_falsey
end
end
describe '#group' do
it 'returns the group that matches the group label' do
expect(issue.group.key).to eq('gitaly')
......@@ -64,8 +87,8 @@ describe ReleasePosts::Issue do
end
 
describe '#image_url' do
it 'returns the first documentation URL from the description' do
expect(issue.image_url).to eq('uploads/image.png')
it 'returns the URL of the first image in the description' do
expect(issue.image_url).to eq('/uploads/image.png')
end
 
it 'returns nil when no content block found' do
......@@ -73,6 +96,20 @@ describe ReleasePosts::Issue do
end
end
 
describe '#absolute_image_url' do
it 'returns the absolute URL of first image in the issue description' do
expect(issue.absolute_image_url).to eq('https://gitlab.com/gitlab-org/gitaly/uploads/image.png')
end
it 'returns the absolute URL of first image in the issue description' do
expect(epic.absolute_image_url).to eq('https://gitlab.com/gitlab-org/gitaly/-/uploads/image.png')
end
it 'returns nil when no content block found' do
expect(empty_issue.absolute_image_url).to be_nil
end
end
describe '#due_date' do
it 'returns the formatted milestone due date when no due date set' do
expect(issue.due_date).to eq('July 18, 2020')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment