Class: ObsDeploy::CheckDiff
- Inherits:
-
Object
- Object
- ObsDeploy::CheckDiff
- Defined in:
- lib/obs_deploy/check_diff.rb
Instance Method Summary collapse
- #about_url ⇒ Object
- #data_migrations ⇒ Object
- #github_diff ⇒ Object
- #has_data_migration? ⇒ Boolean
- #has_migration? ⇒ Boolean
-
#initialize(server: 'https://api.opensuse.org', product: 'SLE_12_SP4', project: 'OBS:Server:Unstable', target_server: 'https://api.opensuse.org') ⇒ CheckDiff
constructor
A new instance of CheckDiff.
- #migrations ⇒ Object
- #new_version_available? ⇒ Boolean
- #obs_running_commit ⇒ Object
- #package_commit ⇒ Object
- #package_url ⇒ Object
- #package_version ⇒ Object
Constructor Details
#initialize(server: 'https://api.opensuse.org', product: 'SLE_12_SP4', project: 'OBS:Server:Unstable', target_server: 'https://api.opensuse.org') ⇒ CheckDiff
Returns a new instance of CheckDiff.
5 6 7 8 9 10 |
# File 'lib/obs_deploy/check_diff.rb', line 5 def initialize(server: 'https://api.opensuse.org', product: 'SLE_12_SP4', project: 'OBS:Server:Unstable', target_server: 'https://api.opensuse.org') @server = server @product = product @project = project @target_server = target_server end |
Instance Method Details
#about_url ⇒ Object
62 63 64 |
# File 'lib/obs_deploy/check_diff.rb', line 62 def about_url URI("#{@target_server}/about") end |
#data_migrations ⇒ Object
46 47 48 49 50 |
# File 'lib/obs_deploy/check_diff.rb', line 46 def data_migrations return [] unless has_data_migration? github_diff.match(%r{db/data/.*\.rb}).to_a end |
#github_diff ⇒ Object
26 27 28 |
# File 'lib/obs_deploy/check_diff.rb', line 26 def github_diff Net::HTTP.get(URI("https://github.com/openSUSE/open-build-service/compare/#{obs_running_commit}...#{package_commit}.diff")) end |
#has_data_migration? ⇒ Boolean
40 41 42 43 44 |
# File 'lib/obs_deploy/check_diff.rb', line 40 def has_data_migration? return true if github_diff.nil? || github_diff.empty? github_diff.match(%r{db/data}) end |
#has_migration? ⇒ Boolean
34 35 36 37 38 |
# File 'lib/obs_deploy/check_diff.rb', line 34 def has_migration? return true if github_diff.nil? || github_diff.empty? GitDiffParser.parse(github_diff).files.any? { |f| f.match?(%r{db/migrate}) } end |
#migrations ⇒ Object
52 53 54 55 56 |
# File 'lib/obs_deploy/check_diff.rb', line 52 def migrations return [] unless has_migration? github_diff.match(%r{db/migrate/.*\.rb}).to_a end |
#new_version_available? ⇒ Boolean
30 31 32 |
# File 'lib/obs_deploy/check_diff.rb', line 30 def new_version_available? obs_running_commit != package_commit end |
#obs_running_commit ⇒ Object
21 22 23 24 |
# File 'lib/obs_deploy/check_diff.rb', line 21 def obs_running_commit doc = Nokogiri::XML(Net::HTTP.get(about_url)) doc.xpath('//commit/text()').to_s end |
#package_commit ⇒ Object
17 18 19 |
# File 'lib/obs_deploy/check_diff.rb', line 17 def package_commit package_version.match(/obs-api-.*\..*\..*\.(.*)-.*\.rpm/).captures.first end |
#package_url ⇒ Object
58 59 60 |
# File 'lib/obs_deploy/check_diff.rb', line 58 def package_url URI("#{@server}/public/build/#{@project}/#{@product}/x86_64/obs-server") end |
#package_version ⇒ Object
12 13 14 15 |
# File 'lib/obs_deploy/check_diff.rb', line 12 def package_version doc = Nokogiri::XML(Net::HTTP.get(package_url)) doc.xpath("//binary[starts-with(@filename, 'obs-api')]/@filename").to_s end |