Commit bb164ebf1bd672527a76a6699427cbec728d638b
1 parent
796784c7
Exists in
master
and in
4 other branches
Send author to post hook. Display push activity to dashboard
Showing
15 changed files
with
107 additions
and
11 deletions
Show diff stats
Gemfile
@@ -30,6 +30,7 @@ gem "charlock_holmes" | @@ -30,6 +30,7 @@ gem "charlock_holmes" | ||
30 | gem "foreman" | 30 | gem "foreman" |
31 | gem "omniauth-ldap" | 31 | gem "omniauth-ldap" |
32 | gem 'bootstrap-sass', "1.4.4" | 32 | gem 'bootstrap-sass', "1.4.4" |
33 | +gem "colored" | ||
33 | 34 | ||
34 | group :assets do | 35 | group :assets do |
35 | gem "sass-rails", "3.2.3" | 36 | gem "sass-rails", "3.2.3" |
Gemfile.lock
@@ -88,6 +88,7 @@ GEM | @@ -88,6 +88,7 @@ GEM | ||
88 | coffee-script-source | 88 | coffee-script-source |
89 | execjs | 89 | execjs |
90 | coffee-script-source (1.2.0) | 90 | coffee-script-source (1.2.0) |
91 | + colored (1.2) | ||
91 | crack (0.3.1) | 92 | crack (0.3.1) |
92 | daemons (1.1.8) | 93 | daemons (1.1.8) |
93 | database_cleaner (0.7.1) | 94 | database_cleaner (0.7.1) |
@@ -296,6 +297,7 @@ DEPENDENCIES | @@ -296,6 +297,7 @@ DEPENDENCIES | ||
296 | carrierwave | 297 | carrierwave |
297 | charlock_holmes | 298 | charlock_holmes |
298 | coffee-rails (= 3.2.1) | 299 | coffee-rails (= 3.2.1) |
300 | + colored | ||
299 | database_cleaner | 301 | database_cleaner |
300 | devise | 302 | devise |
301 | drapper | 303 | drapper |
app/assets/stylesheets/common.scss
app/controllers/dashboard_controller.rb
@@ -11,6 +11,8 @@ class DashboardController < ApplicationController | @@ -11,6 +11,8 @@ class DashboardController < ApplicationController | ||
11 | @user = current_user | 11 | @user = current_user |
12 | @issues = current_user.assigned_issues.opened.order("created_at DESC").limit(10) | 12 | @issues = current_user.assigned_issues.opened.order("created_at DESC").limit(10) |
13 | @issues = @issues.includes(:author, :project) | 13 | @issues = @issues.includes(:author, :project) |
14 | + | ||
15 | + @events = Event.where(:project_id => @projects.map(&:id)).recent.limit(20) | ||
14 | end | 16 | end |
15 | 17 | ||
16 | # Get authored or assigned open merge requests | 18 | # Get authored or assigned open merge requests |
app/controllers/issues_controller.rb
@@ -69,7 +69,10 @@ class IssuesController < ApplicationController | @@ -69,7 +69,10 @@ class IssuesController < ApplicationController | ||
69 | @issue.author = current_user | 69 | @issue.author = current_user |
70 | @issue.save | 70 | @issue.save |
71 | 71 | ||
72 | - respond_with(@issue) | 72 | + respond_to do |format| |
73 | + format.html { redirect_to project_issue_path(@project, @issue) } | ||
74 | + format.js | ||
75 | + end | ||
73 | end | 76 | end |
74 | 77 | ||
75 | def update | 78 | def update |
app/models/event.rb
@@ -11,6 +11,8 @@ class Event < ActiveRecord::Base | @@ -11,6 +11,8 @@ class Event < ActiveRecord::Base | ||
11 | 11 | ||
12 | serialize :data | 12 | serialize :data |
13 | 13 | ||
14 | + scope :recent, order("created_at DESC") | ||
15 | + | ||
14 | def self.determine_action(record) | 16 | def self.determine_action(record) |
15 | if [Issue, MergeRequest].include? record.class | 17 | if [Issue, MergeRequest].include? record.class |
16 | Event::Created | 18 | Event::Created |
@@ -18,6 +20,38 @@ class Event < ActiveRecord::Base | @@ -18,6 +20,38 @@ class Event < ActiveRecord::Base | ||
18 | Event::Commented | 20 | Event::Commented |
19 | end | 21 | end |
20 | end | 22 | end |
23 | + | ||
24 | + def push? | ||
25 | + action == self.class::Pushed | ||
26 | + end | ||
27 | + | ||
28 | + def new_branch? | ||
29 | + data[:before] =~ /^00000/ | ||
30 | + end | ||
31 | + | ||
32 | + def commit_from | ||
33 | + data[:before] | ||
34 | + end | ||
35 | + | ||
36 | + def commit_to | ||
37 | + data[:after] | ||
38 | + end | ||
39 | + | ||
40 | + def branch_name | ||
41 | + @branch_name ||= data[:ref].gsub("refs/heads/", "") | ||
42 | + end | ||
43 | + | ||
44 | + def pusher | ||
45 | + User.find_by_id(data[:user_id]) | ||
46 | + end | ||
47 | + | ||
48 | + def commits | ||
49 | + @commits ||= data[:commits].map do |commit| | ||
50 | + project.commit(commit[:id]) | ||
51 | + end | ||
52 | + end | ||
53 | + | ||
54 | + delegate :id, :name, :email, :to => :pusher, :prefix => true, :allow_nil => true | ||
21 | end | 55 | end |
22 | # == Schema Information | 56 | # == Schema Information |
23 | # | 57 | # |
app/models/key.rb
@@ -14,6 +14,7 @@ class Key < ActiveRecord::Base | @@ -14,6 +14,7 @@ class Key < ActiveRecord::Base | ||
14 | before_save :set_identifier | 14 | before_save :set_identifier |
15 | after_save :update_repository | 15 | after_save :update_repository |
16 | after_destroy :repository_delete_key | 16 | after_destroy :repository_delete_key |
17 | + delegate :id, :name, :email, :to => :user, :prefix => true | ||
17 | 18 | ||
18 | def set_identifier | 19 | def set_identifier |
19 | if is_deploy_key | 20 | if is_deploy_key |
app/models/project.rb
@@ -90,8 +90,8 @@ class Project < ActiveRecord::Base | @@ -90,8 +90,8 @@ class Project < ActiveRecord::Base | ||
90 | [GIT_HOST['host'], code].join("/") | 90 | [GIT_HOST['host'], code].join("/") |
91 | end | 91 | end |
92 | 92 | ||
93 | - def observe_push(oldrev, newrev, ref) | ||
94 | - data = web_hook_data(oldrev, newrev, ref) | 93 | + def observe_push(oldrev, newrev, ref, author_key_id) |
94 | + data = web_hook_data(oldrev, newrev, ref, author_key_id) | ||
95 | 95 | ||
96 | Event.create( | 96 | Event.create( |
97 | :project => self, | 97 | :project => self, |
@@ -100,22 +100,25 @@ class Project < ActiveRecord::Base | @@ -100,22 +100,25 @@ class Project < ActiveRecord::Base | ||
100 | ) | 100 | ) |
101 | end | 101 | end |
102 | 102 | ||
103 | - def execute_web_hooks(oldrev, newrev, ref) | 103 | + def execute_web_hooks(oldrev, newrev, ref, author_key_id) |
104 | ref_parts = ref.split('/') | 104 | ref_parts = ref.split('/') |
105 | 105 | ||
106 | # Return if this is not a push to a branch (e.g. new commits) | 106 | # Return if this is not a push to a branch (e.g. new commits) |
107 | return if ref_parts[1] !~ /heads/ || oldrev == "00000000000000000000000000000000" | 107 | return if ref_parts[1] !~ /heads/ || oldrev == "00000000000000000000000000000000" |
108 | 108 | ||
109 | - data = web_hook_data(oldrev, newrev, ref) | 109 | + data = web_hook_data(oldrev, newrev, ref, author_key_id) |
110 | 110 | ||
111 | web_hooks.each { |web_hook| web_hook.execute(data) } | 111 | web_hooks.each { |web_hook| web_hook.execute(data) } |
112 | end | 112 | end |
113 | 113 | ||
114 | - def web_hook_data(oldrev, newrev, ref) | 114 | + def web_hook_data(oldrev, newrev, ref, author_key_id) |
115 | + key = Key.find_by_identifier(author_key_id) | ||
115 | data = { | 116 | data = { |
116 | before: oldrev, | 117 | before: oldrev, |
117 | after: newrev, | 118 | after: newrev, |
118 | ref: ref, | 119 | ref: ref, |
120 | + user_id: key.user_id, | ||
121 | + user_name: key.user_name, | ||
119 | repository: { | 122 | repository: { |
120 | name: name, | 123 | name: name, |
121 | url: web_url, | 124 | url: web_url, |
app/models/users_project.rb
@@ -16,7 +16,7 @@ class UsersProject < ActiveRecord::Base | @@ -16,7 +16,7 @@ class UsersProject < ActiveRecord::Base | ||
16 | validates_presence_of :user_id | 16 | validates_presence_of :user_id |
17 | validates_presence_of :project_id | 17 | validates_presence_of :project_id |
18 | 18 | ||
19 | - delegate :name, :email, :to => :user, :prefix => true | 19 | + delegate :id, :name, :email, :to => :user, :prefix => true |
20 | 20 | ||
21 | def self.bulk_import(project, user_ids, project_access, repo_access) | 21 | def self.bulk_import(project, user_ids, project_access, repo_access) |
22 | UsersProject.transaction do | 22 | UsersProject.transaction do |
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +- @events.each do |event| | ||
2 | + .wll.event_feed | ||
3 | + - if event.push? | ||
4 | + - if event.new_branch? | ||
5 | + User pushed new branch | ||
6 | + - else | ||
7 | + = image_tag gravatar_icon(event.pusher_email), :class => "avatar" | ||
8 | + #{event.pusher_name} pushed to | ||
9 | + = link_to project_commits_path(event.project, :ref => event.branch_name) do | ||
10 | + %strong= event.branch_name | ||
11 | + %span.cgray | ||
12 | + = time_ago_in_words(event.created_at) | ||
13 | + ago. | ||
14 | + - if event.commits.count > 1 | ||
15 | + = link_to compare_project_commits_path(event.project, :from => event.commits.last, :to => event.commits.first) do | ||
16 | + Compare #{event.commits.last.id[0..8]}...#{event.commits.first.id[0..8]} | ||
17 | + - @project = event.project | ||
18 | + %ul.unstyled | ||
19 | + = render event.commits |
app/views/dashboard/index.html.haml
@@ -54,3 +54,12 @@ | @@ -54,3 +54,12 @@ | ||
54 | %hr | 54 | %hr |
55 | .row | 55 | .row |
56 | .dashboard_block= render "dashboard/issues_feed" | 56 | .dashboard_block= render "dashboard/issues_feed" |
57 | + | ||
58 | +- unless @events.blank? | ||
59 | + %div.dashboard_category | ||
60 | + %h3 | ||
61 | + Activities | ||
62 | + | ||
63 | + %hr | ||
64 | + .row | ||
65 | + .dashboard_block= render "dashboard/events_feed" |
app/workers/post_receive.rb
1 | class PostReceive | 1 | class PostReceive |
2 | @queue = :post_receive | 2 | @queue = :post_receive |
3 | 3 | ||
4 | - def self.perform(reponame, oldrev, newrev, ref) | 4 | + def self.perform(reponame, oldrev, newrev, ref, author_key_id) |
5 | project = Project.find_by_path(reponame) | 5 | project = Project.find_by_path(reponame) |
6 | return false if project.nil? | 6 | return false if project.nil? |
7 | 7 | ||
8 | - project.observe_push(oldrev, newrev, ref) | ||
9 | - project.execute_web_hooks(oldrev, newrev, ref) | 8 | + project.observe_push(oldrev, newrev, ref, author_key_id) |
9 | + project.execute_web_hooks(oldrev, newrev, ref, author_key_id) | ||
10 | end | 10 | end |
11 | end | 11 | end |
lib/post-receive-hook
@@ -8,5 +8,5 @@ do | @@ -8,5 +8,5 @@ do | ||
8 | # For every branch or tag that was pushed, create a Resque job in redis. | 8 | # For every branch or tag that was pushed, create a Resque job in redis. |
9 | pwd=`pwd` | 9 | pwd=`pwd` |
10 | reponame=`basename "$pwd" | cut -d. -f1` | 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\",\"$GL_USER\"]}" > /dev/null 2>&1 |
12 | done | 12 | done |
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +desc "Rewrite hooks for repos" | ||
2 | +task :update_hooks => :environment do | ||
3 | + puts "Starting Projects" | ||
4 | + Project.find_each(:batch_size => 100) do |project| | ||
5 | + begin | ||
6 | + if project.commit | ||
7 | + project.repository.write_hooks | ||
8 | + print ".".green | ||
9 | + end | ||
10 | + rescue Exception => e | ||
11 | + print e.message.red | ||
12 | + end | ||
13 | + end | ||
14 | + puts "\nDone with projects" | ||
15 | +end |
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +bundle exec rake environment resque:work QUEUE=* VVERBOSE=1 |