1.添加代码评审(CodeReview)插件

2.添加代码评审插件使用文档
GitlabVersion
nwb 11 years ago
parent 9e0ae72ab7
commit ae3457e68b

@ -185,4 +185,5 @@ DEPENDENCIES
sass-rails (~> 3.2.3)
seems_rateable!
shoulda (> 3.3.2)
therubyracer
uglifier (>= 1.0.3)

@ -120,7 +120,7 @@ class AttachmentsController < ApplicationController
end
if @attachment.container
# Make sure association callbacks are called
@attachment.container.attachments.delete(@attachment)
@attachment.container.def attachments.delete(@attachment)
else
@attachment.destroy
end

@ -568,7 +568,7 @@ class RepositoriesController < ApplicationController
project = Project.find(params[:id])
if !User.current.member_of?(project)
if project.hidden_repo
render_403
#render_403
end
end
rescue ActiveRecord::RecordNotFound

@ -174,6 +174,58 @@ ActiveRecord::Schema.define(:version => 20140618020535) do
add_index "changesets_issues", ["changeset_id", "issue_id"], :name => "changesets_issues_ids", :unique => true
create_table "code_review_assignments", :force => true do |t|
t.integer "issue_id"
t.integer "change_id"
t.integer "attachment_id"
t.string "file_path"
t.string "rev"
t.string "rev_to"
t.string "action_type"
t.integer "changeset_id"
end
create_table "code_review_project_settings", :force => true do |t|
t.integer "project_id"
t.integer "tracker_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "updated_by"
t.boolean "hide_code_review_tab", :default => false
t.integer "auto_relation", :default => 1
t.integer "assignment_tracker_id"
t.text "auto_assign"
t.integer "lock_version", :default => 0, :null => false
t.boolean "tracker_in_review_dialog", :default => false
end
create_table "code_review_user_settings", :force => true do |t|
t.integer "user_id", :default => 0, :null => false
t.integer "mail_notification", :default => 0, :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "code_reviews", :force => true do |t|
t.integer "project_id"
t.integer "change_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "line"
t.integer "updated_by_id"
t.integer "lock_version", :default => 0, :null => false
t.integer "status_changed_from"
t.integer "status_changed_to"
t.integer "issue_id"
t.string "action_type"
t.string "file_path"
t.string "rev"
t.string "rev_to"
t.integer "attachment_id"
t.integer "file_count", :default => 0, :null => false
t.boolean "diff_all"
end
create_table "comments", :force => true do |t|
t.string "commented_type", :limit => 30, :default => "", :null => false
t.integer "commented_id", :default => 0, :null => false

File diff suppressed because it is too large Load Diff

@ -0,0 +1,35 @@
= Redmine Code Review Plugin
This is a plugin for Redmine which lets you annotate source code within the repository browser.
http://www.r-labs.org/wiki/r-labs/Code_Review
=== Plugin installation
1. Copy the plugin directory into the plugins directory
2. Migrate plugin:
rake redmine:plugins:migrate RAILS_ENV=production
3. Start Redmine
4. Add code review module into your project.
5. Go to code review setting tab in the project setting page and select tracker.
=== Language contributors
* de.yml - Michael Diederich, Sebastian Bernhard
* fr.yml - Thomas M
* hu.yml - Péter Major
* ko.yml - Ki-yong Kim, Ki Won Kim
* nl.yml - Stefan Verstege
* pt-br.yml - Alessandro Hecht
* zh.yml - Marshall Wu
* zh-tw.yml - Andrew Liu
* ru.yml - Mykhaylo Sorochan
* sk.yml - Milan Freml
* es.yml - Ignacio Carrera
* pl.yml - Rafal Grzymkowski
* sv.yml - André Jonsson
* bg.yml - Ivan Cenov, jwalkerbg

