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
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2016-06-28 19:04:44 +0300
committerRobert Schilling <rschilling@student.tugraz.at>2016-07-01 15:52:04 +0300
commit87ac9c9850d602fd18654498ab3fa005d2b85ac7 (patch)
treeb9fe37acee0d9dae2f931504ebdf3ff7a2ec06e2 /lib/api/todos.rb
parent3942621329b20307c1676d60324c8f47ea1e1b37 (diff)
Support creating a todo on issuables via API
Diffstat (limited to 'lib/api/todos.rb')
-rw-r--r--lib/api/todos.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/api/todos.rb b/lib/api/todos.rb
index 8334baad1b9..2a6bfa98ca4 100644
--- a/lib/api/todos.rb
+++ b/lib/api/todos.rb
@@ -3,6 +3,36 @@ module API
class Todos < Grape::API
before { authenticate! }
+ ISSUABLE_TYPES = {
+ 'merge_requests' => ->(id) { user_project.merge_requests.find(id) },
+ 'issues' => ->(id) { find_project_issue(id) }
+ }
+
+ 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
+ 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
+
+ if todo
+ present todo, with: Entities::Todo, current_user: current_user
+ else
+ not_modified!
+ end
+ end
+ end
+ end
+
resource :todos do
helpers do
def find_todos