From 02aa5c09e7e01d2d2c9586de86ada166171e127e Mon Sep 17 00:00:00 2001 From: Akash Srivastava Date: Sat, 23 Feb 2019 19:01:55 +0530 Subject: [PATCH 1/2] Markdown API --- lib/gitlab/client.rb | 1 + lib/gitlab/client/markdown.rb | 22 ++++++++++++++++++++++ spec/fixtures/markdown.json | 1 + spec/gitlab/client/markdown_spec.rb | 17 +++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 lib/gitlab/client/markdown.rb create mode 100644 spec/fixtures/markdown.json create mode 100644 spec/gitlab/client/markdown_spec.rb diff --git a/lib/gitlab/client.rb b/lib/gitlab/client.rb index d831f56d0..e0552010e 100644 --- a/lib/gitlab/client.rb +++ b/lib/gitlab/client.rb @@ -28,6 +28,7 @@ class Client < API include Jobs include Keys include Labels + include Markdown include MergeRequestApprovals include MergeRequests include Milestones diff --git a/lib/gitlab/client/markdown.rb b/lib/gitlab/client/markdown.rb new file mode 100644 index 000000000..b13800318 --- /dev/null +++ b/lib/gitlab/client/markdown.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class Gitlab::Client + # Defines methods related to markdown. + # @see https://docs.gitlab.com/ce/api/avatar.html + module Markdown + # Render an arbitrary Markdown document + # + # @example + # Gitlab.markdown(text: 'Hello world! :tada:') + # Gitlab.markdown(text: 'Hello world! :tada:', gfm: true, project: 'group_example/project_example') + # + # @param [Hash] options A customizable set of options. + # @option options [String] :text(required) The markdown text to render. + # @option options [Boolean] :gfm(optional) Render text using GitLab Flavored Markdown. Default is false. + # @option options [String] :project(required) Use project as a context when creating references using GitLab Flavored Markdown. Authentication is required if a project is not public. + # @return Returns the rendered markdown as response + def markdown(options = {}) + post('/markdown', body: options) + end + end +end diff --git a/spec/fixtures/markdown.json b/spec/fixtures/markdown.json new file mode 100644 index 000000000..66cd28d95 --- /dev/null +++ b/spec/fixtures/markdown.json @@ -0,0 +1 @@ +{ "html": "

Hello world! 🎉

" } diff --git a/spec/gitlab/client/markdown_spec.rb b/spec/gitlab/client/markdown_spec.rb new file mode 100644 index 000000000..96f968e5a --- /dev/null +++ b/spec/gitlab/client/markdown_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Client do + describe '.markdown' do + before do + stub_post('/markdown', 'markdown') + Gitlab.markdown(text: 'Hello world! :tada:', gfm: true, project: 'group_example/project_example') + end + + it 'gets the correct resource' do + expect(a_post('/markdown') + .with(body: { text: 'Hello world! :tada:', gfm: true, project: 'group_example/project_example' })).to have_been_made + end + end +end From bd472d8a79bdd4ac154ac66a29fecb1b76cc414c Mon Sep 17 00:00:00 2001 From: Akash Srivastava Date: Sat, 23 Feb 2019 19:48:10 +0530 Subject: [PATCH 2/2] Doc and argument fixes in markdown API --- lib/gitlab/client/markdown.rb | 15 ++++++++------- spec/gitlab/client/markdown_spec.rb | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/gitlab/client/markdown.rb b/lib/gitlab/client/markdown.rb index b13800318..79926876b 100644 --- a/lib/gitlab/client/markdown.rb +++ b/lib/gitlab/client/markdown.rb @@ -2,21 +2,22 @@ class Gitlab::Client # Defines methods related to markdown. - # @see https://docs.gitlab.com/ce/api/avatar.html + # @see https://docs.gitlab.com/ce/api/markdown.html module Markdown # Render an arbitrary Markdown document # # @example - # Gitlab.markdown(text: 'Hello world! :tada:') - # Gitlab.markdown(text: 'Hello world! :tada:', gfm: true, project: 'group_example/project_example') + # Gitlab.markdown('Hello world! :tada:') + # Gitlab.markdown('Hello world! :tada:', gfm: true, project: 'group_example/project_example') # + # @param [String] text The markdown text to render. # @param [Hash] options A customizable set of options. - # @option options [String] :text(required) The markdown text to render. # @option options [Boolean] :gfm(optional) Render text using GitLab Flavored Markdown. Default is false. - # @option options [String] :project(required) Use project as a context when creating references using GitLab Flavored Markdown. Authentication is required if a project is not public. + # @option options [String] :project(optional) Use project as a context when creating references using GitLab Flavored Markdown. Authentication is required if a project is not public. # @return Returns the rendered markdown as response - def markdown(options = {}) - post('/markdown', body: options) + def markdown(text, options = {}) + body = { text: text }.merge(options) + post('/markdown', body: body) end end end diff --git a/spec/gitlab/client/markdown_spec.rb b/spec/gitlab/client/markdown_spec.rb index 96f968e5a..6d123077c 100644 --- a/spec/gitlab/client/markdown_spec.rb +++ b/spec/gitlab/client/markdown_spec.rb @@ -6,7 +6,7 @@ describe '.markdown' do before do stub_post('/markdown', 'markdown') - Gitlab.markdown(text: 'Hello world! :tada:', gfm: true, project: 'group_example/project_example') + Gitlab.markdown('Hello world! :tada:', gfm: true, project: 'group_example/project_example') end it 'gets the correct resource' do