Commit f8a4a760480a2395ca371c4ab6201344a186fa39

Authored by Dmitriy Zaporozhets
1 parent e91ff84d

decorate commits in Gitlab::Git::repository with valid class

lib/gitlab/git/repository.rb
@@ -54,11 +54,11 @@ module Gitlab @@ -54,11 +54,11 @@ module Gitlab
54 repo.commits(root_ref).first 54 repo.commits(root_ref).first
55 end 55 end
56 56
57 - Commit.new(commit) if commit 57 + decorate_commit(commit) if commit
58 end 58 end
59 59
60 def commits_with_refs(n = 20) 60 def commits_with_refs(n = 20)
61 - commits = repo.branches.map { |ref| Commit.new(ref.commit, ref) } 61 + commits = repo.branches.map { |ref| decorate_commit(ref.commit, ref) }
62 62
63 commits.sort! do |x, y| 63 commits.sort! do |x, y|
64 y.committed_date <=> x.committed_date 64 y.committed_date <=> x.committed_date
@@ -74,11 +74,11 @@ module Gitlab @@ -74,11 +74,11 @@ module Gitlab
74 repo.commits(ref, limit, offset) 74 repo.commits(ref, limit, offset)
75 else 75 else
76 repo.commits(ref) 76 repo.commits(ref)
77 - end.map{ |c| Commit.new(c) } 77 + end.map{ |c| decorate_commit(c) }
78 end 78 end
79 79
80 def commits_between(from, to) 80 def commits_between(from, to)
81 - repo.commits_between(from, to).map { |c| Commit.new(c) } 81 + repo.commits_between(from, to).map { |c| decorate_commit(c) }
82 end 82 end
83 83
84 def last_commit_for(ref, path = nil) 84 def last_commit_for(ref, path = nil)
@@ -190,6 +190,12 @@ module Gitlab @@ -190,6 +190,12 @@ module Gitlab
190 def cache_key(type) 190 def cache_key(type)
191 "#{type}:#{path_with_namespace}" 191 "#{type}:#{path_with_namespace}"
192 end 192 end
  193 +
  194 + protected
  195 +
  196 + def decorate_commit(commit, ref = nil)
  197 + Gitlab::Git::Commit.new(commit, ref)
  198 + end
193 end 199 end
194 end 200 end
195 end 201 end
spec/lib/gitlab/git/repository_spec.rb
@@ -82,6 +82,17 @@ describe Gitlab::Git::Repository do @@ -82,6 +82,17 @@ describe Gitlab::Git::Repository do
82 end 82 end
83 end 83 end
84 84
  85 + describe "commits" do
  86 + subject do
  87 + commits = repository.commits('master', 'app', 3, 1)
  88 + commits.map { |c| c.id }
  89 + end
  90 +
  91 + it { should have(3).elements }
  92 + it { should include("8716fc78f3c65bbf7bcf7b574febd583bc5d2812") }
  93 + it { should_not include("bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a") }
  94 + end
  95 +
85 describe "commits_between" do 96 describe "commits_between" do
86 subject do 97 subject do
87 commits = repository.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff", 98 commits = repository.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff",