Read about our upcoming Code of Conduct on this issue

Commit bbfbff3a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Extend models functionality with old decorator methods. Use Repository model

parent b48d3dcf096f
......@@ -13,7 +13,6 @@ def execute
if commit
commit = Commit.new(commit)
commit = CommitDecorator.decorate(commit)
line_notes = project.notes.for_commit_id(commit.id).inline
result[:commit] = commit
......
......@@ -3,7 +3,6 @@ module Notes
def note_commit_email(recipient_id, note_id)
@note = Note.find(note_id)
@commit = @note.noteable
@commit = CommitDecorator.decorate(@commit)
@project = @note.project
mail(to: recipient(recipient_id), subject: subject("note for commit #{@commit.short_id}", @commit.title))
end
......
......@@ -10,10 +10,6 @@ class Commit
attr_accessor :raw
def self.decorate(commits)
commits.map { |c| Commit.new(c) }
end
def initialize(raw_commit)
raise "Nil as raw commit passed" unless raw_commit
......@@ -24,7 +20,54 @@ def id
@raw.id
end
# Returns a string describing the commit for use in a link title
#
# Example
#
# "Commit: Alex Denisov - Project git clone panel"
def link_title
"Commit: #{author_name} - #{title}"
end
# Returns the commits title.
#
# Usually, the commit title is the first line of the commit message.
# In case this first line is longer than 80 characters, it is cut off
# after 70 characters and ellipses (`&hellp;`) are appended.
def title
title = safe_message
return no_commit_message if title.blank?
title_end = title.index(/\n/)
if (!title_end && title.length > 80) || (title_end && title_end > 80)
title[0..69] << "&hellip;".html_safe
else
title.split(/\n/, 2).first
end
end
# Returns the commits description
#
# cut off, ellipses (`&hellp;`) are prepended to the commit message.
def description
description = safe_message
title_end = description.index(/\n/)
if (!title_end && description.length > 80) || (title_end && title_end > 80)
"&hellip;".html_safe << description[70..-1]
else
description.split(/\n/, 2)[1].try(:chomp)
end
end
def method_missing(m, *args, &block)
@raw.send(m, *args, &block)
end
def respond_to?(method)
return true if @raw.respond_to?(method)
super
end
end
......@@ -152,7 +152,17 @@ def closed_event
end
def commits
st_commits || []
if st_commits.present?
# check if merge request commits are valid
if st_commits.first.respond_to?(:short_id)
st_commits
else
# if commits are invalid - simply reload it from repo
reloaded_commits
end
else
[]
end
end
def probably_merged?
......@@ -171,7 +181,6 @@ def reloaded_commits
def unmerged_commits
self.project.repository.
commits_between(self.target_branch, self.source_branch).
map {|c| Commit.new(c)}.
sort_by(&:created_at).
reverse
end
......
......@@ -142,7 +142,7 @@ def team
def repository
if path
@repository ||= Gitlab::Git::Repository.new(path_with_namespace, default_branch)
@repository ||= Repository.new(path_with_namespace, default_branch)
else
nil
end
......
......@@ -26,4 +26,12 @@ def invalid?
def empty?
data.blank?
end
def up_dir?
path.present?
end
def readme
@readme ||= contents.find { |c| c.is_a?(Grit::Blob) and c.name =~ /^readme/i }
end
end
......@@ -101,10 +101,8 @@ def assign_ref_vars
# It is used "@project.repository.commits(@ref, @path, 1, 0)",
# because "@project.repository.commit(@ref)" returns wrong commit when @ref is tag name.
@commit = @project.repository.commits(@ref, @path, 1, 0).first
@commit = CommitDecorator.decorate(@commit)
@tree = Tree.new(@commit.tree, @ref, @path)
@tree = TreeDecorator.new(@tree)
raise InvalidPathError if @tree.invalid?
rescue RuntimeError, NoMethodError, InvalidPathError
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment