Mercurial > hg > soundsoftware-site
comparison app/controllers/repositories_controller.rb @ 1526:404aa68d4227
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 11 Sep 2014 12:46:20 +0100 |
parents | a1bdbf8a87d5 |
children |
comparison
equal
deleted
inserted
replaced
1493:a5f2bdf3b486 | 1526:404aa68d4227 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2014 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require 'SVG/Graph/Bar' | 18 require 'SVG/Graph/Bar' |
19 require 'SVG/Graph/BarHorizontal' | 19 require 'SVG/Graph/BarHorizontal' |
20 require 'digest/sha1' | 20 require 'digest/sha1' |
21 require 'redmine/scm/adapters/abstract_adapter' | 21 require 'redmine/scm/adapters' |
22 | 22 |
23 class ChangesetNotFound < Exception; end | 23 class ChangesetNotFound < Exception; end |
24 class InvalidRevisionParam < Exception; end | 24 class InvalidRevisionParam < Exception; end |
25 | 25 |
26 class RepositoriesController < ApplicationController | 26 class RepositoriesController < ApplicationController |
93 | 93 |
94 def committers | 94 def committers |
95 @committers = @repository.committers | 95 @committers = @repository.committers |
96 @users = @project.users | 96 @users = @project.users |
97 additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id) | 97 additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id) |
98 @users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty? | 98 @users += User.where(:id => additional_user_ids).all unless additional_user_ids.empty? |
99 @users.compact! | 99 @users.compact! |
100 @users.sort! | 100 @users.sort! |
101 if request.post? && params[:committers].is_a?(Hash) | 101 if request.post? && params[:committers].is_a?(Hash) |
102 # Build a hash with repository usernames as keys and corresponding user ids as values | 102 # Build a hash with repository usernames as keys and corresponding user ids as values |
103 @repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h} | 103 @repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h} |
110 @repository.destroy if request.delete? | 110 @repository.destroy if request.delete? |
111 redirect_to settings_project_path(@project, :tab => 'repositories') | 111 redirect_to settings_project_path(@project, :tab => 'repositories') |
112 end | 112 end |
113 | 113 |
114 def show | 114 def show |
115 @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty? | 115 @repository.fetch_changesets if @project.active? && Setting.autofetch_changesets? && @path.empty? |
116 | 116 |
117 @entries = @repository.entries(@path, @rev) | 117 @entries = @repository.entries(@path, @rev) |
118 @changeset = @repository.find_changeset_by_name(@rev) | 118 @changeset = @repository.find_changeset_by_name(@rev) |
119 if request.xhr? | 119 if request.xhr? |
120 @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) | 120 @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) |
137 @changeset = @repository.find_changeset_by_name(@rev) | 137 @changeset = @repository.find_changeset_by_name(@rev) |
138 end | 138 end |
139 | 139 |
140 def revisions | 140 def revisions |
141 @changeset_count = @repository.changesets.count | 141 @changeset_count = @repository.changesets.count |
142 @changeset_pages = Paginator.new self, @changeset_count, | 142 @changeset_pages = Paginator.new @changeset_count, |
143 per_page_option, | 143 per_page_option, |
144 params['page'] | 144 params['page'] |
145 @changesets = @repository.changesets.find(:all, | 145 @changesets = @repository.changesets. |
146 :limit => @changeset_pages.items_per_page, | 146 limit(@changeset_pages.per_page). |
147 :offset => @changeset_pages.current.offset, | 147 offset(@changeset_pages.offset). |
148 :include => [:user, :repository, :parents]) | 148 includes(:user, :repository, :parents). |
149 all | |
149 | 150 |
150 respond_to do |format| | 151 respond_to do |format| |
151 format.html { render :layout => false if request.xhr? } | 152 format.html { render :layout => false if request.xhr? } |
152 format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") } | 153 format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") } |
153 end | 154 end |
226 end | 227 end |
227 | 228 |
228 # Adds a related issue to a changeset | 229 # Adds a related issue to a changeset |
229 # POST /projects/:project_id/repository/(:repository_id/)revisions/:rev/issues | 230 # POST /projects/:project_id/repository/(:repository_id/)revisions/:rev/issues |
230 def add_related_issue | 231 def add_related_issue |
231 @issue = @changeset.find_referenced_issue_by_id(params[:issue_id]) | 232 issue_id = params[:issue_id].to_s.sub(/^#/,'') |
233 @issue = @changeset.find_referenced_issue_by_id(issue_id) | |
232 if @issue && (!@issue.visible? || @changeset.issues.include?(@issue)) | 234 if @issue && (!@issue.visible? || @changeset.issues.include?(@issue)) |
233 @issue = nil | 235 @issue = nil |
234 end | 236 end |
235 | 237 |
236 if @issue | 238 if @issue |
349 | 351 |
350 def graph_commits_per_month(repository) | 352 def graph_commits_per_month(repository) |
351 @date_to = Date.today | 353 @date_to = Date.today |
352 @date_from = @date_to << 11 | 354 @date_from = @date_to << 11 |
353 @date_from = Date.civil(@date_from.year, @date_from.month, 1) | 355 @date_from = Date.civil(@date_from.year, @date_from.month, 1) |
354 commits_by_day = Changeset.count( | 356 commits_by_day = Changeset. |
355 :all, :group => :commit_date, | 357 where("repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to). |
356 :conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]) | 358 group(:commit_date). |
359 count | |
357 commits_by_month = [0] * 12 | 360 commits_by_month = [0] * 12 |
358 commits_by_day.each {|c| commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last } | 361 commits_by_day.each {|c| commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last } |
359 | 362 |
360 changes_by_day = Change.count( | 363 changes_by_day = Change. |
361 :all, :group => :commit_date, :include => :changeset, | 364 joins(:changeset). |
362 :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]) | 365 where("#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to). |
366 group(:commit_date). | |
367 count | |
363 changes_by_month = [0] * 12 | 368 changes_by_month = [0] * 12 |
364 changes_by_day.each {|c| changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last } | 369 changes_by_day.each {|c| changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last } |
365 | 370 |
366 fields = [] | 371 fields = [] |
367 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)} | 372 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)} |
390 | 395 |
391 graph.burn | 396 graph.burn |
392 end | 397 end |
393 | 398 |
394 def graph_commits_per_author(repository) | 399 def graph_commits_per_author(repository) |
395 commits_by_author = Changeset.count(:all, :group => :committer, :conditions => ["repository_id = ?", repository.id]) | 400 commits_by_author = Changeset.where("repository_id = ?", repository.id).group(:committer).count |
396 commits_by_author.to_a.sort! {|x, y| x.last <=> y.last} | 401 commits_by_author.to_a.sort! {|x, y| x.last <=> y.last} |
397 | 402 |
398 changes_by_author = Change.count(:all, :group => :committer, :include => :changeset, :conditions => ["#{Changeset.table_name}.repository_id = ?", repository.id]) | 403 changes_by_author = Change.joins(:changeset).where("#{Changeset.table_name}.repository_id = ?", repository.id).group(:committer).count |
399 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o} | 404 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o} |
400 | 405 |
401 fields = commits_by_author.collect {|r| r.first} | 406 fields = commits_by_author.collect {|r| r.first} |
402 commits_data = commits_by_author.collect {|r| r.last} | 407 commits_data = commits_by_author.collect {|r| r.last} |
403 changes_data = commits_by_author.collect {|r| h[r.first] || 0} | 408 changes_data = commits_by_author.collect {|r| h[r.first] || 0} |
408 | 413 |
409 # Remove email adress in usernames | 414 # Remove email adress in usernames |
410 fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') } | 415 fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') } |
411 | 416 |
412 graph = SVG::Graph::BarHorizontal.new( | 417 graph = SVG::Graph::BarHorizontal.new( |
413 :height => 400, | 418 :height => 30 * commits_data.length, |
414 :width => 800, | 419 :width => 800, |
415 :fields => fields, | 420 :fields => fields, |
416 :stack => :side, | 421 :stack => :side, |
417 :scale_integers => true, | 422 :scale_integers => true, |
418 :show_data_values => false, | 423 :show_data_values => false, |