diff --git a/app/contexts/commit_load_context.rb b/app/contexts/commit_load_context.rb index 1f23f633af322e528211a3b14b71b49c9fd1aa20..c8d77d9b5f349cfb2a9b809f97fa6224076cfd1b 100644 --- a/app/contexts/commit_load_context.rb +++ b/app/contexts/commit_load_context.rb @@ -12,6 +12,7 @@ class CommitLoadContext < BaseContext commit = project.repository.commit(params[:id]) if commit + commit = Commit.new(commit) commit = CommitDecorator.decorate(commit) line_notes = project.notes.for_commit_id(commit.id).inline diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index 9dc0d96883e3351082497b7bd8ed6b863aa10e0f..fded5f0ab8698b90ffb8752ad4e5bda9e9c5c428 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -13,6 +13,7 @@ class CommitsController < ProjectResourceController @limit, @offset = (params[:limit] || 40), (params[:offset] || 0) @commits = @repo.commits(@ref, @path, @limit, @offset) + @commits = Commit.decorate(@commits) @commits = CommitDecorator.decorate_collection(@commits) respond_to do |format| diff --git a/app/models/commit.rb b/app/models/commit.rb index 0164ae663bec18e59c00292244c50d674e7d4a5f..ea5b451b28fa1a21558280de3fabae230af64515 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -10,12 +10,20 @@ 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 @raw = raw_commit end + def id + @raw.id + end + def method_missing(m, *args, &block) @raw.send(m, *args, &block) end diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index 86e0dfbbf2566611593965fff043740630a12e5a..023672f986b37975f3acc2eea02b7eb7db9a72e1 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -7,8 +7,8 @@ module Gitlab attr_accessor :raw_commit, :head, :refs delegate :message, :authored_date, :committed_date, :parents, :sha, - :date, :committer, :author, :diffs, :tree, :id, :stats, - :to_patch, to: :raw_commit + :date, :committer, :author, :diffs, :tree, :id, :stats, :to_patch, + to: :raw_commit class << self def find_or_first(repo, commit_id = nil, root_ref) diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index b9025026c1bbed705f664b039c54d06e766b2ead..3abeaeef821979086d3dffd9ae1e1fb7727ceb8d 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -7,7 +7,7 @@ describe GitlabMarkdownHelper do let!(:project) { create(:project) } let(:user) { create(:user, username: 'gfm') } - let(:commit) { CommitDecorator.decorate(project.repository.commit) } + let(:commit) { CommitDecorator.decorate(Commit.new(project.repository.commit)) } let(:issue) { create(:issue, project: project) } let(:merge_request) { create(:merge_request, project: project) } let(:snippet) { create(:snippet, project: project) }