overrides_tracker 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de906983bd67adacd693b79f6171a0a3926b55e50938914c3edb552fd9fccdda
4
- data.tar.gz: ade3eb37f8c485ac26e3d3b5f1c35429ebf66b8c889400f605625d21f0e59231
3
+ metadata.gz: 22c40f48f04af34f145bc26c68acf9ebc52913bb814f21dd1a98cd687c61237c
4
+ data.tar.gz: 2b50d662098bdeb7cd06597ff674ee82f9b1e69d2dc181e2e8a782578afe391c
5
5
  SHA512:
6
- metadata.gz: abf5002371dffaeebceec5accf867ee11112d70b8e394136246c7ec4cee42d5ed2ea672e4f7f165fd1338bf174463fffd4e101582b83137bc38d26bb0e3585ac
7
- data.tar.gz: 22869fe1494e6098e5f3cecbd055873cd81f65edb8f22f7f1e298a95b3e3b8901ebfac0f93be6dbdce73bb99128ac1fa9db08306f18cbb35a528f2b9d5713ea7
6
+ metadata.gz: 50a5c5811f4511385fc0e564c6bfe0c12d40e764bd1eb7af84ddd3057adfa1ed2b1df17af2e1fc7aa032a17956aafeb76473591312aa366ccca9695c60080d4b
7
+ data.tar.gz: ebda84d5c5c899deb6fc323e28a3c74e513471839741cf77a64d8656ad56a325e9449cb500b09ed39781f6b3bb760de25fa29a2a2ba94e19209701491d748b8c
data/Gemfile CHANGED
@@ -4,3 +4,11 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in overrides_tracker.gemspec
6
6
  gemspec
7
+
8
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9')
9
+ gem 'vcr', '~> 2.9'
10
+ gem 'webmock', '~> 1.20'
11
+ else
12
+ gem 'vcr', '>= 2.9'
13
+ gem 'webmock', '>= 1.20'
14
+ end
@@ -7,7 +7,34 @@ if ARGV[0] == "track"
7
7
  require 'overrides_tracker'
8
8
  OverridesTracker::MethodsCollector.instance.save_to_file
9
9
 
10
+ if ENV['OVERRIDES_API_TOKEN']
11
+ OverridesTracker::MethodsCollector.instance.report(ENV['OVERRIDES_API_TOKEN'])
12
+ elsif !ARGV[1].nil?
13
+ OverridesTracker::MethodsCollector.instance.report(ARGV[1])
14
+ else
15
+ #puts 'No OVERRIDES_API_TOKEN was set. The report will not be uploaded to overrides.io.'
16
+ #puts ''
17
+ #puts 'Have no idea what overrides.io is about? Check it out at https://www.overrides.com'
18
+ end
19
+
10
20
  elsif ARGV[0] == "compare"
11
21
  require 'overrides_tracker'
12
22
  OverridesTracker::Comparer.compare
23
+
24
+ unless ENV['OVERRIDES_API_TOKEN']
25
+ puts ''
26
+ #puts 'Have you heard of overrides.io?'
27
+ #puts 'It integrates with your CI pipeline and notifies you whenever original methods are changing or disappearing.'
28
+ #puts 'Check it out at https://www.overrides.com'
29
+ end
30
+ elsif ARGV[0] == "report"
31
+ require 'overrides_tracker'
32
+
33
+ if ENV['OVERRIDES_API_TOKEN']
34
+ OverridesTracker::MethodsCollector.instance.report(ENV['OVERRIDES_API_TOKEN'])
35
+ elsif !ARGV[1].nil?
36
+ OverridesTracker::MethodsCollector.instance.report(ARGV[1])
37
+ else
38
+ puts 'No OVERRIDES_API_TOKEN was set. The report will not be uploaded to overrides.io.'
39
+ end
13
40
  end
@@ -0,0 +1,66 @@
1
+ require 'json'
2
+ require 'net/https'
3
+
4
+ class OverridesTracker::Api
5
+
6
+ API_HOST = ENV['OVERRIDES_TRACKER_DEVELOPMENT'] ? "localhost:3000" : "overrides.io"
7
+ API_PROTOCOL = ENV['OVERRIDES_TRACKER_DEVELOPMENT'] ? "http" : "https"
8
+ API_DOMAIN = "#{API_PROTOCOL}://#{API_HOST}"
9
+
10
+ API_BASE = "#{API_DOMAIN}/api/v1"
11
+
12
+ def self.report_build(api_token, branch_name, last_commit_id, last_commit_name, file_path)
13
+
14
+ disable_net_blockers!
15
+
16
+ uri = URI(API_DOMAIN)
17
+ client = build_client(uri)
18
+
19
+ request = Net::HTTP::Post.new('/api/v1/builds')
20
+ form_data = [['api_token',api_token], ['branch_name', branch_name],['build_provider_id', last_commit_id], ['build_name', last_commit_name], ['result_file', File.open(file_path)]]
21
+ request.set_form form_data, 'multipart/form-data'
22
+
23
+ puts ' '
24
+ puts '==========='
25
+ puts 'Sending report to Overrides.io...'
26
+
27
+ begin
28
+ response = client.request(request)
29
+ response_hash = JSON.load(response.body.to_str)
30
+ puts 'Success.'.green
31
+ rescue SocketError => each
32
+ puts 'Failed to report to the Overrides API.'.red
33
+ end
34
+ end
35
+
36
+
37
+ def self.build_client(uri)
38
+ client = Net::HTTP.new(uri.host, uri.port)
39
+ client.use_ssl = true if uri.port == 443
40
+ client.verify_mode = OpenSSL::SSL::VERIFY_NONE
41
+
42
+
43
+ client
44
+ end
45
+
46
+ private
47
+
48
+ def self.disable_net_blockers!
49
+ begin
50
+ require 'webmock'
51
+
52
+ allow = WebMock::Config.instance.allow || []
53
+ WebMock::Config.instance.allow = [*allow].push API_HOST
54
+ rescue LoadError
55
+ end
56
+
57
+ begin
58
+ require 'vcr'
59
+
60
+ VCR.send(VCR.version.major < 2 ? :config : :configure) do |c|
61
+ c.ignore_hosts API_HOST
62
+ end
63
+ rescue LoadError
64
+ end
65
+ end
66
+ end
@@ -6,7 +6,6 @@ class OverridesTracker::MethodsCollector
6
6
  @overridden_methods_collection = {}
