Commit b81c513aaa03d9dcde5253104870c622c826def8

move #users_by_commits into Repository model where it belongs

Commit diff

app/helpers/repositories_helper.rb

 
1module RepositoriesHelper
2 # Returns a Hash {email => user}
3 def self.users_by_commits(commits)
4 emails = commits.map { |commit| commit.committer.email }
5 users = User.find(:all, :conditions => ["email in (?)", emails])
6 email_user = {}
7 users.each { |user|
8 email_user[user.email] = user
9 }
10
11 email_user
12 end
13
1module RepositoriesHelper
142 def log_path(objectish = "master", options = {})
153 if options.blank? # just to avoid the ? being tacked onto the url
164 project_repository_log_path(@project, @repository, objectish)
toggle raw diff

app/models/repository.rb

 
212212 hash
213213 end
214214 end
215
216 # Returns a Hash {email => user}, where email is selected from the +commits+
217 def users_by_commits(commits)
218 emails = commits.map { |commit| commit.committer.email }.uniq
219 users = User.find(:all, :conditions => ["email in (?)", emails])
220
221 users_by_email = users.inject({}){|hash, user| hash[user.email] = user; hash }
222 users_by_email
223 end
215224
216225 protected
217226 def set_as_mainline_if_first
toggle raw diff

app/views/logs/_log.html.erb

 
1<% email_user = RepositoriesHelper.users_by_commits(@commits) %>
1<% users_by_email = @repository.users_by_commits(@commits) %>
22<ul class="commit_list">
33<% @commits.each do |commit| -%>
4<% user = email_user[commit.committer.email] %>
4<% user = users_by_email[commit.committer.email] %>
55<li class="commit_item">
66 <div>
77 <a href=""><%= link_to h(commit.id_abbrev),
toggle raw diff

app/views/projects/show.html.erb

 
3636 <th></th>
3737 <th></th>
3838 </thead>
39 <% commits = [] %>
4039 <% repositories = @repositories.sort_by { |e| if e.last_commit then commits << e.last_commit; e.mainline? ? Time.now : e.last_commit.committed_date; else Time.at(0); end } %>
41 <% email_user = RepositoriesHelper.users_by_commits(commits) %>
4240 <% repositories.reverse_each do |repos| # FIXME: need to graph the parent relation proper -%>
43 <% user = email_user[repos.last_commit.committer.email] if repos.has_commits? %>
4441 <tr class="<%= cycle("even", "odd") -%> <%= repos.mainline? ? "mainline" : "clone" -%>">
4542 <td class="name">
4643 <%= link_to h(repos.name), project_repository_path(@project, repos) -%>
toggle raw diff

spec/models/repository_spec.rb

 
257257 @repository.count_commits_from_last_week_by_user(users(:johan)).should == 0
258258 end
259259
260 it "returns a set of users from a list of commits" do
261 commits = []
262 users(:johan, :moe).map(&:email).each do |email|
263 committer = OpenStruct.new(:email => email)
264 commits << OpenStruct.new(:committer => committer)
265 end
266 users = @repository.users_by_commits(commits)
267 users.keys.sort.should == users(:johan, :moe).map(&:email).sort
268 users.values.map(&:login).sort.should == users(:johan, :moe).map(&:login).sort
269 end
270
260271 describe "observers" do
261272 it "sends an email to the admin if there's a parent" do
262273 Mailer.should_receive(:deliver_new_repository_clone).with(@repository).and_return(true)
toggle raw diff