Commit a0bca5b71d11454b51f890f4dd36bbf948f1edf5

Authored by Dmitriy Zaporozhets
1 parent 1ea38562

Add Repository model to proxy request to Gitlab::Git::Repositoty and decorate co…

…mmits with Commit model
Showing 1 changed file with 41 additions and 0 deletions   Show diff stats
app/models/repository.rb 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +class Repository
  2 + attr_accessor :raw_repository
  3 +
  4 + def initialize(path_with_namespace, default_branch)
  5 + @raw_repository = Gitlab::Git::Repository.new(path_with_namespace, default_branch)
  6 + end
  7 +
  8 + def commit(id = nil)
  9 + commit = raw_repository.commit(id)
  10 + commit = Commit.new(commit) if commit
  11 + commit
  12 + end
  13 +
  14 + def commits(ref, path = nil, limit = nil, offset = nil)
  15 + commits = raw_repository.commits(ref, path, limit, offset)
  16 + commits = decorate_commits(commits) if commits.present?
  17 + commits
  18 + end
  19 +
  20 + def commits_between(target, source)
  21 + commits = raw_repository.commits_between(target, source)
  22 + commits = decorate_commits(commits) if commits.present?
  23 + commits
  24 + end
  25 +
  26 + def method_missing(m, *args, &block)
  27 + @raw_repository.send(m, *args, &block)
  28 + end
  29 +
  30 + def respond_to?(method)
  31 + return true if @raw_repository.respond_to?(method)
  32 +
  33 + super
  34 + end
  35 +
  36 + protected
  37 +
  38 + def decorate_commits(commits)
  39 + commits.map { |c| Commit.new(c) }
  40 + end
  41 +end
... ...