7
7
 
8
8
  private_class_method :new
9
-
10
9
  def self.instance
11
10
  @instance
12
11
  end
@@ -77,7 +76,8 @@ class OverridesTracker::MethodsCollector
77
76
  data = nil
78
77
  begin
79
78
  File.open(file_path) do |f|
80
- data = JSON.parse(f.read)
79
+ file_data = JSON.parse(f.read)
80
+ data = file_data['overridden_methods'] != nil ? file_data['overridden_methods'] : file_data
81
81
  end
82
82
  rescue
83
83
  puts "Error processing #{file_path}"
@@ -86,14 +86,28 @@ class OverridesTracker::MethodsCollector
86
86
  end
87
87
 
88
88
  def save_to_file
89
+
90
+ file_data = {}
91
+ file_data[:version] = OverridesTracker::VERSION
92
+ file_data[:branch_name] = branch_name
93
+ file_data[:branch_name_to_report] = branch_name_to_report
94
+ file_data[:last_commit_id] = last_commit_id
95
+ file_data[:last_commit_name] = last_commit_name
96
+ file_data[:last_commit_name_to_report] = last_commit_name_to_report
97
+ file_data[:overridden_methods] = @overridden_methods_collection
98
+
89
99
  File.open(path_to_report_file, "w") do |f|
90
- f << @overridden_methods_collection.to_json
100
+ f << file_data.to_json
91
101
  end
92
102
  puts ' '
93
103
  puts '==========='
94
104
  puts "Report saved to #{path_to_report_file}."
95
105
  end
96
-
106
+
107
+ def report(api_token)
108
+ OverridesTracker::Api.report_build(api_token, branch_name_to_report, last_commit_id, last_commit_name_to_report, path_to_report_file)
109
+ end
110
+
97
111
  private
98
112
 
99
113
  def methods_collection(class_name)
@@ -117,14 +131,23 @@ class OverridesTracker::MethodsCollector
117
131
  branch.downcase.gsub('/','_').gsub(/\s+/, "")
118
132
  end
119
133
 
134
+ def branch_name_to_report
135
+ branch = `git rev-parse --abbrev-ref HEAD`
136
+ branch.gsub(/\s+/, "")
137
+ end
138
+
120
139
  def last_commit_id
121
140
  commit_id = `git log --format="%H" -n 1`
122
141
  commit_id.gsub(/\s+/, "")
123
142
  end
124
143
 
125
144
  def last_commit_name
126
- commit_id = `git log --format="%s" -n 1`
127
- commit_id.gsub(/\s+/, "")
145
+ commit_name = `git log --format="%s" -n 1`
146
+ commit_name.gsub(/\s+/, "")
147
+ end
148
+
149
+ def last_commit_name_to_report
150
+ commit_name = `git log --format="%s" -n 1`
128
151
  end
129
152
 
130
153
  def path_to_report_file
@@ -1,3 +1,3 @@
1
1
  module OverridesTracker
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -8,6 +8,7 @@ require "overrides_tracker/methods_collector"
8
8
  require "overrides_tracker/file_observer"
9
9
  require "overrides_tracker/util"
10
10
  require "overrides_tracker/comparer"
11
+ require "overrides_tracker/api"
11
12
 
12
13
 
13
14
  module OverridesTracker
@@ -38,8 +38,5 @@ Gem::Specification.new do |spec|
38
38
  spec.executables = ['overrides_tracker']
39
39
  spec.require_paths = ["lib"]
40
40
 
41
- spec.add_development_dependency "bundler", "~> 1.17"
42
- spec.add_development_dependency "rake", "~> 10.0"
43
- spec.add_development_dependency "rspec", "~> 3.0"
44
41
  spec.add_dependency "method_source"
45
42
  end
metadata CHANGED
@@ -1,57 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overrides_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Meyborg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-26 00:00:00.000000000 Z
11
+ date: 2022-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.17'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.17'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '10.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
55
13
  - !ruby/object:Gem::Dependency
56
14
  name: method_source
57
15
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +47,7 @@ files:
89
47
  - bin/overrides_tracker
90
48
  - bin/setup
91
49
  - lib/overrides_tracker.rb
50
+ - lib/overrides_tracker/api.rb
92
51
  - lib/overrides_tracker/comparer.rb
93
52
  - lib/overrides_tracker/file_observer.rb
94
53
  - lib/overrides_tracker/methods_collector.rb