summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-19 21:18:11 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-24 16:17:52 -0300
commit3c0a713a379025c079f8a684943e95af087c9e86 (patch)
treef35dd4098c5fe77a4df01816bfeb17906903eddf
parent3aa89795568dc2fbc53f2fac8c4f8ac3499dadb0 (diff)
downloadgitlab-ce-3c0a713a379025c079f8a684943e95af087c9e86.tar.gz
Import Github releases
-rw-r--r--lib/github/import.rb27
-rw-r--r--lib/github/representation/release.rb17
2 files changed, 44 insertions, 0 deletions
diff --git a/lib/github/import.rb b/lib/github/import.rb
index 12f4dbc9e43..4ef0ac3e40c 100644
--- a/lib/github/import.rb
+++ b/lib/github/import.rb
@@ -255,6 +255,33 @@ module Github
end
end
+ def fetch_releases
+ url = "/repos/#{repo}/releases"
+
+ while url
+ response = Github::Client.new(options).get(url)
+
+ response.body.each do |raw|
+ representation = Github::Representation::Release.new(raw)
+ next unless representation.valid?
+
+ release = ::Release.find_or_initialize_by(project_id: project.id, tag: representation.tag)
+ next unless relese.new_record?
+
+ begin
+ release.description = representation.description
+ release.created_at = representation.created_at
+ release.updated_at = representation.updated_at
+ release.save!(validate: false)
+ rescue => e
+ error(:release, representation.url, e.message)
+ end
+ end
+
+ url = response.rels[:next]
+ end
+ end
+
def restore_source_branch(pull_request)
repository.create_branch(pull_request.source_branch_name, pull_request.source_branch_sha)
end
diff --git a/lib/github/representation/release.rb b/lib/github/representation/release.rb
new file mode 100644
index 00000000000..e7e4b428c1a
--- /dev/null
+++ b/lib/github/representation/release.rb
@@ -0,0 +1,17 @@
+module Github
+ module Representation
+ class Release < Representation::Base
+ def description
+ raw['body']
+ end
+
+ def tag
+ raw['tag_name']
+ end
+
+ def valid?
+ !raw['draft']
+ end
+ end
+ end
+end