summaryrefslogtreecommitdiff
path: root/lib/bitbucket_server/page.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-06-25 13:06:10 -0700
committerStan Hu <stanhu@gmail.com>2018-06-25 13:06:10 -0700
commitebd8e4333a263138abf2113dd315a97352851cbe (patch)
tree4e4975eab778d490c20c9252785761a1d78fae26 /lib/bitbucket_server/page.rb
parent2bac2918b2d6f12d94f739f4b6865b9e9221c642 (diff)
downloadgitlab-ce-ebd8e4333a263138abf2113dd315a97352851cbe.tar.gz
WIP: Add support for Bitbucket Server imports
Diffstat (limited to 'lib/bitbucket_server/page.rb')
-rw-r--r--lib/bitbucket_server/page.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/bitbucket_server/page.rb b/lib/bitbucket_server/page.rb
new file mode 100644
index 00000000000..17be8cbb860
--- /dev/null
+++ b/lib/bitbucket_server/page.rb
@@ -0,0 +1,34 @@
+module BitbucketServer
+ class Page
+ attr_reader :attrs, :items
+
+ def initialize(raw, type)
+ @attrs = parse_attrs(raw)
+ @items = parse_values(raw, representation_class(type))
+ end
+
+ def next?
+ !attrs.fetch(:isLastPage, true)
+ end
+
+ def next
+ attrs.fetch(:nextPageStart)
+ end
+
+ private
+
+ def parse_attrs(raw)
+ raw.slice(*%w(size nextPageStart isLastPage)).symbolize_keys
+ end
+
+ def parse_values(raw, bitbucket_rep_class)
+ return [] unless raw['values'] && raw['values'].is_a?(Array)
+
+ bitbucket_rep_class.decorate(raw['values'])
+ end
+
+ def representation_class(type)
+ BitbucketServer::Representation.const_get(type.to_s.camelize)
+ end
+ end
+end