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
Gemfile.lock
... | ... | @@ -88,6 +88,7 @@ GEM |
88 | 88 | coffee-script-source |
89 | 89 | execjs |
90 | 90 | coffee-script-source (1.2.0) |
91 | + colored (1.2) | |
91 | 92 | crack (0.3.1) |
92 | 93 | daemons (1.1.8) |
93 | 94 | database_cleaner (0.7.1) |
... | ... | @@ -296,6 +297,7 @@ DEPENDENCIES |
296 | 297 | carrierwave |
297 | 298 | charlock_holmes |
298 | 299 | coffee-rails (= 3.2.1) |
300 | + colored | |
299 | 301 | database_cleaner |
300 | 302 | devise |
301 | 303 | drapper | ... | ... |
app/assets/stylesheets/common.scss
app/controllers/dashboard_controller.rb
... | ... | @@ -11,6 +11,8 @@ class DashboardController < ApplicationController |
11 | 11 | @user = current_user |
12 | 12 | @issues = current_user.assigned_issues.opened.order("created_at DESC").limit(10) |
13 | 13 | @issues = @issues.includes(:author, :project) |
14 | + | |
15 | + @events = Event.where(:project_id => @projects.map(&:id)).recent.limit(20) | |
14 | 16 | end |
15 | 17 | |
16 | 18 | # Get authored or assigned open merge requests | ... | ... |
app/controllers/issues_controller.rb
... | ... | @@ -69,7 +69,10 @@ class IssuesController < ApplicationController |
69 | 69 | @issue.author = current_user |
70 | 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 | 76 | end |
74 | 77 | |
75 | 78 | def update | ... | ... |
app/models/event.rb
... | ... | @@ -11,6 +11,8 @@ class Event < ActiveRecord::Base |
11 | 11 | |
12 | 12 | serialize :data |
13 | 13 | |
14 | + scope :recent, order("created_at DESC") | |
15 | + | |
14 | 16 | def self.determine_action(record) |
15 | 17 | if [Issue, MergeRequest].include? record.class |
16 | 18 | Event::Created |
... | ... | @@ -18,6 +20,38 @@ class Event < ActiveRecord::Base |
18 | 20 | Event::Commented |
19 | 21 | end |
20 | 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 | 55 | end |
22 | 56 | # == Schema Information |
23 | 57 | # | ... | ... |
app/models/key.rb
app/models/project.rb
... | ... | @@ -90,8 +90,8 @@ class Project < ActiveRecord::Base |
90 | 90 | [GIT_HOST['host'], code].join("/") |
91 | 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 | 96 | Event.create( |
97 | 97 | :project => self, |
... | ... | @@ -100,22 +100,25 @@ class Project < ActiveRecord::Base |
100 | 100 | ) |
101 | 101 | end |
102 | 102 | |
103 | - def execute_web_hooks(oldrev, newrev, ref) | |
103 | + def execute_web_hooks(oldrev, newrev, ref, author_key_id) | |
104 | 104 | ref_parts = ref.split('/') |
105 | 105 | |
106 | 106 | # Return if this is not a push to a branch (e.g. new commits) |
107 | 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 | 111 | web_hooks.each { |web_hook| web_hook.execute(data) } |
112 | 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 | 116 | data = { |
116 | 117 | before: oldrev, |
117 | 118 | after: newrev, |
118 | 119 | ref: ref, |
120 | + user_id: key.user_id, | |
121 | + user_name: key.user_name, | |
119 | 122 | repository: { |
120 | 123 | name: name, |
121 | 124 | url: web_url, | ... | ... |
app/models/users_project.rb
... | ... | @@ -16,7 +16,7 @@ class UsersProject < ActiveRecord::Base |
16 | 16 | validates_presence_of :user_id |
17 | 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 | 21 | def self.bulk_import(project, user_ids, project_access, repo_access) |
22 | 22 | UsersProject.transaction do | ... | ... |
... | ... | @@ -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
app/workers/post_receive.rb
1 | 1 | class PostReceive |
2 | 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 | 5 | project = Project.find_by_path(reponame) |
6 | 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 | 10 | end |
11 | 11 | end | ... | ... |
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\",\"$GL_USER\"]}" > /dev/null 2>&1 | |
12 | 12 | done | ... | ... |
... | ... | @@ -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 @@ |
1 | +bundle exec rake environment resque:work QUEUE=* VVERBOSE=1 | ... | ... |