Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
haru committed Dec 31, 2018
2 parents 61f3a34 + 3a920e8 commit 4b027dd
Show file tree
Hide file tree
Showing 65 changed files with 960 additions and 1,032 deletions.
14 changes: 6 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
language: ruby
rvm:
- 2.2
- 2.3
- 2.4
- 2.5
env:
- REDMINE_VER=3.4-stable
- REDMINE_VER=master
- REDMINE_VER=4.0-stable
install:
- bash -x ./travis/travis_install.sh
script:
- export TESTSPACE=`pwd`/testspace
- export NAME_OF_PLUGIN=redmine_code_review
- export PATH_TO_PLUGIN=`pwd`
- export PATH_TO_REDMINE=$TESTSPACE/redmine
- mkdir $TESTSPACE
- bash -x ./travis.sh
- bash -x ./travis/travis.sh
notifications:
slack:
secure: XhtN5XeJKyYhGYRFGfxGpGaVcUnUsZoxX3ZL3RgHikcBhD0hY6Ogn09BSiygP381lbIlV7+2nlRvNoSUKYmx2uX5w8AUYCE4yo9yJGlY+70rD2kjWsuG9OK4L/QPCXIUf8NFX24PdY9CRITK5CfR1/hEZCx9ygT6GLAqpjqNDtfMpSRx7S3olVjX58ucB9azDcvaT75vPY1nEnnn/IuOwGF27KBk9lLZtMaG1ohI6+9jW9xCxz8cLfUUPIu+PH4/AvJ8GMNJtlc3Yvgbg57lCtulvHyrXqXHMvMDL2aTdIj2XsjVSvXV4jRrNuhJga6gDAtl/3Lzm+UZZAeHpR4qHDZN06za25HypX/GbX5pZtpr30t+HHs3cd+ecHb4uP/Tnxko0KzNywg6Ayn/8TC548eu0JRITzPS5C9/NKzA+XnAjVgKMzqy0zU1VVk83hBXshgpfqplfZzdIrn75kcV/3qsiaD4qEFM2MqNYD15Epq8a7W/9IKdhd95LsQjp1Fb0g7XiQcM3ahIgMLIjP5tZfQ8b7tVlmDx1GCP4uRFOBeDeoz9i++UaT/FdPHOFGirWfDZMJoVq3MXixaTudEPFomO2HktErAMIEjQQyVe4FylglGnE52RCqEJ0qiD/kh1HV1VnVqyTJ9o3DXgLTIMdFiw+jHtTuorYPG0Qn1Dqbg=
5 changes: 3 additions & 2 deletions Gemfile_for_test
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
source 'http://rubygems.org'


group :test do
gem "simplecov-rcov"
gem 'factory_girl_rails'
gem 'factory_bot_rails'
gem 'shoulda'
gem 'rails-controller-testing'
gem 'coveralls', :require => false
end
130 changes: 59 additions & 71 deletions app/controllers/code_review_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class CodeReviewController < ApplicationController
unloadable
before_filter :find_project, :authorize, :find_user, :find_setting, :find_repository
before_action :find_project, :authorize, :find_user, :find_setting, :find_repository

helper :sort
include SortHelper
Expand All @@ -33,26 +33,26 @@ 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
@all_review_count = CodeReview.where(['project_id = ?', @project.id]).count
@review_pages = Paginator.new @review_count, limit, params['page']
@show_closed = (params['show_closed'] == 'true')
show_closed_option = " and #{IssueStatus.table_name}.is_closed = ? "
if (@show_closed)
show_closed_option = ''
end

show_closed_option = '' if (@show_closed)

conditions = ["#{CodeReview.table_name}.project_id = ? and issue_id is NOT NULL" + show_closed_option, @project.id]
unless (@show_closed)
conditions << false
end

conditions << false unless (@show_closed)

@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 All @@ -68,7 +68,7 @@ def new
else
@review.issue.tracker_id = @setting.tracker_id
end
@review.assign_attributes(params[:review])
@review.attributes = params.require(:review).permit(:change_id, :subject, :line, :parent_id, :comment, :status_id, :issue) if params[:review]
@review.project_id = @project.id
@review.issue.project_id = @project.id

Expand All @@ -85,20 +85,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 @@ -113,38 +113,36 @@ def new
}
@review.save!

render :partial => 'add_success', :status => 200
render partial: 'add_success', status: 200
return
else
change_id = params[:change_id].to_i unless params[:change_id].blank?
@review.change = Change.find(change_id) if change_id
@review.line = params[:line].to_i unless params[:line].blank?
if (@review.changeset and @review.changeset.user_id)
if @review.changeset and @review.changeset.user_id
@review.issue.assigned_to_id = @review.changeset.user_id
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
render partial: 'new_form', status: 200
}
rescue ActiveRecord::RecordInvalid => e
logger.error e
render :partial => 'new_form', :status => 200
render partial: 'new_form', status: 200
end
end

Expand All @@ -160,7 +158,7 @@ def assign
code[:repository_id] = @repository_id if @repository_id

