diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-04-24 21:13:51 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-04-24 21:13:51 -0300 |
commit | 5d106f2597bb009f0e7b8d5ed02b6f2206237e7e (patch) | |
tree | f52f4cc80459cf32b983f030acaa9172718daa17 /lib/github | |
parent | 05255631ae2dad3b22796343453bb3288ca3dbff (diff) | |
download | gitlab-ce-5d106f2597bb009f0e7b8d5ed02b6f2206237e7e.tar.gz |
Use the base initiliazer for representations
Diffstat (limited to 'lib/github')
-rw-r--r-- | lib/github/import.rb | 2 | ||||
-rw-r--r-- | lib/github/representation/branch.rb | 9 | ||||
-rw-r--r-- | lib/github/representation/pull_request.rb | 14 |
3 files changed, 11 insertions, 14 deletions
diff --git a/lib/github/import.rb b/lib/github/import.rb index 641147c40e4..ef0ef9adc7a 100644 --- a/lib/github/import.rb +++ b/lib/github/import.rb @@ -147,7 +147,7 @@ module Github response = Github::Client.new(options).get(url, state: :all, sort: :created, direction: :asc) response.body.each do |raw| - pull_request = Github::Representation::PullRequest.new(project, raw, options) + pull_request = Github::Representation::PullRequest.new(raw, options.merge(project: project)) merge_request = MergeRequest.find_or_initialize_by(iid: pull_request.iid, source_project_id: project.id) next unless merge_request.new_record? && pull_request.valid? diff --git a/lib/github/representation/branch.rb b/lib/github/representation/branch.rb index 7c65a948ede..d1dac6944f0 100644 --- a/lib/github/representation/branch.rb +++ b/lib/github/representation/branch.rb @@ -3,11 +3,6 @@ module Github class Branch < Representation::Base attr_reader :repository - def initialize(repository, raw) - @repository = repository - @raw = raw - end - def user raw.dig('user', 'login') || 'unknown' end @@ -47,6 +42,10 @@ module Github def commit_exists? repository.branch_names_contains(sha).include?(ref) end + + def repository + @repository ||= options.fetch(:repository) + end end end end diff --git a/lib/github/representation/pull_request.rb b/lib/github/representation/pull_request.rb index 4119ca400c6..ac9c8283b4b 100644 --- a/lib/github/representation/pull_request.rb +++ b/lib/github/representation/pull_request.rb @@ -6,12 +6,6 @@ module Github delegate :user, :repo, :ref, :sha, to: :source_branch, prefix: true delegate :user, :exists?, :repo, :ref, :sha, :short_sha, to: :target_branch, prefix: true - def initialize(project, raw, options) - @project = project - @raw = raw - @options = options - end - def source_project project end @@ -54,8 +48,12 @@ module Github private + def project + @project ||= options.fetch(:project) + end + def source_branch - @source_branch ||= Representation::Branch.new(project.repository, raw['head']) + @source_branch ||= Representation::Branch.new(raw['head'], repository: project.repository) end def source_branch_name_prefixed @@ -63,7 +61,7 @@ module Github end def target_branch - @target_branch ||= Representation::Branch.new(project.repository, raw['base']) + @target_branch ||= Representation::Branch.new(raw['base'], repository: project.repository) end def target_branch_name_prefixed |