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
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-01-08 15:20:56 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-01-08 15:20:56 +0400
commit7b0cd969e05995b3792aed76ed15b482ed4381a3 (patch)
treea98c70bab7e0621cf1e04ea5ffba07700a95cef6 /app
parenta3efa430624fc7678859a9296dd318d2220ec036 (diff)
parent473445c76fe6d99243a0e6b0247bc79cc47c3e44 (diff)
Merge branch 'web_hooks_scaffold'
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/projects.css.scss7
-rw-r--r--app/controllers/hooks_controller.rb51
-rw-r--r--app/helpers/projects_helper.rb3
-rw-r--r--app/views/hooks/_data_ex.html.erb42
-rw-r--r--app/views/hooks/index.html.haml30
-rw-r--r--app/views/hooks/new.html.haml13
-rw-r--r--app/views/hooks/show.html.haml11
-rw-r--r--app/views/repositories/_head.html.haml2
-rw-r--r--app/workers/post_receive.rb2
9 files changed, 159 insertions, 2 deletions
diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss
index cd189fd9c2f..0b43f55789d 100644
--- a/app/assets/stylesheets/projects.css.scss
+++ b/app/assets/stylesheets/projects.css.scss
@@ -181,6 +181,13 @@ input.ssh_project_url {
}
}
+.text_field {
+ width:400px;
+ padding:8px;
+ font-size:14px;
+ @include round-borders-all(4px);
+}
+
.input_button {
padding:8px;
font-size:14px;
diff --git a/app/controllers/hooks_controller.rb b/app/controllers/hooks_controller.rb
new file mode 100644
index 00000000000..7c5f7631f4e
--- /dev/null
+++ b/app/controllers/hooks_controller.rb
@@ -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
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 902d278019c..57786338ceb 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -35,7 +35,8 @@ module ProjectsHelper
end
def repository_tab_class
- if controller.controller_name == "repositories"
+ if controller.controller_name == "repositories" ||
+ controller.controller_name == "hooks"
"current"
end
end
diff --git a/app/views/hooks/_data_ex.html.erb b/app/views/hooks/_data_ex.html.erb
new file mode 100644
index 00000000000..f212bb2dc0b
--- /dev/null
+++ b/app/views/hooks/_data_ex.html.erb
@@ -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) %>
diff --git a/app/views/hooks/index.html.haml b/app/views/hooks/index.html.haml
new file mode 100644
index 00000000000..e149f4fc767
--- /dev/null
+++ b/app/views/hooks/index.html.haml
@@ -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"
diff --git a/app/views/hooks/new.html.haml b/app/views/hooks/new.html.haml
new file mode 100644
index 00000000000..8078aefa503
--- /dev/null
+++ b/app/views/hooks/new.html.haml
@@ -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"
+
diff --git a/app/views/hooks/show.html.haml b/app/views/hooks/show.html.haml
new file mode 100644
index 00000000000..47c1ddeac40
--- /dev/null
+++ b/app/views/hooks/show.html.haml
@@ -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"
diff --git a/app/views/repositories/_head.html.haml b/app/views/repositories/_head.html.haml
index c22286ec094..7ada9ff7798 100644
--- a/app/views/repositories/_head.html.haml
+++ b/app/views/repositories/_head.html.haml
@@ -8,7 +8,7 @@
= link_to tags_project_repository_path(@project), :class => "tab #{'active' if current_page?(tags_project_repository_path(@project)) }" do
%span
Tags
- -#= link_to "#", :class => "tab" do
+ = link_to project_hooks_path, :class => "tab #{'active' if controller.controller_name == "hooks" }" do
%span
Hooks
-#= link_to "#", :class => "tab" do
diff --git a/app/workers/post_receive.rb b/app/workers/post_receive.rb
index d79f4599d80..922a66ebf86 100644
--- a/app/workers/post_receive.rb
+++ b/app/workers/post_receive.rb
@@ -1,4 +1,6 @@
class PostReceive
+ @queue = :post_receive
+
def self.perform(reponame, oldrev, newrev, ref)
project = Project.find_by_path(reponame)
return false if project.nil?