Use while instead of loop/break

parent 18144530
...@@ -54,14 +54,12 @@ module Github ...@@ -54,14 +54,12 @@ module Github
# Fetch labels # Fetch labels
url = "/repos/#{owner}/#{repo}/labels" url = "/repos/#{owner}/#{repo}/labels"
loop do while url
response = Github::Client.new(options).get(url) response = Github::Client.new(options).get(url)
response.body.each do |raw| response.body.each do |raw|
begin begin
label = Github::Representation::Label.new(raw) label = Github::Representation::Label.new(raw)
# TODO: we should take group labels in account
next if project.labels.where(title: label.title).exists? next if project.labels.where(title: label.title).exists?
project.labels.create!(title: label.title, color: label.color) project.labels.create!(title: label.title, color: label.color)
...@@ -70,7 +68,7 @@ module Github ...@@ -70,7 +68,7 @@ module Github
end end
end end
break unless url = response.rels[:next] url = response.rels[:next]
end end
# Cache labels # Cache labels
...@@ -82,7 +80,7 @@ module Github ...@@ -82,7 +80,7 @@ module Github
# Fetch milestones # Fetch milestones
url = "/repos/#{owner}/#{repo}/milestones" url = "/repos/#{owner}/#{repo}/milestones"
loop do while url
response = Github::Client.new(options).get(url, state: :all) response = Github::Client.new(options).get(url, state: :all)
response.body.each do |raw| response.body.each do |raw|
...@@ -104,13 +102,13 @@ module Github ...@@ -104,13 +102,13 @@ module Github
end end
end end
break unless url = response.rels[:next] url = response.rels[:next]
end end
# Fetch pull requests # Fetch pull requests
url = "/repos/#{owner}/#{repo}/pulls" url = "/repos/#{owner}/#{repo}/pulls"
loop do while url
response = Github::Client.new(options).get(url, state: :all, sort: :created, direction: :asc) response = Github::Client.new(options).get(url, state: :all, sort: :created, direction: :asc)
response.body.each do |raw| response.body.each do |raw|
...@@ -156,13 +154,13 @@ module Github ...@@ -156,13 +154,13 @@ module Github
end end
end end
break unless url = response.rels[:next] url = response.rels[:next]
end end
# Fetch issues # Fetch issues
url = "/repos/#{owner}/#{repo}/issues" url = "/repos/#{owner}/#{repo}/issues"
loop do while url
response = Github::Client.new(options).get(url, state: :all, sort: :created, direction: :asc) response = Github::Client.new(options).get(url, state: :all, sort: :created, direction: :asc)
response.body.each do |raw| response.body.each do |raw|
...@@ -207,7 +205,7 @@ module Github ...@@ -207,7 +205,7 @@ module Github
end end
end end
break unless url = response.rels[:next] url = response.rels[:next]
end end
repository.expire_content_cache repository.expire_content_cache
...@@ -218,7 +216,7 @@ module Github ...@@ -218,7 +216,7 @@ module Github
private private
def fetch_comments(noteable, type, url) def fetch_comments(noteable, type, url)
loop do while url
comments = Github::Client.new(options).get(url) comments = Github::Client.new(options).get(url)
ActiveRecord::Base.no_touching do ActiveRecord::Base.no_touching do
...@@ -244,7 +242,7 @@ module Github ...@@ -244,7 +242,7 @@ module Github
end end
end end
break unless url = comments.rels[:next] url = comments.rels[:next]
end end
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