Skip to content

Commit

Permalink
Merge pull request #486 from akkee/472-markdown_API
Browse files Browse the repository at this point in the history
Markdown API
  • Loading branch information
Akash Srivastava committed Feb 23, 2019
2 parents 64cabc4 + bd472d8 commit c934d31
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/gitlab/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Client < API
include Jobs
include Keys
include Labels
include Markdown
include MergeRequestApprovals
include MergeRequests
include Milestones
Expand Down
23 changes: 23 additions & 0 deletions lib/gitlab/client/markdown.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

class Gitlab::Client
# Defines methods related to markdown.
# @see https://docs.gitlab.com/ce/api/markdown.html
module Markdown
# Render an arbitrary Markdown document
#
# @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 [Boolean] :gfm(optional) Render text using GitLab Flavored Markdown. Default is false.
# @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 <Gitlab::ObjectifiedHash> Returns the rendered markdown as response
def markdown(text, options = {})
body = { text: text }.merge(options)
post('/markdown', body: body)
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/markdown.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "html": "<p dir=\"auto\">Hello world! <gl-emoji title=\"party popper\" data-name=\"tada\" data-unicode-version=\"6.0\">🎉</gl-emoji></p>" }
17 changes: 17 additions & 0 deletions spec/gitlab/client/markdown_spec.rb
Original file line number Diff line number Diff line change
@@ -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('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

0 comments on commit c934d31

Please sign in to comment.