@ -0,0 +1,119 @@
# Code Review plugin for Redmine
# Copyright (C) 2010 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class CodeReviewSettingsController < ApplicationController
unloadable
layout 'base'
menu_item :code_review
include CodeReviewAutoAssignSettings
before_filter :find_project, :authorize, :find_user
def update
begin
@setting = CodeReviewProjectSetting.find_or_create(@project)
@setting.safe_attributes = params[:setting]
@setting.updated_by = @user.id
params[:auto_assign][:filters] = params[:auto_assign][:filters].values unless params[:auto_assign][:filters].blank?
@setting.auto_assign_settings = params[:auto_assign].to_yaml
@setting.save!
flash[:notice] = l(:notice_successful_update)
rescue ActiveRecord::StaleObjectError
# Optimistic locking exception
flash[:error] = l(:notice_locking_conflict)
end
redirect_to :controller => 'projects', :action => "settings", :id => @project, :tab => 'code_review'
end
def add_filter
setting = CodeReviewProjectSetting.find_or_create(@project)
@auto_assign = setting.auto_assign_settings
filters = params[:auto_assign][:filters].values unless params[:auto_assign][:filters].blank?
filters = [] unless filters
filters << params[:auto_assign_add_filter]
@auto_assign.filters = filters.collect{|f|
filter = AssignmentFilter.new
filter.attributes = f
filter
}
@auto_assign.filter_enabled = true
render :partial => "code_review_settings/filters"
end
def edit_filter
setting = CodeReviewProjectSetting.find_or_create(@project)
@auto_assign = setting.auto_assign_settings
num = params[:num].to_i
filters = params[:auto_assign][:filters].values unless params[:auto_assign][:filters].blank?
filters = [] unless filters
i = 0
@auto_assign.filters = filters.collect{|f|
filter = AssignmentFilter.new
if i == num
filter.attributes = params[:auto_assign_edit_filter][num.to_s]
else
filter.attributes = f
end
i = i + 1
filter
}
render :partial => "code_review_settings/filters"
end
def sort
setting = CodeReviewProjectSetting.find_or_create(@project)
@auto_assign = setting.auto_assign_settings
filters = params[:auto_assign][:filters].values unless params[:auto_assign][:filters].blank?
filters = [] unless filters
num = params[:auto_assign_filter][:num].to_i
move_to = params[:auto_assign_filter][:move_to]
if move_to == 'highest'
filters[num][:order] = 0
elsif move_to == 'higher'
filters[num][:order] = filters[num][:order].to_i - 15
elsif move_to == 'lower'
filters[num][:order] = filters[num][:order].to_i + 15
elsif move_to == 'lowest'
filters[num][:order] = 999999999
end
@auto_assign.filters = filters.collect{|f|
filter = AssignmentFilter.new
filter.attributes = f
filter
}
render :partial => "code_review_settings/filters"
end
private
def find_project
# @project variable must be set before calling the authorize filter
@project = Project.find(params[:id])
end
def find_user
@user = User.current
end
end

@ -0,0 +1,37 @@
# Code Review plugin for Redmine
# Copyright (C) 2009-2011 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module CodeReviewHelper
unloadable
def show_assignments(assignments, project, options = {})
html = "#{l(:review_assignments)}:"
assignments.each do |assignment|
issue = assignment.issue
html << link_to("##{issue.id} ", {:controller => 'issues', :action => 'show', :id => issue.id},
:class => issue.css_classes, :title => "#{issue}(#{issue.status})")
end if assignments
link = link_to(l(:button_add), {:controller => 'code_review',
:action => 'assign', :id=>project, :action_type => options[:action_type],
:rev => options[:rev], :rev_to => options[:rev_to], :path => options[:path],
:change_id => options[:change_id], :attachment_id => options[:attachment_id],
:changeset_id => options[:changeset_id]}, :class => 'icon icon-add')
html << link if link
html
end
end

