Skip to content

Commit

Permalink
code re-format by rufo
Browse files Browse the repository at this point in the history
  • Loading branch information
haru committed Dec 8, 2017
1 parent 61f3a34 commit 4e6feb6
Show file tree
Hide file tree
Showing 55 changed files with 316 additions and 402 deletions.
42 changes: 18 additions & 24 deletions app/controllers/code_review_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CodeReviewController < ApplicationController

def index
sort_init "#{Issue.table_name}.id", 'desc'
sort_update ["#{Issue.table_name}.id", "#{Issue.table_name}.status_id", "#{Issue.table_name}.subject", "path", "updated_at", "user_id", "#{Changeset.table_name}.committer", "#{Changeset.table_name}.revision"]
sort_update ["#{Issue.table_name}.id", "#{Issue.table_name}.status_id", "#{Issue.table_name}.subject", "path", "updated_at", "user_id", "#{Changeset.table_name}.committer", "#{Changeset.table_name}.revision"]

limit = per_page_option
@review_count = CodeReview.where(["project_id = ? and issue_id is NOT NULL", @project.id]).count
Expand All @@ -52,7 +52,8 @@ def index
@reviews = CodeReview.order(sort_clause).limit(limit).where(conditions).joins(
"left join #{Change.table_name} on change_id = #{Change.table_name}.id left join #{Changeset.table_name} on #{Change.table_name}.changeset_id = #{Changeset.table_name}.id " +
"left join #{Issue.table_name} on issue_id = #{Issue.table_name}.id " +
"left join #{IssueStatus.table_name} on #{Issue.table_name}.status_id = #{IssueStatus.table_name}.id").offset(@review_pages.offset)
"left join #{IssueStatus.table_name} on #{Issue.table_name}.status_id = #{IssueStatus.table_name}.id"
).offset(@review_pages.offset)
@i_am_member = @user.member_of?(@project)
render :template => 'code_review/index', :layout => !request.xhr?
end
Expand Down Expand Up @@ -85,20 +86,20 @@ def new
@review.issue.safe_attributes = params[:issue] unless params[:issue].blank?
@review.diff_all = (params[:diff_all] == 'true')

@parent_candidate = get_parent_candidate(@review.rev) if @review.rev
@parent_candidate = get_parent_candidate(@review.rev) if @review.rev

