diffend 0.2.40 → 0.2.41

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.github/workflows/ci.yml +2 -0
  5. data/CHANGELOG.md +2 -0
  6. data/Gemfile.lock +1 -1
  7. data/Rakefile +40 -0
  8. data/lib/diffend/errors.rb +2 -0
  9. data/lib/diffend/handle_errors/report.rb +4 -4
  10. data/lib/diffend/integration_repository.rb +92 -0
  11. data/lib/diffend/local_context/packages.rb +6 -2
  12. data/lib/diffend/plugin.rb +3 -0
  13. data/lib/diffend/repository.rb +109 -0
  14. data/lib/diffend/request_object.rb +1 -1
  15. data/lib/diffend/request_verdict.rb +4 -4
  16. data/lib/diffend/shell.rb +44 -0
  17. data/lib/diffend/track.rb +4 -4
  18. data/lib/diffend/version.rb +1 -1
  19. data/repositories/.diffend.yml +3 -0
  20. data/repositories/bundler_2_1_4/install_with_gemfile_lock/.diffend.yml +3 -0
  21. data/repositories/bundler_2_1_4/install_with_gemfile_lock/Gemfile +6 -0
  22. data/repositories/bundler_2_1_4/install_with_gemfile_lock/Gemfile.lock +22 -0
  23. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_added_gem/.diffend.yml +3 -0
  24. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_added_gem/Gemfile +6 -0
  25. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_added_gem/Gemfile.lock +16 -0
  26. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_changed_gem_version/.diffend.yml +3 -0
  27. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_changed_gem_version/Gemfile +6 -0
  28. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_changed_gem_version/Gemfile.lock +18 -0
  29. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_changed_gem_version/README.md +1 -0
  30. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_locked_gem_version/.diffend.yml +3 -0
  31. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_locked_gem_version/Gemfile +6 -0
  32. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_locked_gem_version/Gemfile.lock +19 -0
  33. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_removed_gem/.diffend.yml +3 -0
  34. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_removed_gem/Gemfile +5 -0
  35. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_removed_gem/Gemfile.lock +43 -0
  36. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_two_platforms/.diffend.yml +3 -0
  37. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_two_platforms/.ruby-version +1 -0
  38. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_two_platforms/Gemfile +10 -0
  39. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_two_platforms/Gemfile.lock +32 -0
  40. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_two_platforms/gem-with-two-platforms.gemspec +16 -0
  41. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_two_primary_sources/.diffend.yml +3 -0
  42. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_two_primary_sources/Gemfile +6 -0
  43. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_two_primary_sources/Gemfile.lock +17 -0
  44. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_two_sources/.diffend.yml +3 -0
  45. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_two_sources/Gemfile +6 -0
  46. data/repositories/bundler_2_1_4/install_with_gemfile_lock_with_two_sources/Gemfile.lock +19 -0
  47. data/repositories/bundler_2_1_4/install_without_gemfile_lock/.diffend.yml +3 -0
  48. data/repositories/bundler_2_1_4/install_without_gemfile_lock/Gemfile +5 -0
  49. data/repositories/bundler_2_1_4/update_with_gemfile_lock/.diffend.yml +3 -0
  50. data/repositories/bundler_2_1_4/update_with_gemfile_lock/Gemfile +5 -0
  51. data/repositories/bundler_2_1_4/update_with_gemfile_lock/Gemfile.lock +16 -0
  52. data/repositories/bundler_2_1_4/update_with_gemfile_lock/README.md +1 -0
  53. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_added_gem/.diffend.yml +3 -0
  54. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_added_gem/Gemfile +6 -0
  55. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_added_gem/Gemfile.lock +16 -0
  56. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_added_gem/README.md +1 -0
  57. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_removed_gem/.diffend.yml +3 -0
  58. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_removed_gem/Gemfile +5 -0
  59. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_removed_gem/Gemfile.lock +43 -0
  60. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_removed_gem/README.md +1 -0
  61. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_two_primary_sources/.diffend.yml +3 -0
  62. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_two_primary_sources/Gemfile +6 -0
  63. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_two_primary_sources/Gemfile.lock +17 -0
  64. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_two_primary_sources/README.md +1 -0
  65. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_two_sources/.diffend.yml +3 -0
  66. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_two_sources/Gemfile +6 -0
  67. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_two_sources/Gemfile.lock +44 -0
  68. data/repositories/bundler_2_1_4/update_with_gemfile_lock_with_two_sources/README.md +1 -0
  69. data/repositories/bundler_2_1_4/update_without_gemfile_lock/.diffend.yml +3 -0
  70. data/repositories/bundler_2_1_4/update_without_gemfile_lock/Gemfile +5 -0
  71. data/repositories/bundler_2_1_4/update_without_gemfile_lock/README.md +1 -0
  72. data/repositories/bundler_2_2_7/install_with_gemfile_lock/.diffend.yml +3 -0
  73. data/repositories/bundler_2_2_7/install_with_gemfile_lock/Gemfile +6 -0
  74. data/repositories/bundler_2_2_7/install_with_gemfile_lock/Gemfile.lock +21 -0
  75. data/repositories/bundler_2_2_7/install_with_gemfile_lock/README.md +1 -0
  76. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_added_gem/.diffend.yml +3 -0
  77. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_added_gem/Gemfile +6 -0
  78. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_added_gem/Gemfile.lock +16 -0
  79. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_added_gem/README.md +1 -0
  80. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_changed_gem_version/.diffend.yml +3 -0
  81. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_changed_gem_version/Gemfile +6 -0
  82. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_changed_gem_version/Gemfile.lock +18 -0
  83. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_changed_gem_version/README.md +1 -0
  84. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_locked_gem_version/.diffend.yml +3 -0
  85. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_locked_gem_version/Gemfile +6 -0
  86. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_locked_gem_version/Gemfile.lock +18 -0
  87. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_locked_gem_version/README.md +1 -0
  88. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_removed_gem/.diffend.yml +3 -0
  89. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_removed_gem/Gemfile +5 -0
  90. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_removed_gem/Gemfile.lock +41 -0
  91. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_removed_gem/README.md +1 -0
  92. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_two_platforms/.diffend.yml +3 -0
  93. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_two_platforms/Gemfile +10 -0
  94. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_two_platforms/Gemfile.lock +30 -0
  95. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_two_platforms/README.md +1 -0
  96. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_two_platforms/gem-with-two-platforms.gemspec +16 -0
  97. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_two_primary_sources/.diffend.yml +3 -0
  98. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_two_primary_sources/Gemfile +6 -0
  99. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_two_primary_sources/Gemfile.lock +17 -0
  100. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_two_primary_sources/README.md +1 -0
  101. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_two_sources/.diffend.yml +3 -0
  102. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_two_sources/Gemfile +6 -0
  103. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_two_sources/Gemfile.lock +19 -0
  104. data/repositories/bundler_2_2_7/install_with_gemfile_lock_with_two_sources/README.md +1 -0
  105. data/repositories/bundler_2_2_7/install_without_gemfile_lock/.diffend.yml +3 -0
  106. data/repositories/bundler_2_2_7/install_without_gemfile_lock/Gemfile +5 -0
  107. data/repositories/bundler_2_2_7/install_without_gemfile_lock/README.md +1 -0
  108. data/repositories/bundler_2_2_7/update_with_gemfile_lock/.diffend.yml +3 -0
  109. data/repositories/bundler_2_2_7/update_with_gemfile_lock/Gemfile +5 -0
  110. data/repositories/bundler_2_2_7/update_with_gemfile_lock/Gemfile.lock +16 -0
  111. data/repositories/bundler_2_2_7/update_with_gemfile_lock/README.md +1 -0
  112. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_added_gem/.diffend.yml +3 -0
  113. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_added_gem/Gemfile +6 -0
  114. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_added_gem/Gemfile.lock +16 -0
  115. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_added_gem/README.md +1 -0
  116. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_changed_gem_version/Gemfile +6 -0
  117. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_changed_gem_version/Gemfile.lock +18 -0
  118. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_changed_gem_version/README.md +1 -0
  119. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_locked_gem_version/Gemfile +6 -0
  120. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_locked_gem_version/Gemfile.lock +18 -0
  121. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_locked_gem_version/README.md +1 -0
  122. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_removed_gem/.diffend.yml +3 -0
  123. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_removed_gem/Gemfile +5 -0
  124. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_removed_gem/Gemfile.lock +41 -0
  125. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_two_primary_sources/.diffend.yml +3 -0
  126. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_two_primary_sources/Gemfile +6 -0
  127. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_two_primary_sources/Gemfile.lock +17 -0
  128. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_two_primary_sources/README.md +1 -0
  129. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_two_sources/.diffend.yml +3 -0
  130. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_two_sources/Gemfile +6 -0
  131. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_two_sources/Gemfile.lock +42 -0
  132. data/repositories/bundler_2_2_7/update_with_gemfile_lock_with_two_sources/README.md +1 -0
  133. data/repositories/bundler_2_2_7/update_without_gemfile_lock/.diffend.yml +3 -0
  134. data/repositories/bundler_2_2_7/update_without_gemfile_lock/Gemfile +5 -0
  135. data/repositories/diffend.json +9 -0
  136. metadata +123 -2
  137. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab9ba402e382256b6318f8a4b278ae8e6ae0e68dc9ab15fedca98b8e46f8a105