@ -0,0 +1,175 @@
# Code Review plugin for Redmine
# Copyright (C) 2009-2012 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class CodeReview < ActiveRecord::Base
include Redmine::SafeAttributes
unloadable
belongs_to :project
belongs_to :change
belongs_to :issue
belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_id'
belongs_to :attachment
validates_presence_of :project_id, :user_id, :updated_by_id, :issue,
:subject, :action_type, :line
STATUS_OPEN = 0
STATUS_CLOSED = 1
safe_attributes 'change_id', 'subject', 'line', 'parent_id', 'comment', 'status_id'
def before_create
issue = Issue.new unless issue
end
def is_closed?
issue.closed?
#self.root.status == STATUS_CLOSED
end
def close
issue.status = IssueStatus.find(5)
#self.root.status = STATUS_CLOSED
end
def reopen
issue.status = IssueStatus.find(1)
#self.root.status = STATUS_OPEN
end
def committer
return changeset.author if changeset
end
def path
begin
return file_path if file_path
return @path if @path
if attachment_id
@path = attachment.filename
return @path
end
repository = changeset.repository
url = repository.url
root_url = repository.root_url
if (url == nil || root_url == nil)
@path = change.path
return @path
end
rootpath = url[root_url.length, url.length - root_url.length]
if rootpath == '/' || rootpath.blank?
@path = change.path
else
@path = change.path[rootpath.length, change.path.length - rootpath.length]
end
rescue => ex
return ex.to_s
end
end
def revision
return rev if rev
changeset.revision if changeset
end
def changeset
@changeset ||= change.changeset if change
end
def repository
@repository ||= changeset.repository if changeset
end
def repository_identifier
return nil unless repository
@repository_identifier ||= repository.identifier_param
end
def comment=(str)
issue.description = str if issue
end
def comment
issue.description if issue
end
def before_save
issue.project_id = project_id unless issue.project_id
end
def validate
unless issue.validate
false
end
end
def user=(u)
issue.author = u
end
def user_id=(id)
issue.author_id = id
end
def user_id
issue.author_id
end
def user
issue.author if issue
end
def subject=(s)
issue.subject = s
end
def subject
issue.subject
end
def parent_id= (p)
issue.parent_issue_id = p
end
def parent_id
issue.parent_issue_id
end
def status_id=(s)
issue.status_id = s
end
def status_id
issue.status_id
end
def open_assignment_issues(user_id)
issues = []
assignments = []
assignments = change.code_review_assignments if change
assignments = assignments + changeset.code_review_assignments if changeset
assignments = assignments + attachment.code_review_assignments if attachment
assignments.each {|assignment|
unless assignment.is_closed?
issues << assignment.issue if user_id == assignment.issue.assigned_to_id
end
}
issues
end
end

