Commit 2dae0e18e09132c0db32c8646d8d11b30cfcb83f

Authored by Dmitriy Zaporozhets
1 parent 8d7aaf0e

web hooks scaffold started

app/controllers/hooks_controller.rb 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +class HooksController < ApplicationController
  2 + before_filter :authenticate_user!
  3 + before_filter :project
  4 + layout "project"
  5 +
  6 + # Authorize
  7 + before_filter :add_project_abilities
  8 + before_filter :authorize_read_project!
  9 + before_filter :authorize_admin_project!, :only => [:new, :create, :destroy]
  10 +
  11 + respond_to :html
  12 +
  13 + def index
  14 + @hooks = @project.web_hooks
  15 + end
  16 +
  17 + def new
  18 + @hook = @project.web_hooks.new
  19 + end
  20 +
  21 + def create
  22 + @hook = @project.web_hooks.new(params[:hook])
  23 + @hook.author = current_user
  24 + @hook.save
  25 +
  26 + if @hook.valid?
  27 + redirect_to [@project, @hook]
  28 + else
  29 + respond_with(@hook)
  30 + end
  31 + end
  32 +
  33 + def show
  34 + @hook = @project.web_hooks.find(params[:id])
  35 + end
  36 +
  37 + def destroy
  38 + @hook = @project.web_hooks.find(params[:id])
  39 + @hook.destroy
  40 +
  41 + redirect_to project_hooks_path(@project)
  42 + end
  43 +end
... ...
app/controllers/projects_controller.rb
... ... @@ -68,7 +68,7 @@ class ProjectsController &lt; ApplicationController
68 68  
69 69 def show
70 70 return render "projects/empty" unless @project.repo_exists? && @project.has_commits?
71   - limit = (params[:limit] || 20).to_i
  71 + limit = (params[:limit] || 10).to_i
72 72 @activities = @project.cached_updates(limit)
73 73 end
74 74  
... ...
app/controllers/repositories_controller.rb
... ... @@ -9,7 +9,7 @@ class RepositoriesController &lt; ApplicationController
9 9 layout "project"
10 10  
11 11 def show
12   - @activities = @project.fresh_commits(20)
  12 + @activities = @project.fresh_commits(10)
13 13 end
14 14  
15 15 def branches
... ...
app/models/user.rb
... ... @@ -82,5 +82,6 @@ end
82 82 # linkedin :string(255) default(""), not null
83 83 # twitter :string(255) default(""), not null
84 84 # authentication_token :string(255)
  85 +# dark_scheme :boolean default(FALSE), not null
85 86 #
86 87  
... ...
app/models/web_hook.rb
... ... @@ -18,3 +18,14 @@ class WebHook &lt; ActiveRecord::Base
18 18 # There was a problem calling this web hook, let's forget about it.
19 19 end
20 20 end
  21 +# == Schema Information
  22 +#
  23 +# Table name: web_hooks
  24 +#
  25 +# id :integer not null, primary key
  26 +# url :string(255)
  27 +# project_id :integer
  28 +# created_at :datetime
  29 +# updated_at :datetime
  30 +#
  31 +
... ...
app/views/hooks/index.html.haml 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 += render "repositories/head"
  2 +- unless @hooks.empty?
  3 + %div.update-data.ui-box.ui-box-small
  4 + .data
  5 + - @hooks.each do |hook|
  6 + %a.update-item{:href => project_hooks_path(@project, hook)}
  7 + %span.update-title{:style => "margin-bottom:0px;"}
  8 + = hook.url
  9 +- else
  10 + %h3 No hooks
... ...
app/workers/post_receive.rb
1 1 class PostReceive
  2 + @queue = :post_receive
  3 +
2 4 def self.perform(reponame, oldrev, newrev, ref)
3 5 project = Project.find_by_path(reponame)
4 6 return false if project.nil?
... ...
config/routes.rb
1 1 Gitlab::Application.routes.draw do
2 2  
3 3 # Optionally, enable Resque here
4   - # require 'resque/server'
5   - # mount Resque::Server.new, at: '/info/resque'
  4 + require 'resque/server'
  5 + mount Resque::Server.new, at: '/info/resque'
6 6  
7 7 get 'tags'=> 'tags#index'
8 8 get 'tags/:tag' => 'projects#index'
... ... @@ -83,6 +83,8 @@ Gitlab::Application.routes.draw do
83 83 get :commits
84 84 end
85 85 end
  86 +
  87 + resources :hooks, :only => [:index, :new, :create, :destroy, :show]
86 88 resources :snippets
87 89 resources :commits
88 90 resources :team_members
... ...
spec/models/user_spec.rb
... ... @@ -65,5 +65,6 @@ end
65 65 # linkedin :string(255) default(""), not null
66 66 # twitter :string(255) default(""), not null
67 67 # authentication_token :string(255)
  68 +# dark_scheme :boolean default(FALSE), not null
68 69 #
69 70  
... ...
spec/models/web_hook_spec.rb
... ... @@ -52,3 +52,14 @@ describe WebHook do
52 52 end
53 53 end
54 54 end
  55 +# == Schema Information
  56 +#
  57 +# Table name: web_hooks
  58 +#
  59 +# id :integer not null, primary key
  60 +# url :string(255)
  61 +# project_id :integer
  62 +# created_at :datetime
  63 +# updated_at :datetime
  64 +#
  65 +
... ...