Extract Github::Representation::Issuable

parent f35573f1
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
module Github module Github
module Representation module Representation
class Issue < Representation::Base class Issue < Representation::Issuable
def iid
raw['number']
end
def title
raw['title']
end
def description
raw['body'] || ''
end
def labels def labels
raw['labels'] raw['labels']
end 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 def state
raw['state'] == 'closed' ? 'closed' : 'opened' raw['state'] == 'closed' ? 'closed' : 'opened'
end end
def assigned?
raw['assignee'].present?
end
def has_comments? def has_comments?
raw['comments'] > 0 raw['comments'] > 0
end end
......
module Github module Github
module Representation module Representation
class PullRequest < Representation::Base class PullRequest < Representation::Issuable
attr_reader :project attr_reader :project
delegate :user, :repo, :ref, :sha, to: :source_branch, prefix: true delegate :user, :repo, :ref, :sha, to: :source_branch, prefix: true
...@@ -11,18 +11,6 @@ module Github ...@@ -11,18 +11,6 @@ module Github
@raw = raw @raw = raw
end end
def iid
raw['number']
end
def title
raw['title']
end
def description
raw['body'] || ''
end
def source_project def source_project
project project
end end
...@@ -48,22 +36,6 @@ module Github ...@@ -48,22 +36,6 @@ module Github
@target_branch_name ||= target_branch_exists? ? target_branch_ref : target_branch_name_prefixed @target_branch_name ||= target_branch_exists? ? target_branch_ref : target_branch_name_prefixed
end 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 def state
return 'merged' if raw['state'] == 'closed' && raw['merged_at'].present? return 'merged' if raw['state'] == 'closed' && raw['merged_at'].present?
return 'closed' if raw['state'] == 'closed' return 'closed' if raw['state'] == 'closed'
...@@ -71,10 +43,6 @@ module Github ...@@ -71,10 +43,6 @@ module Github
'opened' 'opened'
end end
def assigned?
raw['assignee'].present?
end
def opened? def opened?
state == 'opened' state == 'opened'
end end
......
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