diff options
author | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2012-07-31 08:32:49 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2012-07-31 08:32:49 +0300 |
commit | 5926bbac12d5831e1ad90964272b96e152a72e34 (patch) | |
tree | e222160f8f35e7dd772dbd124eef089592efc9c2 /app/contexts | |
parent | 69e41250d1b1eea609ae63f2702d5888396cba9a (diff) | |
download | gitlab-ce-5926bbac12d5831e1ad90964272b96e152a72e34.tar.gz |
Backend Refactoring
Diffstat (limited to 'app/contexts')
-rw-r--r-- | app/contexts/notes/create_context.rb | 12 | ||||
-rw-r--r-- | app/contexts/notes/load_context.rb | 34 | ||||
-rw-r--r-- | app/contexts/notes_load.rb | 32 | ||||
-rw-r--r-- | app/contexts/test_hook_context.rb | 8 |
4 files changed, 54 insertions, 32 deletions
diff --git a/app/contexts/notes/create_context.rb b/app/contexts/notes/create_context.rb new file mode 100644 index 00000000000..d93adb835ef --- /dev/null +++ b/app/contexts/notes/create_context.rb @@ -0,0 +1,12 @@ +module Notes + class CreateContext < BaseContext + def execute + note = project.notes.new(params[:note]) + note.author = current_user + note.notify = true if params[:notify] == '1' + note.notify_author = true if params[:notify_author] == '1' + note.save + note + end + end +end diff --git a/app/contexts/notes/load_context.rb b/app/contexts/notes/load_context.rb new file mode 100644 index 00000000000..c89a7d19761 --- /dev/null +++ b/app/contexts/notes/load_context.rb @@ -0,0 +1,34 @@ +module Notes + class LoadContext < BaseContext + def execute + target_type = params[:target_type] + target_id = params[:target_id] + first_id = params[:first_id] + last_id = params[:last_id] + + + @notes = case target_type + when "commit" + then project.commit_notes(project.commit(target_id)).fresh.limit(20) + when "snippet" + then project.snippets.find(target_id).notes + when "wall" + then project.common_notes.order("created_at DESC").fresh.limit(50) + when "issue" + then project.issues.find(target_id).notes.inc_author.order("created_at DESC").limit(20) + when "merge_request" + then project.merge_requests.find(target_id).notes.inc_author.order("created_at DESC").limit(20) + when "wiki" + then project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20] + end + + @notes = if last_id + @notes.where("id > ?", last_id) + elsif first_id + @notes.where("id < ?", first_id) + else + @notes + end + end + end +end diff --git a/app/contexts/notes_load.rb b/app/contexts/notes_load.rb deleted file mode 100644 index cbb9f67fa05..00000000000 --- a/app/contexts/notes_load.rb +++ /dev/null @@ -1,32 +0,0 @@ -class NotesLoad < BaseContext - def execute - target_type = params[:target_type] - target_id = params[:target_id] - first_id = params[:first_id] - last_id = params[:last_id] - - - @notes = case target_type - when "commit" - then project.commit_notes(project.commit(target_id)).fresh.limit(20) - when "snippet" - then project.snippets.find(target_id).notes - when "wall" - then project.common_notes.order("created_at DESC").fresh.limit(50) - when "issue" - then project.issues.find(target_id).notes.inc_author.order("created_at DESC").limit(20) - when "merge_request" - then project.merge_requests.find(target_id).notes.inc_author.order("created_at DESC").limit(20) - when "wiki" - then project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20] - end - - @notes = if last_id - @notes.where("id > ?", last_id) - elsif first_id - @notes.where("id < ?", first_id) - else - @notes - end - end -end diff --git a/app/contexts/test_hook_context.rb b/app/contexts/test_hook_context.rb new file mode 100644 index 00000000000..cba5d1f87c2 --- /dev/null +++ b/app/contexts/test_hook_context.rb @@ -0,0 +1,8 @@ +class TestHookContext < BaseContext + def execute + hook = project.hooks.find(params[:id]) + commits = project.commits(project.default_branch, nil, 3) + data = project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{project.default_branch}", current_user) + hook.execute(data) + end +end |