@ -0,0 +1,80 @@
# Code Review plugin for Redmine
# Copyright (C) 2010-2011 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class CodeReviewAssignment < ActiveRecord::Base
unloadable
belongs_to :issue
belongs_to :change
belongs_to :changeset
belongs_to :attachment
validates_presence_of :issue_id
def is_closed?
issue.closed?
end
def path
file_path
end
def revision
return rev if rev
changeset.revision if changeset
end
def repository
@repository ||= change.changeset.repository if change
@repository ||= changeset.repository if changeset
@repository
end
def repository_identifier
return nil unless repository
@repository_identifier ||= repository.identifier_param if repository.respond_to?("identifier_param")
end
def self.create_with_changeset(changeset)
project = changeset.project
setting = CodeReviewProjectSetting.find_or_create(project)
auto_assign = setting.auto_assign_settings
assignment = CodeReviewAssignment.new
issue = Issue.new
issue.subject = auto_assign.subject
issue.subject = l(:code_review_requrest) if issue.subject.blank?
issue.subject = issue.subject.sub("$REV" , changeset.revision)
issue.subject = issue.subject.sub("$COMMENTS" , changeset.comments.split(//u)[0..60].join) unless changeset.comments.blank?
issue.tracker_id = setting.assignment_tracker_id
issue.project = project
issue.author = User.find(auto_assign.author_id)
issue.assigned_to_id = auto_assign.select_assign_to(project, changeset.user)
issue.description = auto_assign.description
issue.description = issue.description.sub("$REV" , changeset.revision) unless issue.description.blank?
issue.description = issue.description.sub("$COMMENTS" , changeset.comments) unless changeset.comments.blank?
issue.save!
assignment.issue_id = issue.id
assignment.changeset_id = changeset.id
assignment.save!
assignment
end
def diff_all
path.blank?
end
end

@ -0,0 +1,77 @@
# Code Review plugin for Redmine
# Copyright (C) 2009-2011 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class CodeReviewProjectSetting < ActiveRecord::Base
unloadable
include Redmine::SafeAttributes
include CodeReviewAutoAssignSettings
belongs_to :project
belongs_to :tracker
belongs_to :assignment_tracker, :class_name => 'Tracker'
validates_presence_of :project_id
validates_presence_of :tracker_id
validates_presence_of :assignment_tracker_id
before_save :set_assignment_settings
safe_attributes 'tracker_id', 'assignment_tracker_id', 'hide_code_review_tab', 'auto_relation', 'tracker_in_review_dialog'
AUTORELATION_TYPE_NONE = 0
AUTORELATION_TYPE_RELATES = 1
AUTORELATION_TYPE_BLOCKS = 2
def self.find_or_create(project)
setting = CodeReviewProjectSetting.find_by_project_id(project.id)
unless setting
setting = CodeReviewProjectSetting.new
setting.project_id = project.id
return setting if project.trackers.length == 0
setting.tracker = project.trackers[0]
setting.assignment_tracker = project.trackers[0]
setting.save!
end
setting
end
def auto_assign_settings
@auto_assign_settings ||= AutoAssignSettings.load(auto_assign)
end
def auto_assign_settings=(settings)
@auto_assign_settings = settings
end
def issue_relation_type
return IssueRelation::TYPE_RELATES if auto_relation == CodeReviewProjectSetting::AUTORELATION_TYPE_RELATES
return IssueRelation::TYPE_BLOCKS if auto_relation == CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS
return nil
end
def auto_relation?
issue_relation_type != nil
end
private
def set_assignment_settings
if auto_assign_settings
self.auto_assign = auto_assign_settings.to_s
else
self.auto_assign = nil
end
end
end

@ -0,0 +1,50 @@
# Code Review plugin for Redmine
# Copyright (C) 2011 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class CodeReviewUserSetting < ActiveRecord::Base
unloadable
belongs_to :user
validates_presence_of :user_id
validates_presence_of :mail_notification
validates_uniqueness_of :user_id
NOTIFCIATION_NONE = 0
NOTIFICATION_INVOLVED_IN = 1
NOTIFICATION_ALL = 2
def CodeReviewUserSetting.find_or_create(uid)
setting = CodeReviewUserSetting.find_by_user_id(uid)
return setting if setting
setting = CodeReviewUserSetting.new
setting.user_id = uid
setting.mail_notification = NOTIFICATION_INVOLVED_IN
setting.save
return setting
end
def mail_notification_none?
mail_notification == NOTIFCIATION_NONE
end
def mail_notification_involved_in?
mail_notification == NOTIFICATION_INVOLVED_IN
end
def mail_notification_all?
mail_notification == NOTIFICATION_ALL
end
end

@ -0,0 +1,122 @@
# Code Review plugin for Redmine
# Copyright (C) 2009 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class ReviewMailer < Mailer
def review_add(project, review)
redmine_headers 'Project' => review.project.identifier,
'Review-Id' => review.id,
'Review-Author' => review.user.login
recipients get_mail_addresses(review)
subject "[#{review.project.name} - #{l(:label_review_new)} - #{l(:label_review)}##{review.id}] "
review_url = url_for(:controller => 'code_review', :action => 'show', :id => project, :review_id => review.id)
body :review => review, :review_url => review_url
return if (l(:this_is_checking_for_before_rails_2_2_2) == 'this_is_checking_for_before_rails_2_2_2')
# 何故かrails 2.2 以後は以下の処理が必要
content_type "multipart/alternative"
part "text/plain" do |p|
p.body = render_message("review_add.text.plain.erb", :body => body, :review=>review, :review_url => review_url)
end
part "text/html" do |p|
p.body = render_message("review_add.text.html.erb", :body => body, :review=>review, :review_url => review_url)
end
end
def review_reply(project, review)
redmine_headers 'Project' => review.project.identifier,
'Review-Id' => review.id,
'Review-Author' => review.user.login
recipients recipients get_mail_addresses(review)
subject "[#{review.project.name} - Updated - #{l(:label_review)}##{review.root.id}] "
review_url = url_for(:controller => 'code_review', :action => 'show', :id => project, :review_id => review.root.id)
body :review => review, :review_url => review_url
return if (l(:this_is_checking_for_before_rails_2_2_2) == 'this_is_checking_for_before_rails_2_2_2')
# 何故かrails 2.2 以後は以下の処理が必要
content_type "multipart/alternative"
part "text/plain" do |p|
p.body = render_message("review_reply.text.plain.erb", :body => body, :review=>review, :review_url => review_url)
end
part "text/html" do |p|
p.body = render_message("review_reply.text.html.erb", :body => body, :review=>review, :review_url => review_url)
end
end
def review_status_changed(project, review)
redmine_headers 'Project' => review.project.identifier,
'Review-Id' => review.id,
'Review-Author' => review.user.login
recipients recipients get_mail_addresses(review)
new_status = l(:label_review_open) if review.status_changed_to == CodeReview::STATUS_OPEN
new_status = l(:label_review_closed) if review.status_changed_to == CodeReview::STATUS_CLOSED
subject "[#{review.project.name} - Updated - #{l(:label_review)}##{review.root.id}] Status changed to #{new_status}."
review_url = url_for(:controller => 'code_review', :action => 'show', :id => project, :review_id => review.root.id)
body :review => review, :review_url => review_url
return if (l(:this_is_checking_for_before_rails_2_2_2) == 'this_is_checking_for_before_rails_2_2_2')
# 何故かrails 2.2 以後は以下の処理が必要
content_type "multipart/alternative"
part "text/plain" do |p|
p.body = render_message("review_status_changed.text.plain.erb", :body => body, :review=>review, :review_url => review_url)
end
part "text/html" do |p|
p.body = render_message("review_status_changed.text.html.erb", :body => body, :review=>review, :review_url => review_url)
end
end
def get_mail_addresses(review)
mail_addresses = []
review.root.users_for_notification.each{|u|
mail_addresses << u.mail
}
committer = review.change.changeset.user
if committer
setting = CodeReviewUserSetting.find_or_create(committer.id)
mail_addresses << committer.mail if setting and !setting.mail_notification_none?
end
review.project.members.each{|member|
user = member.user
setting = CodeReviewUserSetting.find_or_create(user.id)
next unless setting
mail_addresses << user.mail if setting.mail_notification_all?
}
mail_addresses.compact.uniq
end
end

@ -0,0 +1,27 @@
<%
# Code Review plugin for Redmine
# Copyright (C) 2009 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-%>
<%= javascript_tag do %>
var line = <%= @review.line %>;
var review_id = <%= @review.id %>;
var file_count = <%= @review.file_count %>;
hideForm();
setShowReviewButton(line, review_id, false, file_count);
<% end %>

@ -0,0 +1,82 @@
<%
# Code Review plugin for Redmine
# Copyright (C) 2010 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-%>
<%
is_target = false
if project and controller and project.module_enabled?(:code_review)
is_target = true
is_target = false unless User.current.allowed_to?({:controller => 'code_review', :action => 'update_diff_view'}, project)
setting = CodeReviewProjectSetting.find(:first, :conditions => ['project_id = ?', project.id])
is_target = false unless setting
is_target = false if(setting && setting.tracker_id == nil)
action_name = controller.action_name
is_target = false unless action_name
is_target = false unless (controller.class.name == 'RepositoriesController' or controller.class.name == 'AttachmentsController')
if (is_target == true)
context = {:project => project, :controller => controller, :requrest => request}
%>
<% if (controller.class.name == 'AttachmentsController') %>
<%= render :partial => 'code_review/change_attachement_view', :locals => context %>
<% elsif (action_name == 'show' or action_name == 'revisions') %>
<%= render :partial => 'code_review/change_repository_view', :locals => context %>
<% elsif (action_name == 'revision') %>
<%= render :partial => 'code_review/change_revision_view', :locals => context %>
<% elsif (action_name == 'diff' or action_name == 'entry' or action_name == 'annotate')%>
<%if (controller.params[:rev].blank? or controller.params[:rev] == 'master')%>
<%= render :partial => 'code_review/change_entry_norevision_view', :locals => context %>
<% else
changeset = @repository.find_changeset_by_name(controller.params[:rev])
%>
<% unless changeset %>
<%= render :partial => 'code_review/change_entry_norevision_view', :locals => context %>
<% else
parameters = request.parameters
rev_to = parameters['rev_to'] unless parameters['rev_to'].blank?
review_id = parameters['review_id']
rev = parameters['rev']
path = parameters['path']
repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param")
url = url_for :controller => 'code_review', :action => 'update_diff_view', :id => project, :repository_id => repository_id
%>
<div id="code_review">
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#code_review').load('<%=url%>', {
rev: '<%=rev%>',
path:'<%=path%>',
review_id: '<%=review_id%>',
action_type:'<%=action_name%>',
rev_to: '<%=rev_to%>'});
});
</script>
<% end %>
<% end %>
<% end %>
<%
end
end
-%>

