Extract Github::Representation::Issuable

This commit is contained in:
Douglas Barbosa Alexandre 2017-04-19 19:17:42 -03:00
parent f35573f12e
commit 00e3d60c3d
3 changed files with 39 additions and 66 deletions

View File

@ -0,0 +1,37 @@
module Github
module Representation
class Issuable < Representation::Base
def iid
raw['number']
end
def title
raw['title']
end
def description
raw['body'] || ''
end
def milestone
return unless raw['milestone'].present?
@milestone ||= Github::Representation::Milestone.new(raw['milestone'])
end
def author
@author ||= Github::Representation::User.new(raw['user'])
end
def assignee
return unless assigned?
@assignee ||= Github::Representation::User.new(raw['assignee'])
end
def assigned?
raw['assignee'].present?
end
end
end
end

View File

@ -1,46 +1,14 @@
module Github
module Representation
class Issue < Representation::Base
def iid
raw['number']
end
def title
raw['title']
end
def description
raw['body'] || ''
end
class Issue < Representation::Issuable
def labels
raw['labels']
end
def milestone
return unless raw['milestone'].present?
@milestone ||= Github::Representation::Milestone.new(raw['milestone'])
end
def author
@author ||= Github::Representation::User.new(raw['user'])
end
def assignee
return unless assigned?
@assignee ||= Github::Representation::User.new(raw['assignee'])
end
def state
raw['state'] == 'closed' ? 'closed' : 'opened'
end
def assigned?
raw['assignee'].present?
end
def has_comments?
raw['comments'] > 0
end

View File

@ -1,6 +1,6 @@
module Github
module Representation
class PullRequest < Representation::Base
class PullRequest < Representation::Issuable
attr_reader :project
delegate :user, :repo, :ref, :sha, to: :source_branch, prefix: true
@ -11,18 +11,6 @@ module Github
@raw = raw
end
def iid
raw['number']
end
def title
raw['title']
end
def description
raw['body'] || ''
end
def source_project
project
end
@ -48,22 +36,6 @@ module Github
@target_branch_name ||= target_branch_exists? ? target_branch_ref : target_branch_name_prefixed
end
def milestone
return unless raw['milestone'].present?
@milestone ||= Github::Representation::Milestone.new(raw['milestone'])
end
def author
@author ||= Github::Representation::User.new(raw['user'])
end
def assignee
return unless assigned?
@assignee ||= Github::Representation::User.new(raw['assignee'])
end
def state
return 'merged' if raw['state'] == 'closed' && raw['merged_at'].present?
return 'closed' if raw['state'] == 'closed'
@ -71,10 +43,6 @@ module Github
'opened'
end
def assigned?
raw['assignee'].present?
end
def opened?
state == 'opened'
end