changeset = Changeset.find(code[:changeset_id]) if code[:changeset_id]
if (changeset == nil and code[:change_id] != nil)
if changeset == nil and code[:change_id] != nil
change = Change.find(code[:change_id])
changeset = change.changeset if change
end
Expand All @@ -174,8 +172,8 @@ def assign
end
issue[:tracker_id] = @setting.assignment_tracker_id if @setting.assignment_tracker_id

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

def update_diff_view
Expand All @@ -190,14 +188,12 @@ def update_diff_view

@action_type = params[:action_type]
changeset = @repository.find_changeset_by_name(@rev)
if @paths.empty?
changeset.filechanges.each{|chg|
}
end

changeset.filechanges.each { |chg| } if @paths.empty?

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

@changeset = changeset
if @path
Expand All @@ -220,12 +216,7 @@ def update_diff_view
end
@review.change_id = @change.id if @change

#render :partial => 'show_error'
#return



render :partial => 'update_diff_view'
render partial: 'update_diff_view'
end

def update_attachment_view
Expand All @@ -238,7 +229,7 @@ def update_attachment_view

@reviews = CodeReview.where(['attachment_id = (?) and issue_id is NOT NULL', @attachment_id]).all

render :partial => 'update_diff_view'
render partial: 'update_diff_view'
end

def show
Expand All @@ -251,29 +242,27 @@ def show
target = @review if @review
target = @assignment if @assignment
@repository_id = target.repository_identifier
if request.xhr? or !params[:update].blank?
render :partial => 'show'
if request.xhr? || !params[:update].blank?
render partial: 'show'
elsif target.path
#@review = @review.root
path = URI.decode(target.path)
#path = '/' + path unless path.match(/^\//)
path = URI.decode_www_form(target.path)
action_name = target.action_type
rev_to = ''
rev_to = '&rev_to=' + target.rev_to if target.rev_to
if action_name == 'attachment'
attachment = target.attachment
url = url_for(:controller => 'attachments', :action => 'show', :id => attachment.id) + '/' + URI.escape(attachment.filename)
url = url_for(controller: 'attachments', action: 'show',
id: attachment.id) + '/' + URI.encode(attachment.filename)
url << '?review_id=' + @review.id.to_s if @review
redirect_to(url)
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)
#url = url_for(:controller => 'repositories', :action => action_name, :id => @project, :repository_id => @repository_id) + path + '?rev=' + target.revision
url = url_for(controller: 'repositories', action: action_name,
id: @project, repository_id: @repository_id,
rev: target.revision, path: path)
url << '?review_id=' + @review.id.to_s + rev_to if @review
url << '?r=' + rev_to unless @review
redirect_to url
end
redirect_to url
end
end

Expand All @@ -284,7 +273,7 @@ def reply
@issue.lock_version = params[:issue][:lock_version]
comment = params[:reply][:comment]
journal = @issue.init_journal(User.current, comment)
@review.assign_attributes(params[:review])
@review.attributes = params.require(:review).permit(:change_id, :subject, :line, :parent_id, :comment, :status_id, :issue) if params[:review]
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)

@issue.save!
Expand All @@ -293,11 +282,11 @@ def reply
flash[:notice] = l(:notice_successful_update)
end

render :partial => 'show'
render partial: 'show'
rescue ActiveRecord::StaleObjectError
# Optimistic locking exception
@error = l(:notice_locking_conflict)
render :partial => 'show'
render partial: 'show'
end
end

Expand All @@ -309,30 +298,30 @@ def update
@allowed_statuses = @review.issue.new_statuses_allowed_to(User.current)
@issue = @review.issue
@issue.lock_version = params[:issue][:lock_version]
@review.assign_attributes(params[:review])
@review.attributes = params.require(:review).permit(:change_id, :subject, :lock_version, :parent_id, :comment, :status_id, :issue)
@review.updated_by_id = @user.id
@review.save!
@review.issue.save!
@notice = l(:notice_review_updated)
lang = current_language
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
set_language lang if respond_to? 'set_language'
render :partial => 'show'
render partial: 'show'
}
rescue ActiveRecord::StaleObjectError
# Optimistic locking exception
@error = l(:notice_locking_conflict)
render :partial => 'show'
rescue
render :partial => 'show'
render partial: 'show'
#rescue => e
#throw e
#render :partial => 'show'
end
end


def destroy
@review = CodeReview.find(params[:review_id].to_i)
@review.issue.destroy if @review
render :text => 'delete success.'
render plain: 'delete success.'
end

def forward_to_revision
Expand All @@ -342,28 +331,28 @@ def forward_to_revision
change = changesets[0]

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

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

def preview
@text = params[:review][:comment]
@text = params[:reply][:comment] unless @text
render :partial => 'common/preview'
@text ||= params[:reply][:comment]
render partial: 'common/preview'
end

def update_revisions_view
changeset_ids = []
#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'
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 +371,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
Loading

0 comments on commit 4b027dd

Please sign in to comment.