@ -0,0 +1,35 @@
<%
# Code Review plugin for Redmine
# Copyright (C) 2010-2012 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-%>
<%
parameters = request.parameters
id = parameters[:id].to_i
attachment = Attachment.find(id)
return '' unless attachment.is_text? or attachment.is_diff?
review_id = parameters[:review_id] unless parameters[:review_id].blank?
url = url_for :controller => 'code_review', :action => 'update_attachment_view', :id => project
-%>
<div id="code_review">
<div id="review_comment"/>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#code_review').load('<%=url%>', {'attachment_id': '<%=id%>', 'review_id': '<%=review_id%>'});
});
</script>

@ -0,0 +1,39 @@
<%
# Code Review plugin for Redmine
# Copyright (C) 2010-2011 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-%>
<%
parameters = request.parameters
path = parameters['path']
rev = parameters['rev']
repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param")
unless path.blank? or path.empty?
changesets = @repository.latest_changesets(path, rev, Setting.repository_log_display_limit.to_i)
change = changesets[0]
if change
link = link_to(l(:label_add_review), {:controller => 'code_review',
:action => 'forward_to_revision', :id => project, :path => path, :rev => rev, :repository_id => repository_id},
:class => 'icon icon-edit')
%>
<script type="text/javascript">
make_addreview_link('<%=project.name%>', '<%=link%>');
</script>
<% end %>
<% end %>

@ -0,0 +1,41 @@
<%
# Code Review plugin for Redmine
# Copyright (C) 2010-2012 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-%>
<%
if @changesets
changeset_ids = ''
@changesets.each { |changeset|
changeset_ids << changeset.revision
changeset_ids << ','
}
repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param")
url = url_for :controller => 'code_review', :action => 'update_revisions_view', :id => project, :repository_id => repository_id
%>
<div id="code_review_revisions"></div>
<script type="text/javascript">
$(document).ready(function(){
$('#code_review_revisions').load('<%=url%>', {changeset_ids: '<%=raw changeset_ids%>'});
});
</script>
<% end %>

@ -0,0 +1,73 @@
<%
# Code Review plugin for Redmine
# Copyright (C) 2010-2011 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-%>
<%
repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param")
if @changeset
urlprefix = url_for(:controller => 'repositories', :action => 'revisions', :id => project, :repository_id => repository_id) +
'/' + @changeset.identifier + '/entry'
%>
<div id="code_review_assignments">
<%=h l(:review_assignments)%>
<% @changeset.code_review_assignments.each do |assignment|
issue = assignment.issue %>
<%= link_to("##{issue.id} ", {:controller => 'issues', :action => 'show', :id => issue.id},
:class => issue.css_classes, :title => "#{issue}(#{issue.status})") %>
<% end if @changeset.code_review_assignments %>
<%= link_to(l(:button_add), {:controller => 'code_review',
:action => 'assign', :id=>project,
:rev => @changeset.revision,
:changeset_id => @changeset.id, :repository_id => repository_id}, :class => 'icon icon-add') %>
</div>
<script type="text/javascript">
$('#changes-legend').after($('#code_review_assignments'));
urlprefix = '<%=urlprefix%>';
<% @changeset.changes.each{|change| %>
var reviewlist = [];
<%
cnt = 0
change.code_reviews.each {|review|
issue = review.issue
url = link_to('#' + "#{issue.id} #{review.subject}(#{issue.status})",
:controller => 'code_review', :action => 'show', :id => project, :review_id => review.id, :repository_id => repository_id)
%>
var review = new CodeReview(<%=review.id%>);
review.url = '<%=url%>';
<% if review.is_closed? %>
review.is_closed = true;
<% end %>
reviewlist[<%=cnt%>] = review;
<%
cnt += 1
}
relative_path = change.relative_path || ""
if relative_path[0] != ?/
relative_path = '/' + relative_path
end
escaped_relative_path = relative_path.gsub("'"){"\\'"}
%>
code_reviews_map['<%=escaped_relative_path-%>'] = reviewlist;
<%
}
%>
UpdateRevisionView();
</script>
<% end %>

