Use the base initiliazer for representations

parent 05255631
......@@ -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?
......
......@@ -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
......@@ -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
......
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