Commit bb164ebf authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Send author to post hook. Display push activity to dashboard

parent 796784c7
...@@ -30,6 +30,7 @@ gem "charlock_holmes" ...@@ -30,6 +30,7 @@ gem "charlock_holmes"
gem "foreman" gem "foreman"
gem "omniauth-ldap" gem "omniauth-ldap"
gem 'bootstrap-sass', "1.4.4" gem 'bootstrap-sass', "1.4.4"
gem "colored"
group :assets do group :assets do
gem "sass-rails", "3.2.3" gem "sass-rails", "3.2.3"
......
...@@ -88,6 +88,7 @@ GEM ...@@ -88,6 +88,7 @@ GEM
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.2.0) coffee-script-source (1.2.0)
colored (1.2)
crack (0.3.1) crack (0.3.1)
daemons (1.1.8) daemons (1.1.8)
database_cleaner (0.7.1) database_cleaner (0.7.1)
...@@ -296,6 +297,7 @@ DEPENDENCIES ...@@ -296,6 +297,7 @@ DEPENDENCIES
carrierwave carrierwave
charlock_holmes charlock_holmes
coffee-rails (= 3.2.1) coffee-rails (= 3.2.1)
colored
database_cleaner database_cleaner
devise devise
drapper drapper
......
...@@ -626,3 +626,9 @@ p.time { ...@@ -626,3 +626,9 @@ p.time {
} }
} }
} }
.event_feed {
ul {
margin-left:50px;
}
}
...@@ -11,6 +11,8 @@ class DashboardController < ApplicationController ...@@ -11,6 +11,8 @@ class DashboardController < ApplicationController
@user = current_user @user = current_user
@issues = current_user.assigned_issues.opened.order("created_at DESC").limit(10) @issues = current_user.assigned_issues.opened.order("created_at DESC").limit(10)
@issues = @issues.includes(:author, :project) @issues = @issues.includes(:author, :project)
@events = Event.where(:project_id => @projects.map(&:id)).recent.limit(20)
end end
# Get authored or assigned open merge requests # Get authored or assigned open merge requests
......
...@@ -69,7 +69,10 @@ class IssuesController < ApplicationController ...@@ -69,7 +69,10 @@ class IssuesController < ApplicationController
@issue.author = current_user @issue.author = current_user
@issue.save @issue.save
respond_with(@issue) respond_to do |format|
format.html { redirect_to project_issue_path(@project, @issue) }
format.js
end
end end
def update def update
......
...@@ -11,6 +11,8 @@ class Event < ActiveRecord::Base ...@@ -11,6 +11,8 @@ class Event < ActiveRecord::Base
serialize :data serialize :data
scope :recent, order("created_at DESC")
def self.determine_action(record) def self.determine_action(record)
if [Issue, MergeRequest].include? record.class if [Issue, MergeRequest].include? record.class
Event::Created Event::Created
...@@ -18,6 +20,38 @@ class Event < ActiveRecord::Base ...@@ -18,6 +20,38 @@ class Event < ActiveRecord::Base
Event::Commented Event::Commented
end end
end end
def push?
action == self.class::Pushed
end
def new_branch?
data[:before] =~ /^00000/
end
def commit_from
data[:before]
end
def commit_to
data[:after]
end
def branch_name
@branch_name ||= data[:ref].gsub("refs/heads/", "")
end
def pusher
User.find_by_id(data[:user_id])
end
def commits
@commits ||= data[:commits].map do |commit|
project.commit(commit[:id])
end
end
delegate :id, :name, :email, :to => :pusher, :prefix => true, :allow_nil => true
end end
# == Schema Information # == Schema Information
# #
......
...@@ -14,6 +14,7 @@ class Key < ActiveRecord::Base ...@@ -14,6 +14,7 @@ class Key < ActiveRecord::Base
before_save :set_identifier before_save :set_identifier
after_save :update_repository after_save :update_repository
after_destroy :repository_delete_key after_destroy :repository_delete_key
delegate :id, :name, :email, :to => :user, :prefix => true
def set_identifier def set_identifier
if is_deploy_key if is_deploy_key
......
...@@ -90,8 +90,8 @@ class Project < ActiveRecord::Base ...@@ -90,8 +90,8 @@ class Project < ActiveRecord::Base
[GIT_HOST['host'], code].join("/") [GIT_HOST['host'], code].join("/")
end end
def observe_push(oldrev, newrev, ref) def observe_push(oldrev, newrev, ref, author_key_id)
data = web_hook_data(oldrev, newrev, ref) data = web_hook_data(oldrev, newrev, ref, author_key_id)
Event.create( Event.create(
:project => self, :project => self,
...@@ -100,22 +100,25 @@ class Project < ActiveRecord::Base ...@@ -100,22 +100,25 @@ class Project < ActiveRecord::Base
) )
end end
def execute_web_hooks(oldrev, newrev, ref) def execute_web_hooks(oldrev, newrev, ref, author_key_id)
ref_parts = ref.split('/') ref_parts = ref.split('/')
# Return if this is not a push to a branch (e.g. new commits) # Return if this is not a push to a branch (e.g. new commits)
return if ref_parts[1] !~ /heads/ || oldrev == "00000000000000000000000000000000" return if ref_parts[1] !~ /heads/ || oldrev == "00000000000000000000000000000000"
data = web_hook_data(oldrev, newrev, ref) data = web_hook_data(oldrev, newrev, ref, author_key_id)
web_hooks.each { |web_hook| web_hook.execute(data) } web_hooks.each { |web_hook| web_hook.execute(data) }
end end
def web_hook_data(oldrev, newrev, ref) def web_hook_data(oldrev, newrev, ref, author_key_id)
key = Key.find_by_identifier(author_key_id)
data = { data = {
before: oldrev, before: oldrev,
after: newrev, after: newrev,
ref: ref, ref: ref,
user_id: key.user_id,
user_name: key.user_name,
repository: { repository: {
name: name, name: name,
url: web_url, url: web_url,
......
...@@ -16,7 +16,7 @@ class UsersProject < ActiveRecord::Base ...@@ -16,7 +16,7 @@ class UsersProject < ActiveRecord::Base
validates_presence_of :user_id validates_presence_of :user_id
validates_presence_of :project_id validates_presence_of :project_id
delegate :name, :email, :to => :user, :prefix => true delegate :id, :name, :email, :to => :user, :prefix => true
def self.bulk_import(project, user_ids, project_access, repo_access) def self.bulk_import(project, user_ids, project_access, repo_access)
UsersProject.transaction do UsersProject.transaction do
......
- @events.each do |event|
.wll.event_feed
- if event.push?
- if event.new_branch?
User pushed new branch
- else
= image_tag gravatar_icon(event.pusher_email), :class => "avatar"
#{event.pusher_name} pushed to
= link_to project_commits_path(event.project, :ref => event.branch_name) do
%strong= event.branch_name
%span.cgray
= time_ago_in_words(event.created_at)
ago.
- if event.commits.count > 1
= link_to compare_project_commits_path(event.project, :from => event.commits.last, :to => event.commits.first) do
Compare #{event.commits.last.id[0..8]}...#{event.commits.first.id[0..8]}
- @project = event.project
%ul.unstyled
= render event.commits
...@@ -54,3 +54,12 @@ ...@@ -54,3 +54,12 @@
%hr %hr
.row .row
.dashboard_block= render "dashboard/issues_feed" .dashboard_block= render "dashboard/issues_feed"
- unless @events.blank?
%div.dashboard_category
%h3
Activities
%hr
.row
.dashboard_block= render "dashboard/events_feed"
class PostReceive class PostReceive
@queue = :post_receive @queue = :post_receive
def self.perform(reponame, oldrev, newrev, ref) def self.perform(reponame, oldrev, newrev, ref, author_key_id)
project = Project.find_by_path(reponame) project = Project.find_by_path(reponame)
return false if project.nil? return false if project.nil?
project.observe_push(oldrev, newrev, ref) project.observe_push(oldrev, newrev, ref, author_key_id)
project.execute_web_hooks(oldrev, newrev, ref) project.execute_web_hooks(oldrev, newrev, ref, author_key_id)
end end
end end
...@@ -8,5 +8,5 @@ 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\",\"$GL_USER\"]}" > /dev/null 2>&1
done done
desc "Rewrite hooks for repos"
task :update_hooks => :environment do
puts "Starting Projects"
Project.find_each(:batch_size => 100) do |project|
begin
if project.commit
project.repository.write_hooks
print ".".green
end
rescue Exception => e
print e.message.red
end
end
puts "\nDone with projects"
end
bundle exec rake environment resque:work QUEUE=* VVERBOSE=1
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment