Merge branch 'web_hooks_scaffold'
This commit is contained in:
commit
7b0cd969e0
14 changed files with 172 additions and 6 deletions
1
.foreman
Normal file
1
.foreman
Normal file
|
@ -0,0 +1 @@
|
||||||
|
port: 3000
|
2
Procfile
Normal file
2
Procfile
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
web: bundle exec rails s -p $PORT
|
||||||
|
worker: bundle exec rake environment resque:work QUEUE=*
|
|
@ -181,6 +181,13 @@ input.ssh_project_url {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.text_field {
|
||||||
|
width:400px;
|
||||||
|
padding:8px;
|
||||||
|
font-size:14px;
|
||||||
|
@include round-borders-all(4px);
|
||||||
|
}
|
||||||
|
|
||||||
.input_button {
|
.input_button {
|
||||||
padding:8px;
|
padding:8px;
|
||||||
font-size:14px;
|
font-size:14px;
|
||||||
|
|
51
app/controllers/hooks_controller.rb
Normal file
51
app/controllers/hooks_controller.rb
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
class HooksController < ApplicationController
|
||||||
|
before_filter :authenticate_user!
|
||||||
|
before_filter :project
|
||||||
|
layout "project"
|
||||||
|
|
||||||
|
# Authorize
|
||||||
|
before_filter :add_project_abilities
|
||||||
|
before_filter :authorize_read_project!
|
||||||
|
before_filter :authorize_admin_project!, :only => [:new, :create, :destroy]
|
||||||
|
|
||||||
|
respond_to :html
|
||||||
|
|
||||||
|
def index
|
||||||
|
@hooks = @project.web_hooks
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@hook = @project.web_hooks.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@hook = @project.web_hooks.new(params[:hook])
|
||||||
|
@hook.save
|
||||||
|
|
||||||
|
if @hook.valid?
|
||||||
|
redirect_to project_hook_path(@project, @hook)
|
||||||
|
else
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test
|
||||||
|
@hook = @project.web_hooks.find(params[:id])
|
||||||
|
commits = @project.commits(@project.default_branch, nil, 3)
|
||||||
|
data = @project.web_hook_data(commits.last.id, commits.first.id, "refs/heads/#{@project.default_branch}")
|
||||||
|
@hook.execute(data)
|
||||||
|
|
||||||
|
redirect_to :back
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@hook = @project.web_hooks.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@hook = @project.web_hooks.find(params[:id])
|
||||||
|
@hook.destroy
|
||||||
|
|
||||||
|
redirect_to project_hooks_path(@project)
|
||||||
|
end
|
||||||
|
end
|
|
@ -35,7 +35,8 @@ module ProjectsHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def repository_tab_class
|
def repository_tab_class
|
||||||
if controller.controller_name == "repositories"
|
if controller.controller_name == "repositories" ||
|
||||||
|
controller.controller_name == "hooks"
|
||||||
"current"
|
"current"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
42
app/views/hooks/_data_ex.html.erb
Normal file
42
app/views/hooks/_data_ex.html.erb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<% data_ex_str = <<eos
|
||||||
|
{
|
||||||
|
:before => "95790bf891e76fee5e1747ab589903a6a1f80f22",
|
||||||
|
:after => "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||||
|
:ref => "refs/heads/master",
|
||||||
|
:repository => {
|
||||||
|
:name => "Diaspora",
|
||||||
|
:url => "localhost/diaspora",
|
||||||
|
:description => "",
|
||||||
|
:homepage => "localhost/diaspora",
|
||||||
|
:private => true
|
||||||
|
},
|
||||||
|
:commits => [
|
||||||
|
[0] {
|
||||||
|
:id => "450d0de7532f8b663b9c5cce183b...",
|
||||||
|
:message => "Update Catalan translation to e38cb41.",
|
||||||
|
:timestamp => "2011-12-12T14:27:31+02:00",
|
||||||
|
:url => "http://localhost/diaspora/commits/450d0de7532f...",
|
||||||
|
:author => {
|
||||||
|
:name => "Jordi Mallach",
|
||||||
|
:email => "jordi@softcatala.org"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
....
|
||||||
|
|
||||||
|
[3] {
|
||||||
|
:id => "da1560886d4f094c3e6c9ef40349...",
|
||||||
|
:message => "fixed readme",
|
||||||
|
:timestamp => "2012-01-03T23:36:29+02:00",
|
||||||
|
:url => "http://localhost/diaspora/commits/da1560886d...",
|
||||||
|
:author => {
|
||||||
|
:name => "gitlab dev user",
|
||||||
|
:email => "gitlabdev@dv6700.(none)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
eos
|
||||||
|
%>
|
||||||
|
<% js_lexer = Pygments::Lexer[:js] %>
|
||||||
|
<%= raw js_lexer.highlight(data_ex_str) %>
|
30
app/views/hooks/index.html.haml
Normal file
30
app/views/hooks/index.html.haml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
= render "repositories/head"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.right= link_to "Add new", new_project_hook_path(@project), :class => "grey-button append-bottom-10"
|
||||||
|
- unless @hooks.empty?
|
||||||
|
%div.update-data.ui-box.ui-box-small
|
||||||
|
.data
|
||||||
|
- @hooks.each do |hook|
|
||||||
|
%a.update-item{:href => project_hook_path(@project, hook)}
|
||||||
|
%span.update-title{:style => "margin-bottom:0px;"}
|
||||||
|
= hook.url
|
||||||
|
%span.update-author.right
|
||||||
|
Added
|
||||||
|
= time_ago_in_words(hook.created_at)
|
||||||
|
ago
|
||||||
|
- else
|
||||||
|
%h3 No hooks
|
||||||
|
|
||||||
|
.clear
|
||||||
|
%h3 Help
|
||||||
|
%p
|
||||||
|
Post receive hooks. For now only POST request allowed. We send some data with request. Example below
|
||||||
|
|
||||||
|
.view_file
|
||||||
|
.view_file_header
|
||||||
|
%strong POST data passed
|
||||||
|
.data.no-padding
|
||||||
|
= render "data_ex"
|
13
app/views/hooks/new.html.haml
Normal file
13
app/views/hooks/new.html.haml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
= render "repositories/head"
|
||||||
|
= form_for [@project, @hook], :as => :hook, :url => project_hooks_path(@project) do |f|
|
||||||
|
-if @hook.errors.any?
|
||||||
|
%ul
|
||||||
|
- @hook.errors.full_messages.each do |msg|
|
||||||
|
%li= msg
|
||||||
|
= f.label :url, "URL:"
|
||||||
|
= f.text_field :url, :class => "text_field"
|
||||||
|
.clear
|
||||||
|
%br
|
||||||
|
.merge-tabs
|
||||||
|
= f.submit "Save", :class => "grey-button"
|
||||||
|
|
11
app/views/hooks/show.html.haml
Normal file
11
app/views/hooks/show.html.haml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
= render "repositories/head"
|
||||||
|
%h3
|
||||||
|
%span.commit.tag POST
|
||||||
|
= @hook.url
|
||||||
|
|
||||||
|
|
||||||
|
- if can? current_user, :admin_project, @project
|
||||||
|
.merge-tabs
|
||||||
|
= link_to 'Test Hook', test_project_hook_path(@project, @hook), :class => "grey-button"
|
||||||
|
.right
|
||||||
|
= link_to 'Remove', project_hook_path(@project, @hook), :confirm => 'Are you sure?', :method => :delete, :class => "red-button"
|
|
@ -8,7 +8,7 @@
|
||||||
= link_to tags_project_repository_path(@project), :class => "tab #{'active' if current_page?(tags_project_repository_path(@project)) }" do
|
= link_to tags_project_repository_path(@project), :class => "tab #{'active' if current_page?(tags_project_repository_path(@project)) }" do
|
||||||
%span
|
%span
|
||||||
Tags
|
Tags
|
||||||
-#= link_to "#", :class => "tab" do
|
= link_to project_hooks_path, :class => "tab #{'active' if controller.controller_name == "hooks" }" do
|
||||||
%span
|
%span
|
||||||
Hooks
|
Hooks
|
||||||
-#= link_to "#", :class => "tab" do
|
-#= link_to "#", :class => "tab" do
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
class PostReceive
|
class PostReceive
|
||||||
|
@queue = :post_receive
|
||||||
|
|
||||||
def self.perform(reponame, oldrev, newrev, ref)
|
def self.perform(reponame, oldrev, newrev, ref)
|
||||||
project = Project.find_by_path(reponame)
|
project = Project.find_by_path(reponame)
|
||||||
return false if project.nil?
|
return false if project.nil?
|
||||||
|
|
|
@ -20,6 +20,6 @@ test:
|
||||||
|
|
||||||
production:
|
production:
|
||||||
adapter: sqlite3
|
adapter: sqlite3
|
||||||
database: db/production.sqlite3
|
database: db/development.sqlite3
|
||||||
pool: 5
|
pool: 5
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
Gitlab::Application.routes.draw do
|
Gitlab::Application.routes.draw do
|
||||||
|
|
||||||
# Optionally, enable Resque here
|
# Optionally, enable Resque here
|
||||||
# require 'resque/server'
|
require 'resque/server'
|
||||||
# mount Resque::Server.new, at: '/info/resque'
|
mount Resque::Server.new, at: '/info/resque'
|
||||||
|
|
||||||
get 'tags'=> 'tags#index'
|
get 'tags'=> 'tags#index'
|
||||||
get 'tags/:tag' => 'projects#index'
|
get 'tags/:tag' => 'projects#index'
|
||||||
|
@ -83,7 +83,13 @@ Gitlab::Application.routes.draw do
|
||||||
get :commits
|
get :commits
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :snippets
|
resources :snippets
|
||||||
|
resources :hooks, :only => [:index, :new, :create, :destroy, :show] do
|
||||||
|
member do
|
||||||
|
get :test
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :commits
|
resources :commits
|
||||||
resources :team_members
|
resources :team_members
|
||||||
resources :issues do
|
resources :issues do
|
||||||
|
|
|
@ -8,5 +8,5 @@ do
|
||||||
# For every branch or tag that was pushed, create a Resque job in redis.
|
# For every branch or tag that was pushed, create a Resque job in redis.
|
||||||
pwd=`pwd`
|
pwd=`pwd`
|
||||||
reponame=`basename "$pwd" | cut -d. -f1`
|
reponame=`basename "$pwd" | cut -d. -f1`
|
||||||
env -i redis-cli rpush "resque:queue:post-receive" "{\"class\":\"PostReceive\",\"args\":[\"$reponame\",\"$oldrev\",\"$newrev\",\"$ref\"]}" > /dev/null 2>&1
|
env -i redis-cli rpush "resque:queue:post_receive" "{\"class\":\"PostReceive\",\"args\":[\"$reponame\",\"$oldrev\",\"$newrev\",\"$ref\"]}" > /dev/null 2>&1
|
||||||
done
|
done
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue