Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2016-10-17 12:56:55 +0300
committerSean McGivern <sean@gitlab.com>2016-10-17 12:56:55 +0300
commit86dcb79be37f5759dfeaa26283ed8bf031b38d54 (patch)
tree70869aeaa6bfbdcaada873cfd3e4054c62d3e25a /lib
parent26e327ea93140f6400b965b845958ff50461718c (diff)
parent052de0600c6b137e6f9df08250b4cf5f38280295 (diff)
Merge branch 'master' into merge-conflicts-editor-2
Diffstat (limited to 'lib')
-rw-r--r--lib/api/boards.rb76
-rw-r--r--lib/api/system_hooks.rb60
-rw-r--r--lib/api/todos.rb45
-rw-r--r--lib/banzai/renderer.rb4
-rw-r--r--lib/extracts_path.rb17
-rw-r--r--lib/gitlab/backend/shell.rb4
6 files changed, 105 insertions, 101 deletions
diff --git a/lib/api/boards.rb b/lib/api/boards.rb
index 9b71d335128..b14dd4f6e83 100644
--- a/lib/api/boards.rb
+++ b/lib/api/boards.rb
@@ -3,19 +3,28 @@ module API
class Boards < Grape::API
before { authenticate! }
+ params do
+ requires :id, type: String, desc: 'The ID of a project'
+ end
resource :projects do
- # Get the project board
+ desc 'Get all project boards' do
+ detail 'This feature was introduced in 8.13'
+ success Entities::Board
+ end
get ':id/boards' do
authorize!(:read_board, user_project)
present user_project.boards, with: Entities::Board
end
+ params do
+ requires :board_id, type: Integer, desc: 'The ID of a board'
+ end
segment ':id/boards/:board_id' do
helpers do
def project_board
board = user_project.boards.first
- if params[:board_id].to_i == board.id
+ if params[:board_id] == board.id
board
else
not_found!('Board')
@@ -27,29 +36,35 @@ module API
end
end
- # Get the lists of a project board
- # Does not include `backlog` and `done` lists
+ desc 'Get the lists of a project board' do
+ detail 'Does not include `backlog` and `done` lists. This feature was introduced in 8.13'
+ success Entities::List
+ end
get '/lists' do
authorize!(:read_board, user_project)
present board_lists, with: Entities::List
end
- # Get a list of a project board
+ desc 'Get a list of a project board' do
+ detail 'This feature was introduced in 8.13'
+ success Entities::List
+ end
+ params do
+ requires :list_id, type: Integer, desc: 'The ID of a list'
+ end
get '/lists/:list_id' do
authorize!(:read_board, user_project)
present board_lists.find(params[:list_id]), with: Entities::List
end
- # Create a new board list
- #
- # Parameters:
- # id (required) - The ID of a project
- # label_id (required) - The ID of an existing label
- # Example Request:
- # POST /projects/:id/boards/:board_id/lists
+ desc 'Create a new board list' do
+ detail 'This feature was introduced in 8.13'
+ success Entities::List
+ end
+ params do
+ requires :label_id, type: Integer, desc: 'The ID of an existing label'
+ end
post '/lists' do
- required_attributes! [:label_id]
-
unless user_project.labels.exists?(params[:label_id])
render_api_error!({ error: "Label not found!" }, 400)
end
@@ -68,21 +83,21 @@ module API
end
end
- # Moves a board list to a new position
- #
- # Parameters:
- # id (required) - The ID of a project
- # board_id (required) - The ID of a board
- # position (required) - The position of the list
- # Example Request:
- # PUT /projects/:id/boards/:board_id/lists/:list_id
+ desc 'Moves a board list to a new position' do
+ detail 'This feature was introduced in 8.13'
+ success Entities::List
+ end
+ params do
+ requires :list_id, type: Integer, desc: 'The ID of a list'
+ requires :position, type: Integer, desc: 'The position of the list'
+ end
put '/lists/:list_id' do
list = project_board.lists.movable.find(params[:list_id])
authorize!(:admin_list, user_project)
service = ::Boards::Lists::MoveService.new(user_project, current_user,
- { position: params[:position].to_i })
+ { position: params[:position] })
if service.execute(list)
present list, with: Entities::List
@@ -91,14 +106,13 @@ module API
end
end
- # Delete a board list
- #
- # Parameters:
- # id (required) - The ID of a project
- # board_id (required) - The ID of a board
- # list_id (required) - The ID of a board list
- # Example Request:
- # DELETE /projects/:id/boards/:board_id/lists/:list_id
+ desc 'Delete a board list' do
+ detail 'This feature was introduced in 8.13'
+ success Entities::List
+ end
+ params do
+ requires :list_id, type: Integer, desc: 'The ID of a board list'
+ end
delete "/lists/:list_id" do
authorize!(:admin_list, user_project)
diff --git a/lib/api/system_hooks.rb b/lib/api/system_hooks.rb
index 22b8f90dc5c..2e76b91051f 100644
--- a/lib/api/system_hooks.rb
+++ b/lib/api/system_hooks.rb
@@ -7,38 +7,36 @@ module API
end
resource :hooks do
- # Get the list of system hooks
- #
- # Example Request:
- # GET /hooks
+ desc 'Get the list of system hooks' do
+ success Entities::Hook
+ end
get do
- @hooks = SystemHook.all
- present @hooks, with: Entities::Hook
+ hooks = SystemHook.all
+ present hooks, with: Entities::Hook
end
- # Create new system hook
- #
- # Parameters:
- # url (required) - url for system hook
- # Example Request
- # POST /hooks
+ desc 'Create a new system hook' do
+ success Entities::Hook
+ end
+ params do
+ requires :url, type: String, desc: 'The URL for the system hook'
+ end
post do
- attrs = attributes_for_keys [:url]
- required_attributes! [:url]
- @hook = SystemHook.new attrs
- if @hook.save
- present @hook, with: Entities::Hook
+ hook = SystemHook.new declared(params).to_h
+
+ if hook.save
+ present hook, with: Entities::Hook
else
not_found!
end
end
- # Test a hook
- #
- # Example Request
- # GET /hooks/:id
+ desc 'Test a hook'
+ params do
+ requires :id, type: Integer, desc: 'The ID of the system hook'
+ end
get ":id" do
- @hook = SystemHook.find(params[:id])
+ hook = SystemHook.find(params[:id])
data = {
event_name: "project_create",
name: "Ruby",
@@ -47,20 +45,20 @@ module API
owner_name: "Someone",
owner_email: "example@gitlabhq.com"
}
- @hook.execute(data, 'system_hooks')
+ hook.execute(data, 'system_hooks')
data
end
- # Delete a hook. This is an idempotent function.
- #
- # Parameters:
- # id (required) - ID of the hook
- # Example Request:
- # DELETE /hooks/:id
+ desc 'Delete a hook' do
+ success Entities::Hook
+ end
+ params do
+ requires :id, type: Integer, desc: 'The ID of the system hook'
+ end
delete ":id" do
begin
- @hook = SystemHook.find(params[:id])
- @hook.destroy
+ hook = SystemHook.find(params[:id])
+ present hook.destroy, with: Entities::Hook
rescue
# SystemHook raises an Error if no hook with id found
end
diff --git a/lib/api/todos.rb b/lib/api/todos.rb
index 19df13d8aac..832b04a3bb1 100644
--- a/lib/api/todos.rb
+++ b/lib/api/todos.rb
@@ -8,18 +8,19 @@ module API
'issues' => ->(id) { find_project_issue(id) }
}
+ params do
+ requires :id, type: String, desc: 'The ID of a project'
+ end
resource :projects do
ISSUABLE_TYPES.each do |type, finder|
type_id_str = "#{type.singularize}_id".to_sym
- # Create a todo on an issuable
- #
- # Parameters:
- # id (required) - The ID of a project
- # issuable_id (required) - The ID of an issuable
- # Example Request:
- # POST /projects/:id/issues/:issuable_id/todo
- # POST /projects/:id/merge_requests/:issuable_id/todo
+ desc 'Create a todo on an issuable' do
+ success Entities::Todo
+ end
+ params do
+ requires type_id_str, type: Integer, desc: 'The ID of an issuable'
+ end
post ":id/#{type}/:#{type_id_str}/todo" do
issuable = instance_exec(params[type_id_str], &finder)
todo = TodoService.new.mark_todo(issuable, current_user).first
@@ -40,25 +41,21 @@ module API
end
end
- # Get a todo list
- #
- # Example Request:
- # GET /todos
- #
+ desc 'Get a todo list' do
+ success Entities::Todo
+ end
get do
todos = find_todos
present paginate(todos), with: Entities::Todo, current_user: current_user
end
- # Mark a todo as done
- #
- # Parameters:
- # id: (required) - The ID of the todo being marked as done
- #
- # Example Request:
- # DELETE /todos/:id
- #
+ desc 'Mark a todo as done' do
+ success Entities::Todo
+ end
+ params do
+ requires :id, type: Integer, desc: 'The ID of the todo being marked as done'
+ end
delete ':id' do
todo = current_user.todos.find(params[:id])
TodoService.new.mark_todos_as_done([todo], current_user)
@@ -66,11 +63,7 @@ module API
present todo.reload, with: Entities::Todo, current_user: current_user
end
- # Mark all todos as done
- #
- # Example Request:
- # DELETE /todos
- #
+ desc 'Mark all todos as done'
delete do
todos = find_todos
TodoService.new.mark_todos_as_done(todos, current_user)
diff --git a/lib/banzai/renderer.rb b/lib/banzai/renderer.rb
index 6924a293da8..ce048a36fa0 100644
--- a/lib/banzai/renderer.rb
+++ b/lib/banzai/renderer.rb
@@ -1,6 +1,6 @@
module Banzai
module Renderer
- extend self
+ module_function
# Convert a Markdown String into an HTML-safe String of HTML
#
@@ -141,8 +141,6 @@ module Banzai
end.html_safe
end
- private
-
def cacheless_render(text, context = {})
Gitlab::Metrics.measure(:banzai_cacheless_render) do
result = render_result(text, context)
diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb
index e4d996a3fb6..9b74364849e 100644
--- a/lib/extracts_path.rb
+++ b/lib/extracts_path.rb
@@ -113,17 +113,18 @@ module ExtractsPath
@id = get_id
@ref, @path = extract_ref(@id)
@repo = @project.repository
- if @options[:extended_sha1].blank?
- @commit = @repo.commit(@ref)
- else
- @commit = @repo.commit(@options[:extended_sha1])
- end
- if @path.empty? && !@commit
- @id = @ref = extract_ref_without_atom(@id)
+ if @options[:extended_sha1].present?
+ @commit = @repo.commit(@options[:extended_sha1])
+ else
@commit = @repo.commit(@ref)
- request.format = :atom if @commit
+ if @path.empty? && !@commit && @id.ends_with?('.atom')
+ @id = @ref = extract_ref_without_atom(@id)
+ @commit = @repo.commit(@ref)
+
+ request.format = :atom if @commit
+ end
end
raise InvalidPathError unless @commit
diff --git a/lib/gitlab/backend/shell.rb b/lib/gitlab/backend/shell.rb
index d0060fbaca1..9cec71a3222 100644
--- a/lib/gitlab/backend/shell.rb
+++ b/lib/gitlab/backend/shell.rb
@@ -47,8 +47,8 @@ module Gitlab
unless File.size?(secret_file)
# Generate a new token of 16 random hexadecimal characters and store it in secret_file.
- token = SecureRandom.hex(16)
- File.write(secret_file, token)
+ @secret_token = SecureRandom.hex(16)
+ File.write(secret_file, @secret_token)
end
link_path = File.join(shell_path, '.gitlab_shell_secret')