@ -0,0 +1,84 @@
<%
# Code Review plugin for Redmine
# Copyright (C) 2009 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-%>
<% for journal in journals %>
<!-- skip initial entry of code review creation -->
<% if not journal.initial? %>
<!-- header and notes/comments -->
<%
header = <<-HTML
<h4>
#{authoring journal.created_at, journal.user, :label => :label_updated_time_by}
#{content_tag('a', '', :name => "note-#{journal.anchor}")}
</h4>
<div class="profile-wrap">
#{avatar(journal.user, :size => "40")}
</div>
HTML
if not journal.notes.blank?
if User.current.logged?
editable = User.current.allowed_to?(:edit_issue_notes, journal.project)
if journal.user == User.current
editable ||= User.current.allowed_to?(:edit_own_issue_notes, journal.project)
end
end
links = [].tap do |l|
if editable
l << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes",
{ :controller => 'journals', :action => 'edit', :id => journal },
:title => l(:button_edit))
end
end
css_classes = "wiki"
css_classes << " editable" if editable
content = ''
content << content_tag('div', links.join(' '), :class => 'contextual') unless links.empty?
content << textilizable(journal, :notes)
header << content_tag("div", content, :id => "journal-#{journal.id}-notes", :class => css_classes)
end
%>
<!-- details such as attribute changes -->
<%
details = ''
if journal.details.any?
content = journal.details.collect do |detail|
if d = journal.render_detail(detail)
content_tag("li", d)
end
end.compact.join(' ')
details = content_tag("ul", content, :class => "details journal-attributes") unless content.empty?
end
%>
<!-- output HTML code -->
<%= content_tag "div", "#{header}#{details}",
{ :id => "change-#{journal.id}", :class => journal.css_classes } %>
<% end %>
<% end %>

@ -0,0 +1,30 @@
<%
# Code Review plugin for Redmine
# Copyright (C) 2010-2012 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-%>
<% if @project and @project.module_enabled?('code_review') %>
<%
baseurl = Redmine::Utils.relative_url_root
-%>
<%= javascript_include_tag(baseurl + "/plugin_assets/redmine_code_review/javascripts/code_review.js") %>
<%= javascript_include_tag(baseurl + '/javascripts/jstoolbar/jstoolbar.js') %>
<%= javascript_include_tag(baseurl + '/javascripts/jstoolbar/textile.js') %>
<%= javascript_include_tag(baseurl + "/javascripts/jstoolbar/lang/jstoolbar-#{@project.current_language}.js") %>
<%= stylesheet_link_tag(baseurl + "/plugin_assets/redmine_code_review/stylesheets/code_review.css") %>
<%= stylesheet_link_tag(baseurl + "/stylesheets/jstoolbar.css") %>
<% end %>

@ -0,0 +1,56 @@
<%#
# To change this template, choose Tools | Templates
# and open the template in the editor.
%>
<%
unless User.current.allowed_to?({:controller => 'code_review', :action => 'show'}, project)
return
end
%>
<% if issue.code_review %>
<%
review = issue.code_review
%>
<tr>
<td><b><%= l(:code_review) %>:</b></td>
<td colspan="3">
<%
label = URI.decode("#{review.repository_identifier + ':' if review.repository_identifier}#{review.path}#{'@' + review.revision if review.revision}:line #{review.line}")
-%>
<%= link_to(label,
:controller => 'code_review', :action => 'show', :id => project, :review_id => review.id, :repository_id => review.repository_identifier) %>
</td>
</tr>
<% end %>
<% if issue.code_review_assignment %>
<%
assignment = issue.code_review_assignment
repository_id = assignment.repository_identifier
%>
<tr>
<td><b><%= l(:review_assigned_for) %>:</b></td>
<td colspan="3">
<% if assignment.path %>
<%
label = URI.decode("#{repository_id + ':' if repository_id}#{assignment.path}#{'@' + assignment.revision if assignment.revision}")
-%>
<%= link_to(label,
:controller => 'code_review', :action => 'show', :id => project, :assignment_id => assignment.id, :repository_id => repository_id) %>
<% elsif assignment.revision %>
<%
repo = project unless repository_id
repo ||= assignment.repository
%>
<%= l(:label_revision) + " "%>
<%= link_to_revision(assignment.revision, repo) %>
<% elsif assignment.attachment %>
<%= link_to(assignment.attachment.filename, :controller => 'attachments', :action => 'show', :id => attachment.id) %>
<% end %>
</td>
</tr>
<% end %>

