summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-31 23:48:12 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-31 23:48:12 +0300
commitbbfbff3add4c78ce1256ac3bbe787cc6eb9fe1b9 (patch)
tree52fca95c2741559ab0961962a863c7ccb1a7e42b /app/models
parentb53557aca64fbf55f9bbd59849d83daa10b7361f (diff)
downloadgitlab-ce-bbfbff3add4c78ce1256ac3bbe787cc6eb9fe1b9.tar.gz
Extend models functionality with old decorator methods. Use Repository model
Diffstat (limited to 'app/models')
-rw-r--r--app/models/commit.rb51
-rw-r--r--app/models/merge_request.rb13
-rw-r--r--app/models/project.rb2
-rw-r--r--app/models/tree.rb8
4 files changed, 67 insertions, 7 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index ea5b451b28f..96c8577f90e 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -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 @@ class Commit
@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
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 505f6637d77..8d3780532f3 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -152,7 +152,17 @@ class MergeRequest < ActiveRecord::Base
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 @@ class MergeRequest < ActiveRecord::Base
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
diff --git a/app/models/project.rb b/app/models/project.rb
index 54abbc3ecb1..934dd6b241b 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -142,7 +142,7 @@ class Project < ActiveRecord::Base
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
diff --git a/app/models/tree.rb b/app/models/tree.rb
index 96395a42394..4b6c5b133e9 100644
--- a/app/models/tree.rb
+++ b/app/models/tree.rb
@@ -26,4 +26,12 @@ class Tree
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