-
-
Notifications
You must be signed in to change notification settings - Fork 400
Added wikis API #442
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
Added wikis API #442
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| # @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' }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "content" : "home page", | ||
| "format" : "markdown", | ||
| "slug" : "home", | ||
| "title" : "home" | ||
| } | ||
|
|
| 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" : "" | ||
| } | ||
| } |
| 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" | ||
| } | ||
| ] |
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
:with_contentsupposed to be a symbol?There was a problem hiding this comment.
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 :)