Only save commit events for repository committers
This commmit should avoid events like:
johan committed 5e61707e to gitorious/patcitos-clone-latest
since johan is not actually a committer of gitorious/patcitos-clone-latest
Signed-off-by: David A. Cuadrado <krawek@gmail.com>
| |   |
| 7 | 7 | require 'date' |
| 8 | 8 | |
| 9 | 9 | gitdir = File.expand_path(File.join(incpath, "..")) |
| 10 | | repository_name = File.basename(gitdir) |
| 11 | | slug = "" |
| 10 | repository = Repository.find_by_path(gitdir) |
| 12 | 11 | |
| 13 | | if repository_name =~ /\.git$/ |
| 14 | | repository_name.sub!(/\.git$/, "") |
| 15 | | slug = File.basename(File.expand_path(File.join(gitdir, ".."))) |
| 16 | | end |
| 17 | | |
| 18 | | project = Project.find_by_slug(slug) |
| 19 | | repository = nil |
| 20 | | |
| 21 | | if project.nil? |
| 22 | | $stderr.puts "Unknown project: '#{slug}'" |
| 12 | if repository.nil? |
| 13 | $stderr.puts "Unknown repository" |
| 23 | 14 | exit 0 |
| 24 | 15 | end |
| 25 | 16 | |
| 26 | | project.repositories.each { |repo| |
| 27 | | if repo.name == repository_name |
| 28 | | repository = repo |
| 29 | | break |
| 30 | | end |
| 31 | | } |
| 32 | | |
| 17 | project = repository.project |
| 33 | 18 | git = Grit::Git.new(gitdir) |
| 34 | 19 | |
| 35 | 20 | while line = gets |
| … | … | |
| 64 | 64 | end |
| 65 | 65 | end |
| 66 | 66 | |
| 67 | | users = User.find(:all, :conditions => ["email in (?)", emails]) |
| 67 | users = repository.committers.find(:all, :conditions => ["email in (?)", emails]) |
| 68 | 68 | user_map = users.inject({}) { |hash, user| hash[user.email] = user; hash } |
| 69 | 69 | |
| 70 | 70 | revs.each do |sha1| |
| … | … | |
| 130 | 130 | |
| 131 | 131 | next unless action_id |
| 132 | 132 | |
| 133 | | # puts "#{hash[:author]}: #{Action.name(action_id)} #{ref} on #{slug} [#{hash[:date]}]" |
| 134 | | # puts " #{hash[:message]}" |
| 135 | | |
| 136 | 133 | project.create_event(action_id, repository, user, ref, hash[:message], hash[:date]) |
| 137 | 134 | action = :update |
| 138 | 135 | end |
| toggle raw diff |
--- a/data/hooks/post-receive
+++ b/data/hooks/post-receive
@@ -7,29 +7,14 @@ require 'rails_env'
require 'date'
gitdir = File.expand_path(File.join(incpath, ".."))
-repository_name = File.basename(gitdir)
-slug = ""
+repository = Repository.find_by_path(gitdir)
-if repository_name =~ /\.git$/
- repository_name.sub!(/\.git$/, "")
- slug = File.basename(File.expand_path(File.join(gitdir, "..")))
-end
-
-project = Project.find_by_slug(slug)
-repository = nil
-
-if project.nil?
- $stderr.puts "Unknown project: '#{slug}'"
+if repository.nil?
+ $stderr.puts "Unknown repository"
exit 0
end
-project.repositories.each { |repo|
- if repo.name == repository_name
- repository = repo
- break
- end
-}
-
+project = repository.project
git = Grit::Git.new(gitdir)
while line = gets
@@ -79,7 +64,7 @@ while line = gets
end
end
- users = User.find(:all, :conditions => ["email in (?)", emails])
+ users = repository.committers.find(:all, :conditions => ["email in (?)", emails])
user_map = users.inject({}) { |hash, user| hash[user.email] = user; hash }
revs.each do |sha1|
@@ -145,9 +130,6 @@ while line = gets
next unless action_id
- # puts "#{hash[:author]}: #{Action.name(action_id)} #{ref} on #{slug} [#{hash[:date]}]"
- # puts " #{hash[:message]}"
-
project.create_event(action_id, repository, user, ref, hash[:message], hash[:date])
action = :update
end |