##// END OF EJS Templates
Added the ability to set the "done ratio" of issues fixed by commit (original path by Nikolay Solakov, slightly edited)....
Jean-Philippe Lang -
r810:5f10cc867327
parent child
Show More
@@ -1,84 +1,86
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class Changeset < ActiveRecord::Base
19 19 belongs_to :repository
20 20 has_many :changes, :dependent => :delete_all
21 21 has_and_belongs_to_many :issues
22 22
23 23 acts_as_event :title => Proc.new {|o| "#{l(:label_revision)} #{o.revision}" + (o.comments.blank? ? '' : (': ' + o.comments))},
24 24 :description => :comments,
25 25 :datetime => :committed_on,
26 26 :author => :committer,
27 27 :url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project_id, :rev => o.revision}}
28 28
29 29 acts_as_searchable :columns => 'comments',
30 30 :include => :repository,
31 31 :project_key => "#{Repository.table_name}.project_id",
32 32 :date_column => 'committed_on'
33 33
34 34 validates_presence_of :repository_id, :revision, :committed_on, :commit_date
35 35 validates_numericality_of :revision, :only_integer => true
36 36 validates_uniqueness_of :revision, :scope => :repository_id
37 37 validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
38 38
39 39 def comments=(comment)
40 40 write_attribute(:comments, comment.strip)
41 41 end
42 42
43 43 def committed_on=(date)
44 44 self.commit_date = date
45 45 super
46 46 end
47 47
48 48 def after_create
49 49 scan_comment_for_issue_ids
50 50 end
51 51
52 52 def scan_comment_for_issue_ids
53 53 return if comments.blank?
54 54 # keywords used to reference issues
55 55 ref_keywords = Setting.commit_ref_keywords.downcase.split(",")
56 56 # keywords used to fix issues
57 57 fix_keywords = Setting.commit_fix_keywords.downcase.split(",")
58 # status applied
58 # status and optional done ratio applied
59 59 fix_status = IssueStatus.find_by_id(Setting.commit_fix_status_id)
60 done_ratio = Setting.commit_fix_done_ratio.blank? ? nil : Setting.commit_fix_done_ratio.to_i
60 61
61 62 kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw.strip)}.join("|")
62 63 return if kw_regexp.blank?
63 64
64 65 # remove any associated issues
65 66 self.issues.clear
66 67
67 68 comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match|
68 69 action = match[0]
69 70 target_issue_ids = match[1].scan(/\d+/)
70 71 target_issues = repository.project.issues.find_all_by_id(target_issue_ids)
71 72 if fix_status && fix_keywords.include?(action.downcase)
72 73 # update status of issues
73 74 logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug?
74 75 target_issues.each do |issue|
75 76 # don't change the status is the issue is already closed
76 77 next if issue.status.is_closed?
77 78 issue.status = fix_status
79 issue.done_ratio = done_ratio if done_ratio
78 80 issue.save
79 81 end
80 82 end
81 83 self.issues << target_issues
82 84 end
83 85 end
84 86 end
@@ -1,93 +1,94
1 1 <h2><%= l(:label_settings) %></h2>
2 2
3 3 <div id="settings">
4 4 <% form_tag({:action => 'edit'}) do %>
5 5 <div class="box tabular">
6 6 <p><label><%= l(:setting_app_title) %></label>
7 7 <%= text_field_tag 'settings[app_title]', Setting.app_title, :size => 30 %></p>
8 8
9 9 <p><label><%= l(:setting_app_subtitle) %></label>
10 10 <%= text_field_tag 'settings[app_subtitle]', Setting.app_subtitle, :size => 60 %></p>
11 11
12 12 <p><label><%= l(:setting_welcome_text) %></label>
13 13 <%= text_area_tag 'settings[welcome_text]', Setting.welcome_text, :cols => 60, :rows => 5, :class => 'wiki-edit' %></p>
14 14 <%= wikitoolbar_for 'settings[welcome_text]' %>
15 15
16 16 <p><label><%= l(:label_theme) %></label>
17 17 <%= select_tag 'settings[ui_theme]', options_for_select( ([[l(:label_default), '']] + Redmine::Themes.themes.collect {|t| [t.name, t.id]}), Setting.ui_theme) %></p>
18 18
19 19 <p><label><%= l(:setting_default_language) %></label>
20 20 <%= select_tag 'settings[default_language]', options_for_select( lang_options_for_select(false), Setting.default_language) %></p>
21 21
22 22 <p><label><%= l(:setting_date_format) %></label>
23 23 <%= select_tag 'settings[date_format]', options_for_select( [[l(:label_language_based), '0'], ['ISO 8601 (YYYY-MM-DD)', '1']], Setting.date_format) %></p>
24 24
25 25 <p><label><%= l(:setting_attachment_max_size) %></label>
26 26 <%= text_field_tag 'settings[attachment_max_size]', Setting.attachment_max_size, :size => 6 %> KB</p>
27 27
28 28 <p><label><%= l(:setting_issues_export_limit) %></label>
29 29 <%= text_field_tag 'settings[issues_export_limit]', Setting.issues_export_limit, :size => 6 %></p>
30 30
31 31 <p><label><%= l(:setting_cross_project_issue_relations) %></label>
32 32 <%= check_box_tag 'settings[cross_project_issue_relations]', 1, Setting.cross_project_issue_relations? %><%= hidden_field_tag 'settings[cross_project_issue_relations]', 0 %></p>
33 33
34 34 <p><label><%= l(:setting_mail_from) %></label>
35 35 <%= text_field_tag 'settings[mail_from]', Setting.mail_from, :size => 60 %></p>
36 36
37 37 <p><label><%= l(:setting_host_name) %></label>
38 38 <%= text_field_tag 'settings[host_name]', Setting.host_name, :size => 60 %></p>
39 39
40 40 <p><label><%= l(:setting_text_formatting) %></label>
41 41 <%= select_tag 'settings[text_formatting]', options_for_select([[l(:label_none), "0"], ["textile", "textile"]], Setting.text_formatting) %></p>
42 42
43 43 <p><label><%= l(:setting_wiki_compression) %></label>
44 44 <%= select_tag 'settings[wiki_compression]', options_for_select( [[l(:label_none), 0], ["gzip", "gzip"]], Setting.wiki_compression) %></p>
45 45
46 46 <p><label><%= l(:setting_feeds_limit) %></label>
47 47 <%= text_field_tag 'settings[feeds_limit]', Setting.feeds_limit, :size => 6 %></p>
48 48
49 49 <p><label><%= l(:setting_autofetch_changesets) %></label>
50 50 <%= check_box_tag 'settings[autofetch_changesets]', 1, Setting.autofetch_changesets? %><%= hidden_field_tag 'settings[autofetch_changesets]', 0 %></p>
51 51
52 52 <p><label><%= l(:setting_sys_api_enabled) %></label>
53 53 <%= check_box_tag 'settings[sys_api_enabled]', 1, Setting.sys_api_enabled? %><%= hidden_field_tag 'settings[sys_api_enabled]', 0 %></p>
54 54
55 55 <p><label><%= l(:setting_repositories_encodings) %></label>
56 56 <%= text_field_tag 'settings[repositories_encodings]', Setting.repositories_encodings, :size => 60 %><br /><em><%= l(:text_comma_separated) %></em></p>
57 57 </div>
58 58
59 59 <fieldset class="box"><legend><%= l(:setting_issue_list_default_columns) %></legend>
60 60 <%= hidden_field_tag 'settings[issue_list_default_columns][]', '' %>
61 61 <p><% Query.available_columns.each do |column| %>
62 62 <label><%= check_box_tag 'settings[issue_list_default_columns][]', column.name, Setting.issue_list_default_columns.include?(column.name.to_s) %>
63 63 <%= l("field_#{column.name}") %></label>
64 64 <% end %></p>
65 65 </fieldset>
66 66
67 67 <fieldset class="box tabular"><legend><%= l(:label_authentication) %></legend>
68 68 <p><label><%= l(:setting_login_required) %></label>
69 69 <%= check_box_tag 'settings[login_required]', 1, Setting.login_required? %><%= hidden_field_tag 'settings[login_required]', 0 %></p>
70 70
71 71 <p><label><%= l(:setting_autologin) %></label>
72 72 <%= select_tag 'settings[autologin]', options_for_select( [[l(:label_disabled), "0"]] + [1, 7, 30, 365].collect{|days| [lwr(:actionview_datehelper_time_in_words_day, days), days.to_s]}, Setting.autologin) %></p>
73 73
74 74 <p><label><%= l(:setting_self_registration) %></label>
75 75 <%= check_box_tag 'settings[self_registration]', 1, Setting.self_registration? %><%= hidden_field_tag 'settings[self_registration]', 0 %></p>
76 76
77 77 <p><label><%= l(:label_password_lost) %></label>
78 78 <%= check_box_tag 'settings[lost_password]', 1, Setting.lost_password? %><%= hidden_field_tag 'settings[lost_password]', 0 %></p>
79 79 </fieldset>
80 80
81 81 <fieldset class="box tabular"><legend><%= l(:text_issues_ref_in_commit_messages) %></legend>
82 82 <p><label><%= l(:setting_commit_ref_keywords) %></label>
83 83 <%= text_field_tag 'settings[commit_ref_keywords]', Setting.commit_ref_keywords, :size => 30 %><br /><em><%= l(:text_comma_separated) %></em></p>
84 84
85 85 <p><label><%= l(:setting_commit_fix_keywords) %></label>
86 86 <%= text_field_tag 'settings[commit_fix_keywords]', Setting.commit_fix_keywords, :size => 30 %>
87 87 &nbsp;<%= l(:label_applied_status) %>: <%= select_tag 'settings[commit_fix_status_id]', options_for_select( [["", 0]] + IssueStatus.find(:all).collect{|status| [status.name, status.id.to_s]}, Setting.commit_fix_status_id) %>
88 &nbsp;<%= l(:field_done_ratio) %>: <%= select_tag 'settings[commit_fix_done_ratio]', options_for_select( [[l(:label_no_change_option), '']] + ((0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }), Setting.commit_fix_done_ratio) %>
88 89 <br /><em><%= l(:text_comma_separated) %></em></p>
89 90 </fieldset>
90 91
91 92 <%= submit_tag l(:button_save) %>
92 93 </div>
93 94 <% end %> No newline at end of file
@@ -1,97 +1,100
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18
19 19 # DO NOT MODIFY THIS FILE !!!
20 20 # Settings can be defined through the application in Admin -> Settings
21 21
22 22 app_title:
23 23 default: Redmine
24 24 app_subtitle:
25 25 default: Project management
26 26 welcome_text:
27 27 default:
28 28 login_required:
29 29 default: 0
30 30 self_registration:
31 31 default: 1
32 32 lost_password:
33 33 default: 1
34 34 attachment_max_size:
35 35 format: int
36 36 default: 5120
37 37 issues_export_limit:
38 38 format: int
39 39 default: 500
40 40 mail_from:
41 41 default: redmine@somenet.foo
42 42 text_formatting:
43 43 default: textile
44 44 wiki_compression:
45 45 default: ""
46 46 default_language:
47 47 default: en
48 48 host_name:
49 49 default: localhost:3000
50 50 feeds_limit:
51 51 format: int
52 52 default: 15
53 53 autofetch_changesets:
54 54 default: 1
55 55 sys_api_enabled:
56 56 default: 0
57 57 commit_ref_keywords:
58 58 default: 'refs,references,IssueID'
59 59 commit_fix_keywords:
60 60 default: 'fixes,closes'
61 61 commit_fix_status_id:
62 62 format: int
63 63 default: 0
64 commit_fix_done_ratio:
65 format: int
66 default: 100
64 67 # autologin duration in days
65 68 # 0 means autologin is disabled
66 69 autologin:
67 70 format: int
68 71 default: 0
69 72 # date format
70 73 # 0: language based
71 74 # 1: ISO format
72 75 date_format:
73 76 format: int
74 77 default: 0
75 78 cross_project_issue_relations:
76 79 default: 0
77 80 notified_events:
78 81 serialized: true
79 82 default: --
80 83 - issue_added
81 84 - issue_updated
82 85 issue_list_default_columns:
83 86 serialized: true
84 87 default: --
85 88 - tracker
86 89 - status
87 90 - priority
88 91 - subject
89 92 - assigned_to
90 93 - updated_on
91 94 # encodings used to convert repository files content to UTF-8
92 95 # multiple values accepted, comma separated
93 96 repositories_encodings:
94 97 default: ''
95 98 ui_theme:
96 99 default: ''
97 100 No newline at end of file
@@ -1,71 +1,74
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class RepositoryTest < Test::Unit::TestCase
21 21 fixtures :projects, :repositories, :issues, :issue_statuses, :changesets, :changes
22 22
23 23 def setup
24 24 @repository = Project.find(1).repository
25 25 end
26 26
27 27 def test_create
28 28 repository = Repository::Subversion.new(:project => Project.find(2))
29 29 assert !repository.save
30 30
31 31 repository.url = "svn://localhost"
32 32 assert repository.save
33 33 repository.reload
34 34
35 35 project = Project.find(2)
36 36 assert_equal repository, project.repository
37 37 end
38 38
39 39 def test_scan_changesets_for_issue_ids
40 40 # choosing a status to apply to fix issues
41 41 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
42
42 Setting.commit_fix_done_ratio = "90"
43
43 44 # make sure issue 1 is not already closed
44 45 assert !Issue.find(1).status.is_closed?
45 46
46 47 Repository.scan_changesets_for_issue_ids
47 48 assert_equal [101, 102], Issue.find(3).changeset_ids
48 49
49 50 # fixed issues
50 assert Issue.find(1).status.is_closed?
51 assert_equal [101], Issue.find(1).changeset_ids
51 fixed_issue = Issue.find(1)
52 assert fixed_issue.status.is_closed?
53 assert_equal 90, fixed_issue.done_ratio
54 assert_equal [101], fixed_issue.changeset_ids
52 55
53 56 # ignoring commits referencing an issue of another project
54 57 assert_equal [], Issue.find(4).changesets
55 58 end
56 59
57 60 def test_for_changeset_comments_strip
58 61 repository = Repository::Mercurial.create( :project => Project.find( 4 ), :url => '/foo/bar/baz' )
59 62 comment = <<-COMMENT
60 63 This is a loooooooooooooooooooooooooooong comment
61 64
62 65
63 66 COMMENT
64 67 changeset = Changeset.new(
65 68 :comments => comment, :commit_date => Time.now, :revision => 0, :scmid => 'f39b7922fb3c',
66 69 :committer => 'foo <foo@example.com>', :committed_on => Time.now, :repository_id => repository )
67 70 assert( changeset.save )
68 71 assert_not_equal( comment, changeset.comments )
69 72 assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments )
70 73 end
71 74 end
General Comments 0
You need to be logged in to leave comments. Login now