@ -0,0 +1,121 @@
<%
# Code Review plugin for Redmine
# Copyright (C) 2009-2013 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-%>
<div class="box">
<h2>
<%= l(:label_line_number, :line => @review.line) %>
</h2>
<%= form_for @review,:as => :review,
:url => {:controller => 'code_review', :action => 'new', :id=>@project}, :html => {:id => 'review_form'} do |f| %>
<%= error_messages_for 'review' %>
<%= error_messages_for 'issue' %>
<%= error_messages_for 'relation' %>
<%= f.hidden_field(:change_id) %>
<%= f.hidden_field(:line) %>
<%= hidden_field_tag(:action_type, @review.action_type) %>
<%= hidden_field_tag(:rev, @review.revision) %>
<%= hidden_field_tag(:rev_to, @review.rev_to) %>
<%= hidden_field_tag(:path, @review.path) %>
<%= hidden_field_tag(:file_count, @review.file_count) %>
<%= hidden_field_tag(:attachment_id, @review.attachment_id) %>
<%= hidden_field_tag(:repository_id, @repository_id) %>
<%= hidden_field_tag(:diff_all, @review.diff_all) %>
<p>
<label><b><%=h l(:field_subject)%>:</b></label>
<%= f.text_field :subject, :size => 70, :required => true %>
</p>
<% if @setting.tracker_in_review_dialog %>
<p>
<label><b><%=h l(:label_tracker) %>:</b></label>
<%= select :issue, :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %>
<script type="text/javascript">
$(function(){
$('#issue_tracker_id').change(function(){
var url = "<%= url_for(:controller => 'code_review', :action => 'new') -%>";
url = url + '?' + $('#review_form').serialize();
$('#review-form').load(url);
});
});
</script>
</p>
<% end %>
<p>
<label><b><%=h l(:field_parent_issue)%>:</b></label>
<%= f.text_field :parent_id, :size => 10 %>
<% if @parent_candidate %>
<%= raw l(:label_parent_suggestion, {:issue_id => link_to_issue(@parent_candidate)}) %>
<input type="button" value="<%=h l(:general_text_Yes)%>" onclick="$('#review_parent_id').val(<%= @parent_candidate.id %>)"/>
<% end %>
</p>
<% @issue.custom_field_values.each do |value| %>
<% next unless value.required? -%>
<p><%= custom_field_tag_with_label :issue, value %></p>
<% end %>
<p>
<%= f.text_area :comment,
:cols => 30,
:rows => 12,
:accesskey => accesskey(:edit),
:class => 'wiki-edit' %>
</p>
<p>
<label><b><%=h l(:field_assigned_to) %>:</b></label>
<%= select :issue, :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}), :include_blank => true %>
</p>
<% unless @project.issue_categories.empty? %>
<p>
<label><b><%=h l(:field_category) %>:</b></label>
<%= select :issue, :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %>
</p>
<% end %>
<% unless @issue.assignable_versions.empty? %>
<p>
<label><b><%=h l(:field_fixed_version) %>:</b></label>
<%= select :issue, :fixed_version_id, (@issue.assignable_versions.collect {|v| [v.name, v.id]}), :include_blank => true, :selected => @default_version_id %>
</p>
<% end %>
<%
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
-%>
<% if @issue.new_record? || @allowed_statuses.any? %>
<p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %></p>
<% else %>
<p><label><%= l(:field_status) %></label> <%= h(@issue.status.name) %></p>
<% end %>
<p>
<%
submit_url = url_for(:controller => 'code_review', :action => 'new', :id=>@project)
%>
<%= button_to_function l(:button_apply), "$('#review-form').load('#{submit_url}', $('#review_form').serialize2json())" %>
<input type="button" value="<%=h l(:button_cancel) %> " onclick="javascript:hideForm();"/>
<%= preview_link({ :controller => 'code_review', :action => 'preview', :id => @project}, 'review_form') %>
</p>
<div id="preview" class="wiki"></div>
<%= wikitoolbar_for 'review_comment' %>
<% end %>
</div>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save