From d91c3d0e25e989cb1edd95e7932495f92292fce9 Mon Sep 17 00:00:00 2001 From: Mike Kruk Date: Sun, 25 Mar 2012 12:58:36 -0400 Subject: [PATCH 01/12] run update_issues on project after post_receive. Close issue if message contains "#d" --- app/models/project.rb | 15 +++++++++++++++ app/workers/post_receive.rb | 3 +++ 2 files changed, 18 insertions(+) diff --git a/app/models/project.rb b/app/models/project.rb index 8811176170e..638c0acc4ce 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -76,6 +76,21 @@ class Project < ActiveRecord::Base :author_id => data[:user_id] ) end + + def update_issues(oldrev, newrev, ref, author_key_id) + user = Key.find_by_identifier(author_key_id).user + commits = self.commits_between(oldrev, newrev) + commits.each do |commit| + commit.message.split(/(#[0-9]+)/m).each do |m| + if m =~ /(#([0-9]+))/m + begin + issue = self.issues.find($2) + issue.update_attribues(:closed => true, :author_id_of_changes => user.id) + end + end + end + end + end def update_merge_requests(oldrev, newrev, ref, author_key_id) return true unless ref =~ /heads/ diff --git a/app/workers/post_receive.rb b/app/workers/post_receive.rb index 28216ec33da..0fc10572111 100644 --- a/app/workers/post_receive.rb +++ b/app/workers/post_receive.rb @@ -14,6 +14,9 @@ class PostReceive # Close merged MR project.update_merge_requests(oldrev, newrev, ref, author_key_id) + # Close referenced Issues + project.update_issues(oldrev, newrev, ref, author_key_id) + # Execute web hooks project.execute_web_hooks(oldrev, newrev, ref, author_key_id) end -- GitLab From 1c839d462ba30297cd03713c20a0a90cca675f5d Mon Sep 17 00:00:00 2001 From: Mike Kruk Date: Sun, 25 Mar 2012 20:37:07 -0400 Subject: [PATCH 02/12] started spec for update_issues. referenced issues will need to be tracked, so lets stub this out in the model --- app/models/issue.rb | 8 +++++++- app/models/project.rb | 8 ++++---- spec/models/project_spec.rb | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 632e6537aad..2dc430bd65d 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -3,7 +3,9 @@ class Issue < ActiveRecord::Base belongs_to :author, :class_name => "User" belongs_to :assignee, :class_name => "User" has_many :notes, :as => :noteable, :dependent => :destroy - + + serialize :st_commits + attr_protected :author, :author_id, :project, :project_id attr_accessor :author_id_of_changes @@ -50,6 +52,10 @@ class Issue < ActiveRecord::Base def upvotes notes.select(&:upvote?).size end + + def commits + st_commits || [] + end end # == Schema Information # diff --git a/app/models/project.rb b/app/models/project.rb index 638c0acc4ce..59f67988b07 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -81,11 +81,11 @@ class Project < ActiveRecord::Base user = Key.find_by_identifier(author_key_id).user commits = self.commits_between(oldrev, newrev) commits.each do |commit| - commit.message.split(/(#[0-9]+)/m).each do |m| - if m =~ /(#([0-9]+))/m + commit.message.split(/(closes|fixes)\s?(#[0-9]+)/mi).each do |m| + if m =~ /(closes|fixes)\s?(#([0-9]+))/mi begin - issue = self.issues.find($2) - issue.update_attribues(:closed => true, :author_id_of_changes => user.id) + issue = self.issues.find($3) + issue.update_attributes(:closed => true, :author_id_of_changes => user.id) unless $1.empty? end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 1f8133e7ff7..0551725af31 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -188,6 +188,22 @@ describe Project do @merge_request.last_commit.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" end end + + describe :update_issues do + let(:project) { Factory :project } + + before do + @issue = Factory :issue, + :project => project, + :closed => false + @key = Factory :key, :user_id => project.owner.id + @commit = project.commit(ValidCommit::ID) + end + + it "should close issue if issue id is in commit message" do + + end + end end # == Schema Information # -- GitLab From 68c5a43b66a30471341754a37d9d7c952587ba40 Mon Sep 17 00:00:00 2001 From: Mike Kruk Date: Tue, 27 Mar 2012 10:34:48 -0400 Subject: [PATCH 03/12] create note with commit id as reference marker. Parse commit IDs with notes helper. --- app/helpers/notes_helper.rb | 23 +++++++++++++++++++++++ app/models/project.rb | 7 +++++++ app/views/notes/_show.html.haml | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 app/helpers/notes_helper.rb diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb new file mode 100644 index 00000000000..7395669ee82 --- /dev/null +++ b/app/helpers/notes_helper.rb @@ -0,0 +1,23 @@ +module NotesHelper + def note_with_commit_reference(project, note) + return '' unless note.note + out = '' + + if note.note =~ /^[0-9a-zA-Z]{6,52}$/ + begin + commit = project.commit(note.note) + issue_refs = commit.safe_message.scan(/#([0-9]+)/m).flatten + if issue_refs.include?(note.target.id) + out += link_to(commit.safe_message, project_commit_path(project,commit)) + else + out += link_to(note.note, project_commit_path(project,commit)) + end + rescue + out += note.note + end + else + out = note.note + end + preserve out + end +end \ No newline at end of file diff --git a/app/models/project.rb b/app/models/project.rb index 59f67988b07..ce0809b9ded 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -85,11 +85,14 @@ class Project < ActiveRecord::Base if m =~ /(closes|fixes)\s?(#([0-9]+))/mi begin issue = self.issues.find($3) + note = self.build_issue_commit_reference(commit,issue) + note.save issue.update_attributes(:closed => true, :author_id_of_changes => user.id) unless $1.empty? end end end end + true end def update_merge_requests(oldrev, newrev, ref, author_key_id) @@ -188,6 +191,10 @@ class Project < ActiveRecord::Base def commit_line_notes(commit) notes.where(:noteable_id => commit.id, :noteable_type => "Commit").where("line_code is not null") end + + def build_issue_commit_reference(commit,issue) + notes.new(:noteable => issue, :author => commit.author, :note => commit.id) + end def has_commits? !!commit diff --git a/app/views/notes/_show.html.haml b/app/views/notes/_show.html.haml index 6da1d5904bf..2dd9d11e33c 100644 --- a/app/views/notes/_show.html.haml +++ b/app/views/notes/_show.html.haml @@ -9,7 +9,7 @@ %strong= link_to "Remove", [@project, note], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "cred delete-note btn small" %div.note-title - = markdown(note.note) + = markdown(note_with_commit_reference(@project, note)) - if note.attachment.url .right %span.file -- GitLab From 17ebc57fc2d8f35b34bce5d3ac5832a9e3b63c8d Mon Sep 17 00:00:00 2001 From: Mike Kruk Date: Tue, 27 Mar 2012 11:40:14 -0400 Subject: [PATCH 04/12] parse pushed commits properly to find issue references, and close issues that are prefixed with closes or fixes. properly parse commit hashes from issue notes. --- app/helpers/notes_helper.rb | 23 +++++++++++------------ app/models/project.rb | 17 ++++++++--------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index 7395669ee82..6cee68bfb58 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -3,20 +3,19 @@ module NotesHelper return '' unless note.note out = '' - if note.note =~ /^[0-9a-zA-Z]{6,52}$/ - begin - commit = project.commit(note.note) - issue_refs = commit.safe_message.scan(/#([0-9]+)/m).flatten - if issue_refs.include?(note.target.id) - out += link_to(commit.safe_message, project_commit_path(project,commit)) - else - out += link_to(note.note, project_commit_path(project,commit)) + note.note.split(/([0-9a-zA-Z]{6,52})/).each do |m| + if m =~ /^[0-9a-zA-Z]{6,52}$/ + begin + commit = project.commit(m) + issue_refs = commit.safe_message.scan(/#([0-9]+)/m).flatten + link_message = issue_refs.include?(note.target.id.to_s)? commit.safe_message : m + out += "[#{link_message}](#{project_commit_path(project,:id => commit.id)})" + rescue + out += m end - rescue - out += note.note + else + out += m end - else - out = note.note end preserve out end diff --git a/app/models/project.rb b/app/models/project.rb index ce0809b9ded..2712d1cb126 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -81,14 +81,13 @@ class Project < ActiveRecord::Base user = Key.find_by_identifier(author_key_id).user commits = self.commits_between(oldrev, newrev) commits.each do |commit| - commit.message.split(/(closes|fixes)\s?(#[0-9]+)/mi).each do |m| - if m =~ /(closes|fixes)\s?(#([0-9]+))/mi - begin - issue = self.issues.find($3) - note = self.build_issue_commit_reference(commit,issue) - note.save - issue.update_attributes(:closed => true, :author_id_of_changes => user.id) unless $1.empty? - end + commit.message.scan(/(closes|fixes)?\s#([0-9]+)/mi).each do |m| + begin + issue = self.issues.find(m.last) + note = self.build_issue_commit_reference(commit,issue) + note.author = user + note.save + issue.update_attributes(:closed => true, :author_id_of_changes => user.id) unless m.first.nil? end end end @@ -193,7 +192,7 @@ class Project < ActiveRecord::Base end def build_issue_commit_reference(commit,issue) - notes.new(:noteable => issue, :author => commit.author, :note => commit.id) + notes.new(:noteable => issue, :note => commit.id) end def has_commits? -- GitLab From a28acf556f9cc333b2ae9877ceb5e1ba1123b490 Mon Sep 17 00:00:00 2001 From: Mike Kruk Date: Tue, 27 Mar 2012 14:47:11 -0400 Subject: [PATCH 05/12] gah. I can't figure out how to run tets. this at least gets things setup. --- spec/models/project_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 0551725af31..649e095b871 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -201,7 +201,8 @@ describe Project do end it "should close issue if issue id is in commit message" do - + @commit.message = "closes ##{@issue.id}" + @issue.closed.should be_true end end end -- GitLab From 0dbd14c84d534297f9537280ff82fc959c3dd1d6 Mon Sep 17 00:00:00 2001 From: Mike Kruk Date: Sat, 31 Mar 2012 15:48:40 -0400 Subject: [PATCH 06/12] Add commit_id to notes to be referenced by. --- db/migrate/20120331034342_add_commit_id_to_note.rb | 8 ++++++++ db/schema.rb | 1 + 2 files changed, 9 insertions(+) create mode 100644 db/migrate/20120331034342_add_commit_id_to_note.rb diff --git a/db/migrate/20120331034342_add_commit_id_to_note.rb b/db/migrate/20120331034342_add_commit_id_to_note.rb new file mode 100644 index 00000000000..01abcba0939 --- /dev/null +++ b/db/migrate/20120331034342_add_commit_id_to_note.rb @@ -0,0 +1,8 @@ +class AddCommitIdToNote < ActiveRecord::Migration + def up + add_column :notes, :commit_id, :string + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index c76fd9b5d98..04a72c58199 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -77,6 +77,7 @@ ActiveRecord::Schema.define(:version => 20120323221339) do t.integer "project_id" t.string "attachment" t.string "line_code" + t.string "commit_id" end add_index "notes", ["noteable_id"], :name => "index_notes_on_noteable_id" -- GitLab From cf68cb117a0ff1f67336b41bfc178d934f99a564 Mon Sep 17 00:00:00 2001 From: Mike Kruk Date: Sat, 31 Mar 2012 16:01:36 -0400 Subject: [PATCH 07/12] Only add commit references to issues if that commit wasn't already added as a reference. Added commit_id to creating reference notes. --- app/models/note.rb | 2 ++ app/models/project.rb | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/note.rb b/app/models/note.rb index cee726ea0e5..85e7f0893ac 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -35,6 +35,7 @@ class Note < ActiveRecord::Base scope :fresh, order("created_at DESC") scope :inc_author_project, includes(:project, :author) scope :inc_author, includes(:author) + scope :from_commit, includes(:commit_id) mount_uploader :attachment, AttachmentUploader @@ -108,5 +109,6 @@ end # project_id :integer # attachment :string(255) # line_code :string(255) +# commit_id :string(255) # diff --git a/app/models/project.rb b/app/models/project.rb index 2712d1cb126..8051193f873 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -84,9 +84,11 @@ class Project < ActiveRecord::Base commit.message.scan(/(closes|fixes)?\s#([0-9]+)/mi).each do |m| begin issue = self.issues.find(m.last) - note = self.build_issue_commit_reference(commit,issue) - note.author = user - note.save + unless issue.notes.from_commit.where(:commit_id => commit.id) do + note = self.build_issue_commit_reference(commit,issue) + note.author = user + note.save + end issue.update_attributes(:closed => true, :author_id_of_changes => user.id) unless m.first.nil? end end @@ -192,7 +194,7 @@ class Project < ActiveRecord::Base end def build_issue_commit_reference(commit,issue) - notes.new(:noteable => issue, :note => commit.id) + notes.new(:noteable => issue, :note => commit.safe_message, :commit_id => commit.id) end def has_commits? -- GitLab From aa7c084126e20dac65542f5f81a796f70374af41 Mon Sep 17 00:00:00 2001 From: Mike Kruk Date: Sat, 31 Mar 2012 16:06:52 -0400 Subject: [PATCH 08/12] don't need to mess with issue model. --- app/models/issue.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 2dc430bd65d..f1508225366 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -3,9 +3,7 @@ class Issue < ActiveRecord::Base belongs_to :author, :class_name => "User" belongs_to :assignee, :class_name => "User" has_many :notes, :as => :noteable, :dependent => :destroy - - serialize :st_commits - + attr_protected :author, :author_id, :project, :project_id attr_accessor :author_id_of_changes @@ -53,9 +51,6 @@ class Issue < ActiveRecord::Base notes.select(&:upvote?).size end - def commits - st_commits || [] - end end # == Schema Information # -- GitLab From 0449c1920ce23ac81537509f0364679ed5178c9b Mon Sep 17 00:00:00 2001 From: Mike Kruk Date: Sat, 31 Mar 2012 16:13:11 -0400 Subject: [PATCH 09/12] reference commit ids in notes. Note message should be the commit message linking to the commit. --- app/helpers/notes_helper.rb | 4 +--- app/models/project.rb | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index 6cee68bfb58..28a7f38b9f8 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -7,9 +7,7 @@ module NotesHelper if m =~ /^[0-9a-zA-Z]{6,52}$/ begin commit = project.commit(m) - issue_refs = commit.safe_message.scan(/#([0-9]+)/m).flatten - link_message = issue_refs.include?(note.target.id.to_s)? commit.safe_message : m - out += "[#{link_message}](#{project_commit_path(project,:id => commit.id)})" + out += "[#{m}](#{project_commit_path(project,:id => commit.id)})" rescue out += m end diff --git a/app/models/project.rb b/app/models/project.rb index 8051193f873..f034747a2cd 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -194,7 +194,8 @@ class Project < ActiveRecord::Base end def build_issue_commit_reference(commit,issue) - notes.new(:noteable => issue, :note => commit.safe_message, :commit_id => commit.id) + message = "[#{commit.safe_message}](#{project_commit_path(self,:id => commit.id)})" + notes.new(:noteable => issue, :note => message, :commit_id => commit.id) end def has_commits? -- GitLab From e02995179bad903314055e9ff4713aacab351aa7 Mon Sep 17 00:00:00 2001 From: Mike Kruk Date: Sat, 31 Mar 2012 16:30:52 -0400 Subject: [PATCH 10/12] allow for referenced commits in an issue to look different. --- app/models/note.rb | 4 ++++ app/models/project.rb | 5 ++--- app/views/notes/_notes_list.html.haml | 5 ++++- app/views/notes/_show_from_commit.html.haml | 13 +++++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 app/views/notes/_show_from_commit.html.haml diff --git a/app/models/note.rb b/app/models/note.rb index 85e7f0893ac..43e65be7961 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -88,6 +88,10 @@ class Note < ActiveRecord::Base rescue nil end + + def from_commit? + !commit_id.nil? + end # Returns true if this is an upvote note, # otherwise false is returned diff --git a/app/models/project.rb b/app/models/project.rb index f034747a2cd..8a5dd7175a4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -84,7 +84,7 @@ class Project < ActiveRecord::Base commit.message.scan(/(closes|fixes)?\s#([0-9]+)/mi).each do |m| begin issue = self.issues.find(m.last) - unless issue.notes.from_commit.where(:commit_id => commit.id) do + unless issue.notes.from_commit.where(:commit_id => commit.id).any? note = self.build_issue_commit_reference(commit,issue) note.author = user note.save @@ -194,8 +194,7 @@ class Project < ActiveRecord::Base end def build_issue_commit_reference(commit,issue) - message = "[#{commit.safe_message}](#{project_commit_path(self,:id => commit.id)})" - notes.new(:noteable => issue, :note => message, :commit_id => commit.id) + notes.new(:noteable => issue, :note => commit.safe_message, :commit_id => commit.id) end def has_commits? diff --git a/app/views/notes/_notes_list.html.haml b/app/views/notes/_notes_list.html.haml index 1e4a6bb2b2f..94d07fadc97 100644 --- a/app/views/notes/_notes_list.html.haml +++ b/app/views/notes/_notes_list.html.haml @@ -1,4 +1,7 @@ - @notes.each do |note| - next unless note.author - = render :partial => "notes/show", :locals => {:note => note} + - if note.from_commit? + = render :partial => "notes/show_from_commit", :locals => {:note => note} + - else + = render :partial => "notes/show", :locals => {:note => note} diff --git a/app/views/notes/_show_from_commit.html.haml b/app/views/notes/_show_from_commit.html.haml new file mode 100644 index 00000000000..b3ffa740068 --- /dev/null +++ b/app/views/notes/_show_from_commit.html.haml @@ -0,0 +1,13 @@ +%li{:id => dom_id(note), :class => "note"} += image_tag gravatar_icon(note.author.email), :class => "left", :width => 40, :style => "padding-right:5px;" +%div.note-author + %strong + = note.author_name + referenced this issue from a commit + %cite.cgray + = time_ago_in_words(note.updated_at) + ago +%div.note-title + p + = link_to(markdown(note.note), project_commit_path(@project,:id => note.commit_id)) +.clear \ No newline at end of file -- GitLab From 4848231f9be1fa64fc1f94ac1d959ed29b830d90 Mon Sep 17 00:00:00 2001 From: Mike Kruk Date: Sat, 31 Mar 2012 17:41:24 -0400 Subject: [PATCH 11/12] cleaned up show_from_commit view --- app/views/notes/_show_from_commit.html.haml | 22 ++++++++++----------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/views/notes/_show_from_commit.html.haml b/app/views/notes/_show_from_commit.html.haml index b3ffa740068..2e455a0ecfe 100644 --- a/app/views/notes/_show_from_commit.html.haml +++ b/app/views/notes/_show_from_commit.html.haml @@ -1,13 +1,11 @@ %li{:id => dom_id(note), :class => "note"} -= image_tag gravatar_icon(note.author.email), :class => "left", :width => 40, :style => "padding-right:5px;" -%div.note-author - %strong - = note.author_name - referenced this issue from a commit - %cite.cgray - = time_ago_in_words(note.updated_at) - ago -%div.note-title - p - = link_to(markdown(note.note), project_commit_path(@project,:id => note.commit_id)) -.clear \ No newline at end of file + = image_tag gravatar_icon(note.author.email), :class => "left", :width => 40, :style => "padding-right:5px;" + %div.note-author + %strong= note.author_name + referenced this issue from a commit + %cite.cgray + = time_ago_in_words(note.updated_at) + ago + %div.note-title + = markdown("[#{note.note}](#{project_commit_path(@project,:id => note.commit_id)})") + .clear \ No newline at end of file -- GitLab From 5bc2ae0ec0596d4bfa92755be72734bde66c4c0c Mon Sep 17 00:00:00 2001 From: Mike Kruk Date: Sat, 31 Mar 2012 22:23:47 -0400 Subject: [PATCH 12/12] change commit_id to more abstract reference association. Allow reference partial to allow for things other than issues. --- app/helpers/notes_helper.rb | 8 ++++++++ app/models/note.rb | 12 +++++++++--- app/models/project.rb | 4 ++-- app/views/notes/_notes_list.html.haml | 4 ++-- ...om_commit.html.haml => _reference_show.html.haml} | 7 +++++-- db/migrate/20120331034342_add_commit_id_to_note.rb | 8 -------- db/migrate/20120331034342_add_references_to_note.rb | 9 +++++++++ db/schema.rb | 3 ++- 8 files changed, 37 insertions(+), 18 deletions(-) rename app/views/notes/{_show_from_commit.html.haml => _reference_show.html.haml} (63%) delete mode 100644 db/migrate/20120331034342_add_commit_id_to_note.rb create mode 100644 db/migrate/20120331034342_add_references_to_note.rb diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index 28a7f38b9f8..57649693e7f 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -17,4 +17,12 @@ module NotesHelper end preserve out end + + def build_reference_link(project, note) + return '' unless note.reference? + case note.reference_type + when "Commit" + then project_commit_path(project,:id => note.reference_id) + end + end end \ No newline at end of file diff --git a/app/models/note.rb b/app/models/note.rb index 43e65be7961..4d9192a04d2 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -4,6 +4,7 @@ require 'file_size_validator' class Note < ActiveRecord::Base belongs_to :project belongs_to :noteable, :polymorphic => true + belongs_to :reference, :polymorphic => true belongs_to :author, :class_name => "User" @@ -35,7 +36,7 @@ class Note < ActiveRecord::Base scope :fresh, order("created_at DESC") scope :inc_author_project, includes(:project, :author) scope :inc_author, includes(:author) - scope :from_commit, includes(:commit_id) + scope :from_commit, where(:reference_type => "Commit") mount_uploader :attachment, AttachmentUploader @@ -89,8 +90,12 @@ class Note < ActiveRecord::Base nil end + def reference? + !reference_type.nil? && !reference_id.nil? + end + def from_commit? - !commit_id.nil? + reference? && reference_type == "Commit" end # Returns true if this is an upvote note, @@ -113,6 +118,7 @@ end # project_id :integer # attachment :string(255) # line_code :string(255) -# commit_id :string(255) +# reference_id :string(255) +# reference_type:string(255) # diff --git a/app/models/project.rb b/app/models/project.rb index 8a5dd7175a4..8dc005a03d6 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -84,7 +84,7 @@ class Project < ActiveRecord::Base commit.message.scan(/(closes|fixes)?\s#([0-9]+)/mi).each do |m| begin issue = self.issues.find(m.last) - unless issue.notes.from_commit.where(:commit_id => commit.id).any? + unless issue.notes.from_commit.where(:reference_id => commit.id).any? note = self.build_issue_commit_reference(commit,issue) note.author = user note.save @@ -194,7 +194,7 @@ class Project < ActiveRecord::Base end def build_issue_commit_reference(commit,issue) - notes.new(:noteable => issue, :note => commit.safe_message, :commit_id => commit.id) + notes.new(:noteable => issue, :note => commit.safe_message, :reference_type => "Commit", :reference_id => commit.id) end def has_commits? diff --git a/app/views/notes/_notes_list.html.haml b/app/views/notes/_notes_list.html.haml index 94d07fadc97..6deec24748f 100644 --- a/app/views/notes/_notes_list.html.haml +++ b/app/views/notes/_notes_list.html.haml @@ -1,7 +1,7 @@ - @notes.each do |note| - next unless note.author - - if note.from_commit? - = render :partial => "notes/show_from_commit", :locals => {:note => note} + - if note.reference? + = render :partial => "notes/reference_show", :locals => {:note => note} - else = render :partial => "notes/show", :locals => {:note => note} diff --git a/app/views/notes/_show_from_commit.html.haml b/app/views/notes/_reference_show.html.haml similarity index 63% rename from app/views/notes/_show_from_commit.html.haml rename to app/views/notes/_reference_show.html.haml index 2e455a0ecfe..69c84ac9c3b 100644 --- a/app/views/notes/_show_from_commit.html.haml +++ b/app/views/notes/_reference_show.html.haml @@ -2,10 +2,13 @@ = image_tag gravatar_icon(note.author.email), :class => "left", :width => 40, :style => "padding-right:5px;" %div.note-author %strong= note.author_name - referenced this issue from a commit + referenced this + = note.noteable_type.downcase + from a + = note.reference_type.downcase %cite.cgray = time_ago_in_words(note.updated_at) ago %div.note-title - = markdown("[#{note.note}](#{project_commit_path(@project,:id => note.commit_id)})") + = markdown("[#{note.note}](#{build_reference_link(@project, note)})") .clear \ No newline at end of file diff --git a/db/migrate/20120331034342_add_commit_id_to_note.rb b/db/migrate/20120331034342_add_commit_id_to_note.rb deleted file mode 100644 index 01abcba0939..00000000000 --- a/db/migrate/20120331034342_add_commit_id_to_note.rb +++ /dev/null @@ -1,8 +0,0 @@ -class AddCommitIdToNote < ActiveRecord::Migration - def up - add_column :notes, :commit_id, :string - end - - def down - end -end diff --git a/db/migrate/20120331034342_add_references_to_note.rb b/db/migrate/20120331034342_add_references_to_note.rb new file mode 100644 index 00000000000..112ec2af011 --- /dev/null +++ b/db/migrate/20120331034342_add_references_to_note.rb @@ -0,0 +1,9 @@ +class AddReferencesToNote < ActiveRecord::Migration + def up + add_column :notes, :reference_id, :string + add_column :notes, :reference_type, :string + end + + def down + end +end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 04a72c58199..329f385cc29 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -77,7 +77,8 @@ ActiveRecord::Schema.define(:version => 20120323221339) do t.integer "project_id" t.string "attachment" t.string "line_code" - t.string "commit_id" + t.string "reference_id" + t.string "reference_type" end add_index "notes", ["noteable_id"], :name => "index_notes_on_noteable_id" -- GitLab