From 3c0a713a379025c079f8a684943e95af087c9e86 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Wed, 19 Apr 2017 21:18:11 -0300 Subject: Import Github releases --- lib/github/import.rb | 27 +++++++++++++++++++++++++++ lib/github/representation/release.rb | 17 +++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 lib/github/representation/release.rb (limited to 'lib/github') 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 -- cgit v1.2.1