summaryrefslogtreecommitdiff
path: root/lib/github
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-19 19:17:42 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-24 16:17:52 -0300
commit00e3d60c3d0ad1b6c981e3069d8b815d5119aa90 (patch)
tree4d97a35c1d19b0c5051d9ad985d827bf744b0e7a /lib/github
parentf35573f12eb579b31b014fa99509c694021c33c7 (diff)
downloadgitlab-ce-00e3d60c3d0ad1b6c981e3069d8b815d5119aa90.tar.gz
Extract Github::Representation::Issuable
Diffstat (limited to 'lib/github')
-rw-r--r--lib/github/representation/issuable.rb37
-rw-r--r--lib/github/representation/issue.rb34
-rw-r--r--lib/github/representation/pull_request.rb34
3 files changed, 39 insertions, 66 deletions
diff --git a/lib/github/representation/issuable.rb b/lib/github/representation/issuable.rb
new file mode 100644
index 00000000000..a55976f9019
--- /dev/null
+++ b/lib/github/representation/issuable.rb
@@ -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
diff --git a/lib/github/representation/issue.rb b/lib/github/representation/issue.rb
index 3bb767a5daa..df3540a6e6c 100644
--- a/lib/github/representation/issue.rb
+++ b/lib/github/representation/issue.rb
@@ -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
diff --git a/lib/github/representation/pull_request.rb b/lib/github/representation/pull_request.rb
index b33561565bf..0596b0425a2 100644
--- a/lib/github/representation/pull_request.rb
+++ b/lib/github/representation/pull_request.rb
@@ -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