Commit 00c3a3f6 authored by Sean Arnold's avatar Sean Arnold

Add url_text to create metric image API response

parent 31d4b47d
......@@ -2422,10 +2422,11 @@ POST /projects/:id/issues/:issue_iid/metric_images
| `issue_iid` | integer | yes | The internal ID of a project's issue |
| `file` | file | yes | The image file to be uploaded |
| `url` | string | no | The URL to view more metric information |
| `url_text` | string | no | A description of the image or URL |
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" --form 'file=@/path/to/file.png' \
--form 'url=http://example.com' "https://gitlab.example.com/api/v4/projects/5/issues/93/metric_images"
--form 'url=http://example.com' --form 'url_text=Example website' "https://gitlab.example.com/api/v4/projects/5/issues/93/metric_images"
```
Example response:
......@@ -2436,7 +2437,8 @@ Example response:
"created_at": "2020-11-13T00:06:18.084Z",
"filename": "file.png",
"file_path": "/uploads/-/system/issuable_metric_image/file/23/file.png",
"url": "http://example.com"
"url": "http://example.com",
"url_text": "Example website"
}
```
......
......@@ -10,6 +10,7 @@ module IncidentManagement
@project = issuable&.project
@file = params.fetch(:file)
@url = params.fetch(:url, nil)
@url_text = params.fetch(:url_text, nil)
end
def execute
......@@ -22,7 +23,7 @@ module IncidentManagement
ServiceResponse.error(message: e.message)
end
attr_reader :issuable, :project, :file, :url, :metric
attr_reader :issuable, :project, :file, :url, :url_text, :metric
private
......@@ -30,7 +31,8 @@ module IncidentManagement
@metric = IssuableMetricImage.create!(
issue: issuable,
file: file,
url: url
url: url,
url_text: url_text
)
end
......
......@@ -5,7 +5,7 @@ module EE
module Entities
class IssuableMetricImage < Grape::Entity
expose :id, :created_at
expose :filename, :file_path, :url
expose :filename, :file_path, :url, :url_text
end
end
end
......
......@@ -34,6 +34,7 @@ module EE
params do
requires :file, type: ::API::Validations::Types::WorkhorseFile, desc: 'The image file to be uploaded'
optional :url, type: String, desc: 'The url to view more metric info'
optional :url_text, type: String, desc: 'A description of the image or URL'
end
post do
require_gitlab_workhorse!
......@@ -44,7 +45,7 @@ module EE
upload = ::IncidentManagement::Incidents::UploadMetricService.new(
issue,
current_user,
params.slice(:file, :url)
params.slice(:file, :url, :url_text)
).execute
if upload.success?
......
......@@ -583,8 +583,9 @@ RSpec.describe API::Issues, :mailer do
let(:file) { fixture_file_upload('spec/fixtures/rails_sample.jpg', 'image/jpg') }
let(:file_name) { 'rails_sample.jpg' }
let(:url) { 'http://gitlab.com' }
let(:url_text) { 'GitLab' }
let(:params) { { url: url } }
let(:params) { { url: url, url_text: url_text } }
subject do
workhorse_finalize(
......@@ -604,6 +605,7 @@ RSpec.describe API::Issues, :mailer do
expect(response).to have_gitlab_http_status(:created)
expect(json_response['filename']).to eq(file_name)
expect(json_response['url']).to eq(url)
expect(json_response['url_text']).to eq(url_text)
expect(json_response['file_path']).to match(%r{/uploads/-/system/issuable_metric_image/file/[\d+]/#{file_name}})
expect(json_response['created_at']).not_to be_nil
expect(json_response['id']).not_to be_nil
......@@ -701,7 +703,8 @@ RSpec.describe API::Issues, :mailer do
created_at: image.created_at.strftime('%Y-%m-%dT%H:%M:%S.%LZ'),
filename: image.filename,
file_path: image.file_path,
url: image.url
url: image.url,
url_text: nil
}.with_indifferent_access
)
end
......
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