Commit 26323046fda07b2353ee427afcd0253cea935047

Authored by Dmitriy Zaporozhets
1 parent 9dc64463

Decorate Gitlab::Git::Commit with Commit

app/contexts/commit_load_context.rb
@@ -12,6 +12,7 @@ class CommitLoadContext < BaseContext @@ -12,6 +12,7 @@ class CommitLoadContext < BaseContext
12 commit = project.repository.commit(params[:id]) 12 commit = project.repository.commit(params[:id])
13 13
14 if commit 14 if commit
  15 + commit = Commit.new(commit)
15 commit = CommitDecorator.decorate(commit) 16 commit = CommitDecorator.decorate(commit)
16 line_notes = project.notes.for_commit_id(commit.id).inline 17 line_notes = project.notes.for_commit_id(commit.id).inline
17 18
app/controllers/commits_controller.rb
@@ -13,6 +13,7 @@ class CommitsController < ProjectResourceController @@ -13,6 +13,7 @@ class CommitsController < ProjectResourceController
13 @limit, @offset = (params[:limit] || 40), (params[:offset] || 0) 13 @limit, @offset = (params[:limit] || 40), (params[:offset] || 0)
14 14
15 @commits = @repo.commits(@ref, @path, @limit, @offset) 15 @commits = @repo.commits(@ref, @path, @limit, @offset)
  16 + @commits = Commit.decorate(@commits)
16 @commits = CommitDecorator.decorate_collection(@commits) 17 @commits = CommitDecorator.decorate_collection(@commits)
17 18
18 respond_to do |format| 19 respond_to do |format|
app/models/commit.rb
@@ -10,12 +10,20 @@ class Commit @@ -10,12 +10,20 @@ class Commit
10 10
11 attr_accessor :raw 11 attr_accessor :raw
12 12
  13 + def self.decorate(commits)
  14 + commits.map { |c| Commit.new(c) }
  15 + end
  16 +
13 def initialize(raw_commit) 17 def initialize(raw_commit)
14 raise "Nil as raw commit passed" unless raw_commit 18 raise "Nil as raw commit passed" unless raw_commit
15 19
16 @raw = raw_commit 20 @raw = raw_commit
17 end 21 end
18 22
  23 + def id
  24 + @raw.id
  25 + end
  26 +
19 def method_missing(m, *args, &block) 27 def method_missing(m, *args, &block)
20 @raw.send(m, *args, &block) 28 @raw.send(m, *args, &block)
21 end 29 end
lib/gitlab/git/commit.rb
@@ -7,8 +7,8 @@ module Gitlab @@ -7,8 +7,8 @@ module Gitlab
7 attr_accessor :raw_commit, :head, :refs 7 attr_accessor :raw_commit, :head, :refs
8 8
9 delegate :message, :authored_date, :committed_date, :parents, :sha, 9 delegate :message, :authored_date, :committed_date, :parents, :sha,
10 - :date, :committer, :author, :diffs, :tree, :id, :stats,  
11 - :to_patch, to: :raw_commit 10 + :date, :committer, :author, :diffs, :tree, :id, :stats, :to_patch,
  11 + to: :raw_commit
12 12
13 class << self 13 class << self
14 def find_or_first(repo, commit_id = nil, root_ref) 14 def find_or_first(repo, commit_id = nil, root_ref)
spec/helpers/gitlab_markdown_helper_spec.rb
@@ -7,7 +7,7 @@ describe GitlabMarkdownHelper do @@ -7,7 +7,7 @@ describe GitlabMarkdownHelper do
7 let!(:project) { create(:project) } 7 let!(:project) { create(:project) }
8 8
9 let(:user) { create(:user, username: 'gfm') } 9 let(:user) { create(:user, username: 'gfm') }
10 - let(:commit) { CommitDecorator.decorate(project.repository.commit) } 10 + let(:commit) { CommitDecorator.decorate(Commit.new(project.repository.commit)) }
11 let(:issue) { create(:issue, project: project) } 11 let(:issue) { create(:issue, project: project) }
12 let(:merge_request) { create(:merge_request, project: project) } 12 let(:merge_request) { create(:merge_request, project: project) }
13 let(:snippet) { create(:snippet, project: project) } 13 let(:snippet) { create(:snippet, project: project) }