Commit bb164ebf authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Send author to post hook. Display push activity to dashboard

parent e77b32f5af1c
......@@ -30,6 +30,7 @@ gem "charlock_holmes"
gem "foreman"
gem "omniauth-ldap"
gem 'bootstrap-sass', "1.4.4"
gem "colored"
group :assets do
gem "sass-rails", "3.2.3"
......
......@@ -88,6 +88,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.2.0)
colored (1.2)
crack (0.3.1)
daemons (1.1.8)
database_cleaner (0.7.1)
......@@ -296,6 +297,7 @@ DEPENDENCIES
carrierwave
charlock_holmes
coffee-rails (= 3.2.1)
colored
database_cleaner
devise
drapper
......
......@@ -626,3 +626,9 @@ p.time {
}
}
}
.event_feed {
ul {
margin-left:50px;
}
}
......@@ -11,6 +11,8 @@ def index
@user = current_user
@issues = current_user.assigned_issues.opened.order("created_at DESC").limit(10)
@issues = @issues.includes(:author, :project)
@events = Event.where(:project_id => @projects.map(&:id)).recent.limit(20)
end
# Get authored or assigned open merge requests
......
......@@ -69,7 +69,10 @@ def create
@issue.author = current_user
@issue.save
respond_with(@issue)
respond_to do |format|
format.html { redirect_to project_issue_path(@project, @issue) }
format.js
end
end
def update
......
......@@ -11,6 +11,8 @@ class Event < ActiveRecord::Base
serialize :data
scope :recent, order("created_at DESC")
def self.determine_action(record)
if [Issue, MergeRequest].include? record.class
Event::Created
......@@ -18,6 +20,38 @@ def self.determine_action(record)
Event::Commented
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
# == Schema Information
#
......
......@@ -14,6 +14,7 @@ class Key < ActiveRecord::Base
before_save :set_identifier
after_save :update_repository
after_destroy :repository_delete_key
delegate :id, :name, :email, :to => :user, :prefix => true
def set_identifier
if is_deploy_key
......
......@@ -90,8 +90,8 @@ def web_url
[GIT_HOST['host'], code].join("/")
end
def observe_push(oldrev, newrev, ref)
data = web_hook_data(oldrev, newrev, ref)
def observe_push(oldrev, newrev, ref, author_key_id)
data = web_hook_data(oldrev, newrev, ref, author_key_id)
Event.create(
:project => self,
......@@ -100,22 +100,25 @@ def observe_push(oldrev, newrev, ref)
)
end
def execute_web_hooks(oldrev, newrev, ref)
def execute_web_hooks(oldrev, newrev, ref, author_key_id)
ref_parts = ref.split('/')
# Return if this is not a push to a branch (e.g. new commits)
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) }
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 = {
before: oldrev,
after: newrev,
ref: ref,
user_id: key.user_id,
user_name: key.user_name,
repository: {
name: name,
url: web_url,
......
......@@ -16,7 +16,7 @@ class UsersProject < ActiveRecord::Base
validates_presence_of :user_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)
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 @@
%hr
.row
.dashboard_block= render "dashboard/issues_feed"
- unless @events.blank?
%div.dashboard_category
%h3
Activities
%hr
.row
.dashboard_block= render "dashboard/events_feed"
class PostReceive
@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)
return false if project.nil?
project.observe_push(oldrev, newrev, ref)
project.execute_web_hooks(oldrev, newrev, ref)
project.observe_push(oldrev, newrev, ref, author_key_id)
project.execute_web_hooks(oldrev, newrev, ref, author_key_id)
end
end
......@@ -8,5 +8,5 @@ do
# For every branch or tag that was pushed, create a Resque job in redis.
pwd=`pwd`
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
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