diff options
Diffstat (limited to 'lib/github/representation')
| -rw-r--r-- | lib/github/representation/branch.rb | 9 | ||||
| -rw-r--r-- | lib/github/representation/pull_request.rb | 14 |
2 files changed, 10 insertions, 13 deletions
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 |
