summaryrefslogtreecommitdiff
path: root/lib/github/collection.rb
diff options
context:
space:
mode:
authorRuben Davila <rdavila84@gmail.com>2017-05-02 13:20:41 -0500
committerRuben Davila <rdavila84@gmail.com>2017-05-02 13:20:41 -0500
commitbbfbcebdf69261bac6aa142f430719955e8e86b9 (patch)
tree25916a1a761cb6c8fcdac4b20b76017a7f4506d3 /lib/github/collection.rb
parent3b82444eb7791e58e3e0ba2f08b8ccde48e3d4c6 (diff)
parent920d55b9f8afd35e16351fb57d671acf66092e89 (diff)
downloadgitlab-ce-bbfbcebdf69261bac6aa142f430719955e8e86b9.tar.gz
Merge branch 'master' into 28433-internationalise-cycle-analytics-page
Diffstat (limited to 'lib/github/collection.rb')
-rw-r--r--lib/github/collection.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/github/collection.rb b/lib/github/collection.rb
new file mode 100644
index 00000000000..014b2038c4b
--- /dev/null
+++ b/lib/github/collection.rb
@@ -0,0 +1,29 @@
+module Github
+ class Collection
+ attr_reader :options
+
+ def initialize(options)
+ @options = options
+ end
+
+ def fetch(url, query = {})
+ return [] if url.blank?
+
+ Enumerator.new do |yielder|
+ loop do
+ response = client.get(url, query)
+ response.body.each { |item| yielder << item }
+
+ raise StopIteration unless response.rels.key?(:next)
+ url = response.rels[:next]
+ end
+ end.lazy
+ end
+
+ private
+
+ def client
+ @client ||= Github::Client.new(options)
+ end
+ end
+end