if request.post?
@review.issue.save!
if @review.changeset
@review.changeset.issues.each {|issue|
@review.changeset.issues.each { |issue|
create_relation @review, issue, @setting.issue_relation_type
} if @setting.auto_relation?
elsif @review.attachment and @review.attachment.container_type == 'Issue'
issue = Issue.find_by_id(@review.attachment.container_id)
create_relation @review, issue, @setting.issue_relation_type if @setting.auto_relation?
end
watched_users = []
@review.open_assignment_issues(@user.id).each {|issue|
@review.open_assignment_issues(@user.id).each { |issue|
unless @review.issue.parent_id == issue.id
create_relation @review, issue, IssueRelation::TYPE_RELATES
end
Expand All @@ -124,21 +125,19 @@ def new
end
@default_version_id = @review.issue.fixed_version.id if @review.issue.fixed_version
if @review.changeset and @default_version_id.blank?
@review.changeset.issues.each {|issue|
@review.changeset.issues.each { |issue|
if issue.fixed_version
@default_version_id = issue.fixed_version.id
break;
break
end
}
end
@review.open_assignment_issues(@user.id).each {|issue|
@review.open_assignment_issues(@user.id).each { |issue|
if issue.fixed_version
@default_version_id = issue.fixed_version.id
break;
break
end
} unless @default_version_id


end
render :partial => 'new_form', :status => 200
}
Expand Down Expand Up @@ -174,7 +173,7 @@ def assign
end
issue[:tracker_id] = @setting.assignment_tracker_id if @setting.assignment_tracker_id

redirect_to :controller => 'issues', :action => "new" , :project_id => @project,
redirect_to :controller => 'issues', :action => "new", :project_id => @project,
:issue => issue, :code => code
end

Expand All @@ -191,8 +190,7 @@ def update_diff_view
@action_type = params[:action_type]
changeset = @repository.find_changeset_by_name(@rev)
if @paths.empty?
changeset.filechanges.each{|chg|
}
changeset.filechanges.each { |chg| }
end

url = @repository.url
Expand All @@ -208,9 +206,9 @@ def update_diff_view
end
end
@change = nil
changeset.filechanges.each{|chg|
changeset.filechanges.each { |chg|
@change = chg if ((chg.path == fullpath) or ("/#{chg.path}" == fullpath)) or (chg.path == "/#{@path}")
} unless @path.blank?
} unless @path.blank?

@changeset = changeset
if @path
Expand All @@ -223,8 +221,6 @@ def update_diff_view
#render :partial => 'show_error'
#return



render :partial => 'update_diff_view'
end

Expand Down Expand Up @@ -268,7 +264,7 @@ def show
else
path = nil if target.diff_all
url = url_for(:controller => 'repositories', :action => action_name, :id => @project,
:repository_id => @repository_id, :rev => target.revision, :path => path)
:repository_id => @repository_id, :rev => target.revision, :path => path)
#url = url_for(:controller => 'repositories', :action => action_name, :id => @project, :repository_id => @repository_id) + path + '?rev=' + target.revision
url << '?review_id=' + @review.id.to_s + rev_to if @review
url << '?r=' + rev_to unless @review
Expand Down Expand Up @@ -328,7 +324,6 @@ def update
end
end


def destroy
@review = CodeReview.find(params[:review_id].to_i)
@review.issue.destroy if @review
Expand All @@ -343,7 +338,6 @@ def forward_to_revision

identifier = change.identifier
redirect_to url_for(:controller => 'repositories', :action => 'entry', :id => @project, :repository_id => @repository_id) + '/' + path + '?rev=' + identifier.to_s

end

def preview
Expand All @@ -357,13 +351,14 @@ def update_revisions_view
#changeset_ids = CGI.unescape(params[:changeset_ids]).split(',') unless params[:changeset_ids].blank?
changeset_ids = params[:changeset_ids].split(',') unless params[:changeset_ids].blank?
@changesets = []
changeset_ids.each {|id|
changeset_ids.each { |id|
@changesets << @repository.find_changeset_by_name(id) unless id.blank?
}
render :partial => 'update_revisions'
end

private

def find_repository
if params[:repository_id].present? and @project.repositories
@repository = @project.repositories.find_by_identifier_param(params[:repository_id])
Expand All @@ -382,14 +377,13 @@ def find_user
@user = User.current
end


def find_setting
@setting = CodeReviewProjectSetting.find_or_create(@project)
end

def get_parent_candidate(revision)
changeset = @repository.find_changeset_by_name(revision)
changeset.issues.each {|issue|
changeset.issues.each { |issue|
return Issue.find(issue.parent_issue_id) if issue.parent_issue_id
}
nil
Expand Down
13 changes: 6 additions & 7 deletions app/controllers/code_review_settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ def update
@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
Expand All @@ -50,7 +49,7 @@ def add_filter
filters = [] unless filters
filters << params[:auto_assign_add_filter]

@auto_assign.filters = filters.collect{|f|
@auto_assign.filters = filters.collect { |f|
filter = AssignmentFilter.new
filter.attributes = f
filter
Expand All @@ -66,7 +65,7 @@ def edit_filter
filters = params[:auto_assign][:filters].values unless params[:auto_assign][:filters].blank?
filters = [] unless filters
i = 0
@auto_assign.filters = filters.collect{|f|
@auto_assign.filters = filters.collect { |f|
filter = AssignmentFilter.new
if i == num
filter.attributes = params[:auto_assign_edit_filter][num.to_s]
Expand Down Expand Up @@ -97,16 +96,17 @@ def sort
filters[num][:order] = 999999999
end

@auto_assign.filters = filters.collect{|f|
@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])
Expand All @@ -115,5 +115,4 @@ def find_project
def find_user
@user = User.current
end

end
11 changes: 6 additions & 5 deletions app/helpers/code_review_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
# 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})")
: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')
: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

Expand Down
15 changes: 7 additions & 8 deletions app/models/code_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CodeReview < ActiveRecord::Base
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,
validates_presence_of :project_id, :user_id, :updated_by_id, :issue,
:subject, :action_type, :line

STATUS_OPEN = 0
Expand All @@ -49,7 +49,7 @@ def reopen
issue.status = IssueStatus.find(1)
#self.root.status = STATUS_OPEN
end

def committer
return changeset.author if changeset
end
Expand All @@ -74,7 +74,7 @@ def path
@path = change.path
else
@path = change.path[rootpath.length, change.path.length - rootpath.length]
end
end
rescue => ex
return ex.to_s
end
Expand All @@ -92,13 +92,13 @@ def changeset
def repository
@repository ||= changeset.repository if changeset
end

def repository_identifier
return nil unless repository
@repository_identifier ||= repository.identifier_param
end

def comment=(str)
def comment=(str)
issue.description = str if issue
end

Expand All @@ -113,7 +113,6 @@ def before_save
def validate
unless issue.validate
false

end
end

Expand Down Expand Up @@ -141,7 +140,7 @@ def subject
issue.subject
end

def parent_id= (p)
def parent_id=(p)
issue.parent_issue_id = p
end

Expand All @@ -164,7 +163,7 @@ def open_assignment_issues(user_id)
assignments = assignments + changeset.code_review_assignments if changeset
assignments = assignments + attachment.code_review_assignments if attachment

assignments.each {|assignment|
assignments.each { |assignment|
unless assignment.is_closed?
issues << assignment.issue if user_id == assignment.issue.assigned_to_id
end
Expand Down
15 changes: 7 additions & 8 deletions app/models/code_review_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ 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")
Expand All @@ -55,25 +55,24 @@ def self.create_with_changeset(changeset)
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.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.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
Expand Down
5 changes: 3 additions & 2 deletions app/models/code_review_project_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@ def auto_assign_settings
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
Expand Down
Loading

0 comments on commit 4e6feb6

Please sign in to comment.