rosa-abf/rosa-build

View on GitHub
app/controllers/projects/git/commits_controller.rb

Summary

Maintainability
A
1 hr
Test Coverage
class Projects::Git::CommitsController < Projects::Git::BaseController
 
def index
if @path.present?
@commits = @project.repo.log(@treeish, @path)
else
@commits, @page, @last_page = @project.paginate_commits(@treeish, page: params[:page])
end
end
 
Method `show` has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
def show
@commit = @commentable = @project.repo.commit(params[:id]) || raise(ActiveRecord::RecordNotFound)
@comments = Comment.for_commit(@commit)
 
respond_to do |format|
format.html
format.diff { render text: (@commit.show.map(&:diff).join("\n") rescue ''), content_type: "text/plain" }
format.patch { render text: (@commit.to_patch rescue ''), content_type: "text/plain" }
end
end
 
Method `diff` has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
def diff
res = params[:diff].split(/\A(.*)\.\.\.(.*)\z/).select {|e| e.present?}
if res[1].present?
params1 = res[0]
params2 = res[1] == 'HEAD' ? @project.resolve_default_branch : res.last
else # get only one parameter
params1 = @project.resolve_default_branch
params2 = res.first
end
params1.sub! 'HEAD', @project.resolve_default_branch
params2.sub! 'HEAD', @project.resolve_default_branch
 
ref1 = if @project.repo.branches_and_tags.include? params1
@project.repo.commits(params1).first
else
params1 # possible commit hash
end
@commit1 = @project.repo.commit(ref1) || raise(ActiveRecord::RecordNotFound)
 
ref = if @project.repo.branches_and_tags.include? params2
@project.repo.commits(params2).first
else
params2 # possible commit hash
end
@commit = @project.repo.commit(ref) || raise(ActiveRecord::RecordNotFound)
@common_ancestor = @project.repo.commit(@project.repo.git.merge_base({}, @commit1, @commit)) || @commit1
@stats = @project.repo.diff_stats @commit1.id, @commit.id
end
end