4
- data.tar.gz: 7f0fa88a9af55b5b7d2992fa67fcde7f464f36b68801f4b69b3d0204033428df
3
+ metadata.gz: cc35a87fc80048201e46cf210e72c4359849b9c17b3208a885e151c2384be274
4
+ data.tar.gz: c438271e070263543f0cc7ae84911631bc8f57dd4804d2fe58d529caf7929e49
5
5
  SHA512:
6
- metadata.gz: e41cad9b056aed9f846424964a14862cf5dfeab3596b93673bf7ed9ceacc50beab92157cfe8b98aa4a35c8bce5341862c79e6a35ae03fdc754a85eeb730b7077
7
- data.tar.gz: dfd06d10e56962b7ffa3eca0530b8b7fcaa9bb83169c2bd52e672a957de9dba22dd63f2dd91c3d90441c466256446d4609c293e028e75deaa66db28f47fccbfc
6
+ metadata.gz: 6e41e7343c6c0f1137dab1999ceebc1c8df54c2950e92f68b592d4f2b03c5fc2e5817b9443068423f2ea1508cc78884c169a4551a61e2723bb5c931d6ce05ed4
7
+ data.tar.gz: 877952bdb836a09034b0e72862cf374a8049a46ee4b416125beaad3a9102b14a1d22878b4128e6efded825d0bc896fcf1873f046f111da9d5ced03907c2d3a1b
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -48,6 +48,8 @@ jobs:
48
48
  env:
49
49
  GITHUB_COVERAGE: ${{matrix.coverage}}
50
50
  run: bundle _${{matrix.bundler}}_ exec rspec
51
+ - name: Run integration tests
52
+ run: bundle _${{matrix.bundler}}_ exec rake integration_suite
51
53
 
52
54
  diffend:
53
55
  runs-on: ubuntu-latest
data/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Changelog
2
2
 
3
3
  ## [Unreleased][master]
4
+ - introduce integration specs ([#107](https://github.com/diffend-io/diffend-ruby/pull/107))
5
+ - use `Bundler::Definition.resolve` for specs ([#112](https://github.com/diffend-io/diffend-ruby/pull/112))
4
6
 
5
7
  ## [0.2.40] (2021-02-23)
6
8
  - don't expose ips, we can identify instance by a hostname ([#108](https://github.com/diffend-io/diffend-ruby/pull/108))
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- diffend (0.2.40)
4
+ diffend (0.2.41)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w[
4
+ bundler/setup
5
+ ].each(&method(:require))
6
+
7
+ require 'diffend/errors'
8
+ require 'diffend/config'
9
+ require 'diffend/shell'
10
+ require 'diffend/repository'
11
+ require 'diffend/integration_repository'
12
+
13
+ task :integration_suite do
14
+ Diffend::Repository::SUPPORTED.each do |command, repositories|
15
+ repositories.each do |repository_name|
16
+ repository = Diffend::IntegrationRepository.new(command, repository_name)
17
+ repository.repository.isolate do |path|
18
+ start = Time.now.to_f
19
+
20
+ repository.config?(path)
21
+
22
+ Bundler.with_unbundled_env do
23
+ repository.install_plugin(path)
24
+
25
+ cmd = Diffend::Shell.call_in_path(path, "bundle #{command}")
26
+
27
+ unless cmd[:exit_code].zero?
28
+ puts "#{repository.full_name} FAILED"
29
+ puts cmd[:stderr]
30
+ exit 1
31
+ end
32
+ end
33
+
34
+ took = Time.now.to_f - start
35
+
36
+ puts "#{repository.full_name} OK, took #{took.round(1)}s"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -21,5 +21,7 @@ module Diffend
21
21
  HandledException = Class.new(BaseError)
22
22
  # Raised when we are unable to resolve dependencies
23
23
  DependenciesResolveException = Class.new(BaseError)
24
+ # Failure of a shell command execution
25
+ FailedShellCommand = Class.new(BaseError)
24
26
  end
25
27
  end
@@ -39,10 +39,10 @@ module Diffend
39
39
  # @return [Diffend::RequestObject]
40
40
  def build_request_object(config, payload)
41
41
  Diffend::RequestObject.new(
42
- config: config,
43
- url: config.errors_url,
44
- payload: payload,
45
- request_method: :post
42
+ config,
43
+ config.errors_url,
44
+ payload,
45
+ :post
46
46
  )
47
47
  end
48
48
 
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Diffend
4
+ # Repository for integrations
5
+ class IntegrationRepository
6
+ # Plugin code entry in Gemfile
7
+ GEMFILE_PLUGIN_ENTRY = 'plugin \'diffend\''
8
+ # Gemfile file name
9
+ GEMFILE_FILE_NAME = 'Gemfile'
10
+ # Gemfile backup file name
11
+ GEMFILE_BACKUP_FILE_NAME = 'Gemfile.backup'
12
+ # Plugin install command
13
+ PLUGIN_INSTALL_COMMAND = 'bundle plugin install diffend'
14
+
15
+ attr_reader :command, :name, :repository
16
+
17
+ # @param command [String] command executed via bundler
18
+ # @param name [String] repository name
19
+ def initialize(command, name)
20
+ @command = command
21
+ @name = name
22
+ @repository = Diffend::Repository.new(command, name)
23
+ end
24
+
25
+ # @return [String] full name of the repository with command
26
+ def full_name
27
+ "#{command}_#{name}"
28
+ end
29
+
30
+ # @param path [String] path to the repository
31
+ def config?(path)
32
+ # check if .diffend.yml exists
33
+ return if File.exist?(File.join(path, Diffend::Config::FILENAME))
34
+
35
+ puts "Diffend configuration does not exist for #{command} #{name}"
36
+ exit 1
37
+ end
38
+
39
+ # @param path [String] path to the repository
40
+ def install_plugin(path)
41
+ cmd = Diffend::Shell.call_in_path(path, PLUGIN_INSTALL_COMMAND)
42
+
43
+ unless cmd[:exit_code].zero?
44
+ puts "#{PLUGIN_INSTALL_COMMAND} failed"
45
+ puts cmd[:stderr]
46
+ exit 1
47
+ end
48
+
49
+ switch_plugin_to_development(path, cmd[:stdout])
50
+ add_plugin_to_gemfile(path)
51
+ end
52
+
53
+ private
54
+
55
+ # @param path [String] path to the repository
56
+ # @param stdout [String] stdout from plugin install command
57
+ def switch_plugin_to_development(path, stdout)
58
+ installed_version = stdout.scan(/Installing diffend (\d*\.\d*\.\d*)/)[0][0]
59
+ diffend_working_path = File.expand_path('..', Bundler.bin_path)
60
+ bundler_plugins_path = File.join(path, '.bundle/plugin/gems')
61
+ bundler_diffend_plugin_path = File.join(bundler_plugins_path, "diffend-#{installed_version}")
62
+ FileUtils.mv(bundler_diffend_plugin_path, "#{bundler_diffend_plugin_path}-")
63
+ FileUtils.ln_s(diffend_working_path, bundler_diffend_plugin_path)
64
+ end
65
+
66
+ # @param path [String] path to the repository
67
+ def add_plugin_to_gemfile(path)
68
+ gemfile_path = File.join(path, GEMFILE_FILE_NAME)
69
+
70
+ FileUtils.mv(gemfile_path, File.join(path, GEMFILE_BACKUP_FILE_NAME))
71
+ file = File.open(gemfile_path, 'w')
72
+ source_detected = nil
73
+
74
+ File.readlines(
75
+ File.join(path, GEMFILE_BACKUP_FILE_NAME)
76
+ ).each do |line|
77
+ if line.start_with?('source') && source_detected.nil?
78
+ source_detected = true
79
+ elsif source_detected
80
+ source_detected = false
81
+ file.write("\n#{GEMFILE_PLUGIN_ENTRY}\n")
82
+ end
83
+
84
+ file.write(line)
85
+ end
86
+
87
+ file.close
88
+
89
+ FileUtils.rm(File.join(path, GEMFILE_BACKUP_FILE_NAME))
90
+ end
91
+ end
92
+ end
@@ -71,7 +71,9 @@ module Diffend
71
71
  def build_install
72
72
  hash = build_main
73
73
 
74
- @definition.specs.each do |spec|
74
+ @definition.resolve.each do |spec|
75
+ # Skip metadata
76
+ next if spec.instance_variable_get(:@specification).nil?
75
77
  next if skip?(spec.source)
76
78
 
77
79
  locked_spec = @locked_specs.find { |s| s.name == spec.name }
@@ -93,7 +95,9 @@ module Diffend
93
95
  def build_update
94
96
  hash = build_main
95
97
 
96
- @definition.specs.each do |spec|
98
+ @definition.resolve.each do |spec|
99
+ # Skip metadata
100
+ next if spec.instance_variable_get(:@specification).nil?
97
101
  next if skip?(spec.source)
98
102
 
99
103
  locked_spec = @locked_specs.find { |s| s.name == spec.name }
@@ -30,6 +30,9 @@
30
30
  request_verdict
31
31
  execute
32
32
  track
33
+ shell
34
+ repository
35
+ integration_repository
33
36
  ].each { |file| require "diffend/#{file}" }
34
37
 
35
38
  module Diffend
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w[
4
+ tmpdir
5
+ securerandom
6
+ ].each(&method(:require))
7
+
8
+ module Diffend
9
+ # Repository for specs
10
+ class Repository
11
+ # Repositories path
12
+ REPOSITORIES_PATH = File.join(
13
+ File.expand_path('..', Bundler.bin_path),
14
+ 'repositories'
15
+ ).freeze
16
+ # List of supported repositories split by command
17
+ SUPPORTED = {
18
+ 'install' => %w[
19
+ with_gemfile_lock
20
+ with_gemfile_lock_with_added_gem
21
+ with_gemfile_lock_with_changed_gem_version
22
+ with_gemfile_lock_with_locked_gem_version
23
+ with_gemfile_lock_with_removed_gem
24
+ with_gemfile_lock_with_two_platforms
25
+ with_gemfile_lock_with_two_primary_sources
26
+ with_gemfile_lock_with_two_sources
27
+ without_gemfile_lock
28
+ ].freeze,
29
+ 'update' => %w[
30
+ with_gemfile_lock
31
+ with_gemfile_lock_with_added_gem
32
+ with_gemfile_lock_with_removed_gem
33
+ with_gemfile_lock_with_two_primary_sources
34
+ with_gemfile_lock_with_two_sources
35
+ without_gemfile_lock
36
+ ].freeze
37
+ }.freeze
38
+
39
+ attr_reader :name, :path
40
+
41
+ # @param command [String] command executed via bundler
42
+ # @param name [String] repository name
43
+ def initialize(command, name)
44
+ @command = command
45
+ @name = name
46
+ @path = File.join(Dir.tmpdir, SecureRandom.uuid)
47
+ end
48
+
49
+ # Build repository path
50
+ #
51
+ # @return [String]
52
+ def orig_path
53
+ @orig_path ||= global_file_path(
54
+ File.join(
55
+ bundler_version_string,
56
+ "#{@command}_#{name}"
57
+ )
58
+ )
59
+ end
60
+
61
+ # Setup an isolated instance of a repository
62
+ def setup
63
+ FileUtils.cp_r(orig_path, path)
64
+ end
65
+
66
+ # Clean isolated instance of a repository
67
+ def clean
68
+ FileUtils.rm_rf(path)
69
+ end
70
+
71
+ # Execute tasks in an isolated instance of a repository
72
+ def isolate
73
+ setup
74
+ yield(path)
75
+ clean
76
+ end
77
+
78
+ # Build the path to a specified file within the repository
79
+ #
80
+ # @param file_name [String]
81
+ #
82
+ # @return [String]
83
+ def file_path(file_name)
84
+ File.join(
85
+ path,
86
+ file_name
87
+ )
88
+ end
89
+
90
+ # Build global path
91
+ #
92
+ # @param file_name [String]
93
+ #
94
+ # @return [String]
95
+ def global_file_path(file_name)
96
+ File.join(
97
+ REPOSITORIES_PATH,
98
+ file_name
99
+ )
100
+ end
101
+
102
+ # Build bundler version string
103
+ #
104
+ # @return [String]
105
+ def bundler_version_string
106
+ @bundler_version_string ||= "bundler_#{Bundler::VERSION.tr('.', '_')}"
107
+ end
108
+ end
109
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Diffend
4
4
  # Class responsible for preparing diffend request object
5
- RequestObject = Struct.new(:config, :url, :payload, :request_method, keyword_init: true)
5
+ RequestObject = Struct.new(:config, :url, :payload, :request_method)
6
6
  end
@@ -42,10 +42,10 @@ module Diffend
42
42
  # @return [Diffend::RequestObject]
43
43
  def build_request_object(config, payload)
44
44
  Diffend::RequestObject.new(
45
- config: config,
46
- url: config.commands_url,
47
- payload: payload,
48
- request_method: :post
45
+ config,
46
+ config.commands_url,
47
+ payload,
48
+ :post
49
49
  )
50
50
  end
51
51
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+
5
+ # Helper commands for running Linux shell commands
6
+ module Diffend
7
+ module Shell
8
+ class << self
9
+ # Allows to execute shell commands and handle errors, etc later
10
+ # (won't raise any errors but instead will catch all things)
11
+ # @param command_with_options [String] command that should be executed with
12
+ # all the arguments and options
13
+ # @param raise_on_invalid_exit [Boolean] raise exception when exit code is not 0
14
+ # @return [Hash] hash with 3 keys describing output
15
+ # (stdout, stderr, exit_code)
16
+ # @example Run ls
17
+ # SupportEngine::Shell.('ls') =>
18
+ # { stdout: "test.rb\n", stderr: '', exit_code: 0}
19
+ def call(command_with_options, raise_on_invalid_exit: true)
20
+ stdout_str, stderr_str, status = Open3.capture3(command_with_options)
21
+
22
+ result = {
23
+ stdout: stdout_str,
24
+ stderr: stderr_str,
25
+ exit_code: status.exitstatus
26
+ }
27
+
28
+ raise Diffend::Errors::FailedShellCommand, result.values.join(': ') \
29
+ if raise_on_invalid_exit && result[:exit_code] != 0
30
+
31
+ result
32
+ end
33
+
34
+ # @param path [String, Pathname] to a place where git repo is
35
+ # @param command [String] that we want to execute in path context
36
+ # @param raise_on_invalid_exit [Boolean] raise exception when exit code is not 0
37
+ # @return [Hash] hash with 3 keys describing output (stdout, stderr, exit_code)
38
+ def call_in_path(path, command, raise_on_invalid_exit: true)
39
+ command = ['cd', path.to_s, '&&', command]
40
+ call(command.join(' '), raise_on_invalid_exit: raise_on_invalid_exit)
41
+ end
42
+ end
43
+ end
44
+ end
data/lib/diffend/track.rb CHANGED
@@ -62,10 +62,10 @@ module Diffend
62
62
  # @return [Diffend::RequestObject]
63
63
  def build_request_object(request_id)
64
64
  Diffend::RequestObject.new(
65
- config: @config,
66
- url: @config.track_url(request_id),
67
- payload: { id: request_id }.freeze,
68
- request_method: :put
65
+ @config,
66
+ @config.track_url(request_id),
67
+ { id: request_id }.freeze,
68
+ :put
69
69
  ).freeze
70
70
  end
71
71
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Diffend
4
4
  # Current version
5
- VERSION = '0.2.40'
5
+ VERSION = '0.2.41'
6
6
  end