Commit 7b0cd969e05995b3792aed76ed15b482ed4381a3
Exists in
master
and in
4 other branches
Merge branch 'web_hooks_scaffold'
Showing
14 changed files
with
172 additions
and
6 deletions
Show diff stats
... | ... | @@ -0,0 +1 @@ |
1 | +port: 3000 | ... | ... |
app/assets/stylesheets/projects.css.scss
... | ... | @@ -0,0 +1,51 @@ |
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.save | |
24 | + | |
25 | + if @hook.valid? | |
26 | + redirect_to project_hook_path(@project, @hook) | |
27 | + else | |
28 | + render :new | |
29 | + end | |
30 | + end | |
31 | + | |
32 | + def test | |
33 | + @hook = @project.web_hooks.find(params[:id]) | |
34 | + commits = @project.commits(@project.default_branch, nil, 3) | |
35 | + data = @project.web_hook_data(commits.last.id, commits.first.id, "refs/heads/#{@project.default_branch}") | |
36 | + @hook.execute(data) | |
37 | + | |
38 | + redirect_to :back | |
39 | + end | |
40 | + | |
41 | + def show | |
42 | + @hook = @project.web_hooks.find(params[:id]) | |
43 | + end | |
44 | + | |
45 | + def destroy | |
46 | + @hook = @project.web_hooks.find(params[:id]) | |
47 | + @hook.destroy | |
48 | + | |
49 | + redirect_to project_hooks_path(@project) | |
50 | + end | |
51 | +end | ... | ... |
app/helpers/projects_helper.rb
... | ... | @@ -0,0 +1,42 @@ |
1 | +<% data_ex_str = <<eos | |
2 | +{ | |
3 | + :before => "95790bf891e76fee5e1747ab589903a6a1f80f22", | |
4 | + :after => "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", | |
5 | + :ref => "refs/heads/master", | |
6 | + :repository => { | |
7 | + :name => "Diaspora", | |
8 | + :url => "localhost/diaspora", | |
9 | + :description => "", | |
10 | + :homepage => "localhost/diaspora", | |
11 | + :private => true | |
12 | + }, | |
13 | + :commits => [ | |
14 | + [0] { | |
15 | + :id => "450d0de7532f8b663b9c5cce183b...", | |
16 | + :message => "Update Catalan translation to e38cb41.", | |
17 | + :timestamp => "2011-12-12T14:27:31+02:00", | |
18 | + :url => "http://localhost/diaspora/commits/450d0de7532f...", | |
19 | + :author => { | |
20 | + :name => "Jordi Mallach", | |
21 | + :email => "jordi@softcatala.org" | |
22 | + } | |
23 | + }, | |
24 | + | |
25 | + .... | |
26 | + | |
27 | + [3] { | |
28 | + :id => "da1560886d4f094c3e6c9ef40349...", | |
29 | + :message => "fixed readme", | |
30 | + :timestamp => "2012-01-03T23:36:29+02:00", | |
31 | + :url => "http://localhost/diaspora/commits/da1560886d...", | |
32 | + :author => { | |
33 | + :name => "gitlab dev user", | |
34 | + :email => "gitlabdev@dv6700.(none)" | |
35 | + } | |
36 | + } | |
37 | + ] | |
38 | +} | |
39 | +eos | |
40 | +%> | |
41 | +<% js_lexer = Pygments::Lexer[:js] %> | |
42 | +<%= raw js_lexer.highlight(data_ex_str) %> | ... | ... |
... | ... | @@ -0,0 +1,30 @@ |
1 | += render "repositories/head" | |
2 | + | |
3 | + | |
4 | + | |
5 | + | |
6 | +.right= link_to "Add new", new_project_hook_path(@project), :class => "grey-button append-bottom-10" | |
7 | +- unless @hooks.empty? | |
8 | + %div.update-data.ui-box.ui-box-small | |
9 | + .data | |
10 | + - @hooks.each do |hook| | |
11 | + %a.update-item{:href => project_hook_path(@project, hook)} | |
12 | + %span.update-title{:style => "margin-bottom:0px;"} | |
13 | + = hook.url | |
14 | + %span.update-author.right | |
15 | + Added | |
16 | + = time_ago_in_words(hook.created_at) | |
17 | + ago | |
18 | +- else | |
19 | + %h3 No hooks | |
20 | + | |
21 | +.clear | |
22 | +%h3 Help | |
23 | +%p | |
24 | + Post receive hooks. For now only POST request allowed. We send some data with request. Example below | |
25 | + | |
26 | +.view_file | |
27 | + .view_file_header | |
28 | + %strong POST data passed | |
29 | + .data.no-padding | |
30 | + = render "data_ex" | ... | ... |
... | ... | @@ -0,0 +1,13 @@ |
1 | += render "repositories/head" | |
2 | += form_for [@project, @hook], :as => :hook, :url => project_hooks_path(@project) do |f| | |
3 | + -if @hook.errors.any? | |
4 | + %ul | |
5 | + - @hook.errors.full_messages.each do |msg| | |
6 | + %li= msg | |
7 | + = f.label :url, "URL:" | |
8 | + = f.text_field :url, :class => "text_field" | |
9 | + .clear | |
10 | + %br | |
11 | + .merge-tabs | |
12 | + = f.submit "Save", :class => "grey-button" | |
13 | + | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | += render "repositories/head" | |
2 | +%h3 | |
3 | + %span.commit.tag POST | |
4 | + = @hook.url | |
5 | + | |
6 | + | |
7 | +- if can? current_user, :admin_project, @project | |
8 | + .merge-tabs | |
9 | + = link_to 'Test Hook', test_project_hook_path(@project, @hook), :class => "grey-button" | |
10 | + .right | |
11 | + = link_to 'Remove', project_hook_path(@project, @hook), :confirm => 'Are you sure?', :method => :delete, :class => "red-button" | ... | ... |
app/views/repositories/_head.html.haml
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 | = link_to tags_project_repository_path(@project), :class => "tab #{'active' if current_page?(tags_project_repository_path(@project)) }" do |
9 | 9 | %span |
10 | 10 | Tags |
11 | - -#= link_to "#", :class => "tab" do | |
11 | + = link_to project_hooks_path, :class => "tab #{'active' if controller.controller_name == "hooks" }" do | |
12 | 12 | %span |
13 | 13 | Hooks |
14 | 14 | -#= link_to "#", :class => "tab" do | ... | ... |
app/workers/post_receive.rb
config/database.yml
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,7 +83,13 @@ Gitlab::Application.routes.draw do |
83 | 83 | get :commits |
84 | 84 | end |
85 | 85 | end |
86 | + | |
86 | 87 | resources :snippets |
88 | + resources :hooks, :only => [:index, :new, :create, :destroy, :show] do | |
89 | + member do | |
90 | + get :test | |
91 | + end | |
92 | + end | |
87 | 93 | resources :commits |
88 | 94 | resources :team_members |
89 | 95 | resources :issues do | ... | ... |
lib/post-receive-hook
... | ... | @@ -8,5 +8,5 @@ do |
8 | 8 | # For every branch or tag that was pushed, create a Resque job in redis. |
9 | 9 | pwd=`pwd` |
10 | 10 | reponame=`basename "$pwd" | cut -d. -f1` |
11 | - env -i redis-cli rpush "resque:queue:post-receive" "{\"class\":\"PostReceive\",\"args\":[\"$reponame\",\"$oldrev\",\"$newrev\",\"$ref\"]}" > /dev/null 2>&1 | |
11 | + env -i redis-cli rpush "resque:queue:post_receive" "{\"class\":\"PostReceive\",\"args\":[\"$reponame\",\"$oldrev\",\"$newrev\",\"$ref\"]}" > /dev/null 2>&1 | |
12 | 12 | done | ... | ... |