Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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 @@ -43,6 +43,7 @@ class Client < API
include Todos
include Users
include Versions
include Wikis

# Text representation of the client, masking private token.
#
Expand Down
79 changes: 79 additions & 0 deletions lib/gitlab/client/wikis.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# frozen_string_literal: true

class Gitlab::Client
# Defines methods related to wikis.
# @see https://docs.gitlab.com/ce/api/wikis.html
module Wikis
# Get all wiki pages for a given project.
#
# @example
# Gitlab.wikis(3)
# Gitlab.wikis(3, {with_content: 'Some wiki content'})
#
# @param [Integer, String] project The ID or name of a project.
# @param [Hash] options A customizable set of options.
# @option options [String] :with_content(optional) Include pages content
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is :with_content supposed to be a symbol?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it is, but the other options in this file aren't symbols, that should probably be fixed :)

# @return [Array<Gitlab::ObjectifiedHash>]
def wikis(project, options = {})
get("/projects/#{url_encode project}/wikis", query: options)
end

# Get a wiki page for a given project.
#
# @example
# Gitlab.wiki(3, 'home')
#
# @param [Integer, String] project The ID or name of a project.
# @param [String] slug The slug (a unique string) of the wiki page
# @return [Gitlab::ObjectifiedHash]
def wiki(project, slug)
get("/projects/#{url_encode project}/wikis/#{slug}")
end

# Creates a new wiki page for the given repository with the given title, slug, and content.
#
# @example
# Gitlab.create_wiki(3, 'Some Content', 'Some Title')
# Gitlab.create_wiki(3, 'Some Content', 'Some Title', { format: 'rdoc' })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The content and title need to be switched here, and in the parameters below

#
# @param [Integer, String] project The ID or name of a project.
# @param [String] content The content of the wiki page.
# @param [String] title The title of the wiki page.
# @param [Hash] options A customizable set of options.
# @option options [String] format (optional) The format of the wiki page. Available formats are: markdown (default), rdoc, and asciidoc.
# @return [Gitlab::ObjectifiedHash] Information about created wiki page.
def create_wiki(project, title, content, options = {})
body = { content: content, title: title }.merge(options)
post("/projects/#{url_encode project}/wikis", body: body)
end

# Updates an existing wiki page. At least one parameter is required to update the wiki page.
#
# @example
# Gitlab.update_wiki(6, 'home', { title: 'New title' })
# Gitlab.update_wiki(6, 'home', { title: 'New title', message: 'New Message', format: 'rdoc' })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is welcome

#
# @param [Integer, String] project The ID or name of a project.
# @param [String] slug The slug (a unique string) of the wiki page.
# @param [Hash] options A customizable set of options.
# @option options [String] content The content of the wiki page.
# @option options [String] title The title of the wiki page.
# @option options [String] format (optional) The format of the wiki page. Available formats are: markdown (default), rdoc, and asciidoc.
# @return [Gitlab::ObjectifiedHash] Information about updated wiki page.
def update_wiki(project, slug, options = {})
put("/projects/#{url_encode project}/wikis/#{slug}", body: options)
end

# Deletes a wiki page with a given slug.
#
# @example
# Gitlab.delete_wiki(42, 'foo')
#
# @param [Integer, String] project The ID or name of a project.
# @param [String] slug The slug (a unique string) of the wiki page.
# @return [Gitlab::ObjectifiedHash] An empty objectified hash
def delete_wiki(project, slug)
delete("/projects/#{url_encode project}/wikis/#{slug}")
end
end
end
7 changes: 7 additions & 0 deletions spec/fixtures/wiki.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"content" : "home page",
"format" : "markdown",
"slug" : "home",
"title" : "home"
}

9 changes: 9 additions & 0 deletions spec/fixtures/wiki_attachment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"file_name" : "dk.png",
"file_path" : "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png",
"branch" : "master",
"link" : {
"url" : "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png",
"markdown" : "![dk](uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png)"
}
}
19 changes: 19 additions & 0 deletions spec/fixtures/wikis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"content" : "Here is an instruction how to deploy this project.",
"format" : "markdown",
"slug" : "deploy",
"title" : "deploy"
},
{
"content" : "Our development process is described here.",
"format" : "markdown",
"slug" : "development",
"title" : "development"
},{
"content" : "* [Deploy](deploy)\n* [Development](development)",
"format" : "markdown",
"slug" : "home",
"title" : "home"
}
]
79 changes: 79 additions & 0 deletions spec/gitlab/client/wikis_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::Client do
describe '.wikis' do
before do
stub_get('/projects/1/wikis', 'wikis')
@wikis = Gitlab.wikis(1)
end

it 'gets the correct resource' do
expect(a_get('/projects/1/wikis')).to have_been_made
end

it "returns a response of a project's wikis" do
expect(@wikis).to be_a Gitlab::PaginatedResponse
end
end

describe '.wiki' do
before do
stub_get('/projects/1/wikis/home', 'wiki')
@wiki = Gitlab.wiki(1, 'home')
end

it 'gets the correct resource' do
expect(a_get('/projects/1/wikis/home')).to have_been_made
end

it 'returns correct information about the wiki' do
expect(@wiki.slug).to eq 'home'
end
end

describe '.create_wiki' do
before do
stub_post('/projects/1/wikis', 'wiki')
@wiki = Gitlab.create_wiki(1, 'home', 'home page')
end

it 'gets the correct resource' do
expect(a_post('/projects/1/wikis')
.with(body: { content: 'home page', title: 'home' })).to have_been_made
end

it 'returns correct information about the created wiki' do
expect(@wiki.content).to eq 'home page'
expect(@wiki.title).to eq 'home'
end
end

describe '.update_wiki' do
before do
stub_put('/projects/1/wikis/home', 'wiki')
@wiki = Gitlab.update_wiki(1, 'home', format: 'markdown')
end

it 'gets the correct resource' do
expect(a_put('/projects/1/wikis/home')
.with(body: { format: 'markdown' })).to have_been_made
end

it 'returns correct information about the updated wiki' do
expect(@wiki.format).to eq 'markdown'
end
end

describe '.delete_wiki' do
before do
stub_delete('/projects/1/wikis/home', 'empty')
@wiki = Gitlab.delete_wiki(1, 'home')
end

it 'gets the correct resource' do
expect(a_delete('/projects/1/wikis/home')).to have_been_made
end
end
end