diff options
author | Stan Hu <stanhu@gmail.com> | 2018-06-25 13:06:10 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-06-25 13:06:10 -0700 |
commit | ebd8e4333a263138abf2113dd315a97352851cbe (patch) | |
tree | 4e4975eab778d490c20c9252785761a1d78fae26 /lib/bitbucket_server/page.rb | |
parent | 2bac2918b2d6f12d94f739f4b6865b9e9221c642 (diff) | |
download | gitlab-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.rb | 34 |
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 |