Use the base initiliazer for representations

parent 05255631
...@@ -147,7 +147,7 @@ module Github ...@@ -147,7 +147,7 @@ module Github
response = Github::Client.new(options).get(url, state: :all, sort: :created, direction: :asc) response = Github::Client.new(options).get(url, state: :all, sort: :created, direction: :asc)
response.body.each do |raw| 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) 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? next unless merge_request.new_record? && pull_request.valid?
......
...@@ -3,11 +3,6 @@ module Github ...@@ -3,11 +3,6 @@ module Github
class Branch < Representation::Base class Branch < Representation::Base
attr_reader :repository attr_reader :repository
def initialize(repository, raw)
@repository = repository
@raw = raw
end
def user def user
raw.dig('user', 'login') || 'unknown' raw.dig('user', 'login') || 'unknown'
end end
...@@ -47,6 +42,10 @@ module Github ...@@ -47,6 +42,10 @@ module Github
def commit_exists? def commit_exists?
repository.branch_names_contains(sha).include?(ref) repository.branch_names_contains(sha).include?(ref)
end end
def repository
@repository ||= options.fetch(:repository)
end
end end
end end
end end
...@@ -6,12 +6,6 @@ module Github ...@@ -6,12 +6,6 @@ module Github
delegate :user, :repo, :ref, :sha, to: :source_branch, prefix: true delegate :user, :repo, :ref, :sha, to: :source_branch, prefix: true
delegate :user, :exists?, :repo, :ref, :sha, :short_sha, to: :target_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 def source_project
project project
end end
...@@ -54,8 +48,12 @@ module Github ...@@ -54,8 +48,12 @@ module Github
private private
def project
@project ||= options.fetch(:project)
end
def source_branch def source_branch
@source_branch ||= Representation::Branch.new(project.repository, raw['head']) @source_branch ||= Representation::Branch.new(raw['head'], repository: project.repository)
end end
def source_branch_name_prefixed def source_branch_name_prefixed
...@@ -63,7 +61,7 @@ module Github ...@@ -63,7 +61,7 @@ module Github
end end
def target_branch def target_branch
@target_branch ||= Representation::Branch.new(project.repository, raw['base']) @target_branch ||= Representation::Branch.new(raw['base'], repository: project.repository)
end end
def target_branch_name_prefixed def target_branch_name_prefixed
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment