Class: ObsDeploy::CheckDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/obs_deploy/check_diff.rb

Instance Method Summary collapse

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_urlObject



62
63
64
# File 'lib/obs_deploy/check_diff.rb', line 62

def about_url
  URI("#{@target_server}/about")
end

#data_migrationsObject



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_diffObject



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

Returns:

  • (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

Returns:

  • (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

#migrationsObject



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

Returns:

  • (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_commitObject



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_commitObject



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_urlObject



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_versionObject



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