Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown API #486

Merged
merged 2 commits into from
Feb 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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