@@ -108,7 +108,7 class IssuesController < ApplicationController | |||||
108 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") |
|
108 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") | |
109 | @journals.each_with_index {|j,i| j.indice = i+1} |
|
109 | @journals.each_with_index {|j,i| j.indice = i+1} | |
110 | @journals.reverse! if User.current.wants_comments_in_reverse_order? |
|
110 | @journals.reverse! if User.current.wants_comments_in_reverse_order? | |
111 | @changesets = @issue.changesets |
|
111 | @changesets = @issue.changesets.visible.all | |
112 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? |
|
112 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? | |
113 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
113 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
114 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
114 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
@@ -41,6 +41,9 class Changeset < ActiveRecord::Base | |||||
41 | validates_uniqueness_of :revision, :scope => :repository_id |
|
41 | validates_uniqueness_of :revision, :scope => :repository_id | |
42 | validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true |
|
42 | validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true | |
43 |
|
43 | |||
|
44 | named_scope :visible, lambda {|*args| { :include => {:repository => :project}, | |||
|
45 | :conditions => Project.allowed_to_condition(args.first || User.current, :view_changesets) } } | |||
|
46 | ||||
44 | def revision=(r) |
|
47 | def revision=(r) | |
45 | write_attribute :revision, (r.nil? ? nil : r.to_s) |
|
48 | write_attribute :revision, (r.nil? ? nil : r.to_s) | |
46 | end |
|
49 | end | |
@@ -90,13 +93,13 class Changeset < ActiveRecord::Base | |||||
90 | # find any issue ID in the comments |
|
93 | # find any issue ID in the comments | |
91 | target_issue_ids = [] |
|
94 | target_issue_ids = [] | |
92 | comments.scan(%r{([\s\(\[,-]|^)#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] } |
|
95 | comments.scan(%r{([\s\(\[,-]|^)#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] } | |
93 |
referenced_issues += |
|
96 | referenced_issues += find_referenced_issues_by_id(target_issue_ids) | |
94 | end |
|
97 | end | |
95 |
|
98 | |||
96 | comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match| |
|
99 | comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match| | |
97 | action = match[0] |
|
100 | action = match[0] | |
98 | target_issue_ids = match[1].scan(/\d+/) |
|
101 | target_issue_ids = match[1].scan(/\d+/) | |
99 |
target_issues = |
|
102 | target_issues = find_referenced_issues_by_id(target_issue_ids) | |
100 | if fix_status && fix_keywords.include?(action.downcase) |
|
103 | if fix_status && fix_keywords.include?(action.downcase) | |
101 | # update status of issues |
|
104 | # update status of issues | |
102 | logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug? |
|
105 | logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug? | |
@@ -148,6 +151,14 class Changeset < ActiveRecord::Base | |||||
148 |
|
151 | |||
149 | private |
|
152 | private | |
150 |
|
153 | |||
|
154 | # Finds issues that can be referenced by the commit message | |||
|
155 | # i.e. issues that belong to the repository project, a subproject or a parent project | |||
|
156 | def find_referenced_issues_by_id(ids) | |||
|
157 | Issue.find_all_by_id(ids, :include => :project).select {|issue| | |||
|
158 | project == issue.project || project.is_ancestor_of?(issue.project) || project.is_descendant_of?(issue.project) | |||
|
159 | } | |||
|
160 | end | |||
|
161 | ||||
151 | def split_comments |
|
162 | def split_comments | |
152 | comments =~ /\A(.+?)\r?\n(.*)$/m |
|
163 | comments =~ /\A(.+?)\r?\n(.*)$/m | |
153 | @short_comments = $1 || comments |
|
164 | @short_comments = $1 || comments |
@@ -73,7 +73,7 | |||||
73 |
|
73 | |||
74 | </div> |
|
74 | </div> | |
75 |
|
75 | |||
76 | <% if @changesets.any? && User.current.allowed_to?(:view_changesets, @project) %> |
|
76 | <% if @changesets.any? %> | |
77 | <div id="issue-changesets"> |
|
77 | <div id="issue-changesets"> | |
78 | <h3><%=l(:label_associated_revisions)%></h3> |
|
78 | <h3><%=l(:label_associated_revisions)%></h3> | |
79 | <%= render :partial => 'changesets', :locals => { :changesets => @changesets} %> |
|
79 | <%= render :partial => 'changesets', :locals => { :changesets => @changesets} %> |
@@ -74,6 +74,29 class ChangesetTest < ActiveSupport::TestCase | |||||
74 |
|
74 | |||
75 | assert_equal [1,2,3], c.issue_ids.sort |
|
75 | assert_equal [1,2,3], c.issue_ids.sort | |
76 | end |
|
76 | end | |
|
77 | ||||
|
78 | def test_commit_referencing_a_subproject_issue | |||
|
79 | c = Changeset.new(:repository => Project.find(1).repository, | |||
|
80 | :committed_on => Time.now, | |||
|
81 | :comments => 'refs #5, a subproject issue') | |||
|
82 | c.scan_comment_for_issue_ids | |||
|
83 | ||||
|
84 | assert_equal [5], c.issue_ids.sort | |||
|
85 | assert c.issues.first.project != c.project | |||
|
86 | end | |||
|
87 | ||||
|
88 | def test_commit_referencing_a_parent_project_issue | |||
|
89 | # repository of child project | |||
|
90 | r = Repository::Subversion.create!(:project => Project.find(3), :url => 'svn://localhost/test') | |||
|
91 | ||||
|
92 | c = Changeset.new(:repository => r, | |||
|
93 | :committed_on => Time.now, | |||
|
94 | :comments => 'refs #2, an issue of a parent project') | |||
|
95 | c.scan_comment_for_issue_ids | |||
|
96 | ||||
|
97 | assert_equal [2], c.issue_ids.sort | |||
|
98 | assert c.issues.first.project != c.project | |||
|
99 | end | |||
77 |
|
100 | |||
78 | def test_previous |
|
101 | def test_previous | |
79 | changeset = Changeset.find_by_revision('3') |
|
102 | changeset = Changeset.find_by_revision('3') |
General Comments 0
You need to be logged in to leave comments.
Login now