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 12 commit = project.repository.commit(params[:id])
13 13  
14 14 if commit
  15 + commit = Commit.new(commit)
15 16 commit = CommitDecorator.decorate(commit)
16 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 13 @limit, @offset = (params[:limit] || 40), (params[:offset] || 0)
14 14  
15 15 @commits = @repo.commits(@ref, @path, @limit, @offset)
  16 + @commits = Commit.decorate(@commits)
16 17 @commits = CommitDecorator.decorate_collection(@commits)
17 18  
18 19 respond_to do |format|
... ...
app/models/commit.rb
... ... @@ -10,12 +10,20 @@ class Commit
10 10  
11 11 attr_accessor :raw
12 12  
  13 + def self.decorate(commits)
  14 + commits.map { |c| Commit.new(c) }
  15 + end
  16 +
13 17 def initialize(raw_commit)
14 18 raise "Nil as raw commit passed" unless raw_commit
15 19  
16 20 @raw = raw_commit
17 21 end
18 22  
  23 + def id
  24 + @raw.id
  25 + end
  26 +
19 27 def method_missing(m, *args, &block)
20 28 @raw.send(m, *args, &block)
21 29 end
... ...
lib/gitlab/git/commit.rb
... ... @@ -7,8 +7,8 @@ module Gitlab
7 7 attr_accessor :raw_commit, :head, :refs
8 8  
9 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 13 class << self
14 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 let!(:project) { create(:project) }
8 8  
9 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 11 let(:issue) { create(:issue, project: project) }
12 12 let(:merge_request) { create(:merge_request, project: project) }
13 13 let(:snippet) { create(:snippet, project: project) }
... ...