emerge 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/utils/github.rb CHANGED
@@ -4,7 +4,7 @@ module EmergeCLI
4
4
  GITHUB_EVENT_PUSH = 'push'.freeze
5
5
 
6
6
  def self.event_name
7
- ENV['GITHUB_EVENT_NAME']
7
+ ENV.fetch('GITHUB_EVENT_NAME', nil)
8
8
  end
9
9
 
10
10
  def self.supported_github_event?
@@ -22,7 +22,7 @@ module EmergeCLI
22
22
 
23
23
  def self.sha
24
24
  if push?
25
- ENV['GITHUB_SHA']
25
+ ENV.fetch('GITHUB_SHA', nil)
26
26
  elsif pull_request?
27
27
  github_event_data.dig(:pull_request, :head, :sha)
28
28
  end
@@ -55,7 +55,7 @@ module EmergeCLI
55
55
 
56
56
  def self.github_event_data
57
57
  @github_event_data ||= begin
58
- github_event_path = ENV['GITHUB_EVENT_PATH']
58
+ github_event_path = ENV.fetch('GITHUB_EVENT_PATH', nil)
59
59
  Logger.error 'GITHUB_EVENT_PATH is not set' if github_event_path.nil?
60
60
 
61
61
  Logger.error "File #{github_event_path} doesn't exist" unless File.exist?(github_event_path)
data/lib/utils/logger.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'logger'
2
- require 'colorize'
2
+ require 'colored2'
3
3
 
4
4
  module EmergeCLI
5
5
  class Logger
@@ -43,7 +43,7 @@ module EmergeCLI
43
43
  when 'ERROR'
44
44
  msg.to_s.red
45
45
  when 'DEBUG'
46
- msg.to_s.light_blue
46
+ msg.to_s.blue
47
47
  else
48
48
  msg.to_s
49
49
  end
data/lib/utils/network.rb CHANGED
@@ -9,9 +9,9 @@ module EmergeCLI
9
9
  public_constant :EMERGE_API_PROD_URL
10
10
 
11
11
  RETRY_DELAY = 5
12
- MAX_RETRIES = 1
12
+ MAX_RETRIES = 3
13
13
 
14
- def initialize(api_token:, base_url: EMERGE_API_PROD_URL)
14
+ def initialize(api_token: nil, base_url: EMERGE_API_PROD_URL)
15
15
  @base_url = base_url
16
16
  @api_token = api_token
17
17
  @internet = Async::HTTP::Internet.new
@@ -21,8 +21,8 @@ module EmergeCLI
21
21
  request(:get, path, nil, headers)
22
22
  end
23
23
 
24
- def post(path:, body:, headers: {})
25
- request(:post, path, body, headers)
24
+ def post(path:, body:, headers: {}, query: nil)
25
+ request(:post, path, body, headers, query)
26
26
  end
27
27
 
28
28
  def put(path:, body:, headers: {})
@@ -35,15 +35,23 @@ module EmergeCLI
35
35
 
36
36
  private
37
37
 
38
- def request(method, path, body, custom_headers)
38
+ def request(method, path, body, custom_headers, query = nil)
39
39
  uri = if path.start_with?('http')
40
40
  URI.parse(path)
41
41
  else
42
- URI::HTTPS.build(host: @base_url, path:)
42
+ query_string = query ? URI.encode_www_form(query) : nil
43
+ URI::HTTPS.build(
44
+ host: @base_url,
45
+ path: path,
46
+ query: query_string
47
+ )
43
48
  end
44
49
  absolute_uri = uri.to_s
45
50
 
46
- headers = { 'X-API-Token' => @api_token }
51
+ headers = {
52
+ 'User-Agent' => "emerge-cli/#{EmergeCLI::VERSION}"
53
+ }
54
+ headers['X-API-Token'] = @api_token if @api_token
47
55
  headers['Content-Type'] = 'application/json' if method == :post && body.is_a?(Hash)
48
56
  headers.merge!(custom_headers)
49
57
 
@@ -62,20 +70,32 @@ module EmergeCLI
62
70
 
63
71
  response
64
72
  rescue StandardError => e
65
- # Workaround for an issue where the request is not fully written, haven't determined the root cause yet
66
- if e.message.include?('Wrote 0 bytes') && retries < MAX_RETRIES
67
- retries += 1
68
- Logger.warn "Request failed due to incomplete write. Retrying in #{RETRY_DELAY} seconds..."
69
- sleep RETRY_DELAY
73
+ retries += 1
74
+ if retries <= MAX_RETRIES
75
+ delay = RETRY_DELAY * retries
76
+ error_message = e.message
77
+ Logger.warn "Request failed (attempt #{retries}/#{MAX_RETRIES}): #{error_message}"
78
+ Logger.warn "Retrying in #{delay} seconds..."
79
+
80
+ begin
81
+ @internet.close
82
+ rescue StandardError
83
+ nil
84
+ end
85
+ @internet = Async::HTTP::Internet.new
86
+
87
+ sleep delay
70
88
  retry
71
89
  else
72
- Logger.error "Request failed: #{absolute_uri} #{e.message}"
90
+ Logger.error "Request failed after #{MAX_RETRIES} attempts: #{absolute_uri} #{e.message}"
73
91
  raise e
74
92
  end
75
93
  end
76
94
  end
77
95
 
78
96
  def perform_request(method, absolute_uri, headers, body)
97
+ headers ||= {}
98
+
79
99
  case method
80
100
  when :get
81
101
  @internet.get(absolute_uri, headers:)
@@ -0,0 +1,32 @@
1
+ require 'json'
2
+
3
+ module EmergeCLI
4
+ module Utils
5
+ class VersionCheck
6
+ def initialize(network: EmergeCLI::Network.new)
7
+ @network = network
8
+ end
9
+
10
+ def check_version
11
+ Sync do
12
+ response = @network.get(
13
+ path: 'https://rubygems.org/api/v1/gems/emerge.json',
14
+ headers: {}
15
+ )
16
+ latest_version = JSON.parse(response.read).fetch('version')
17
+ current_version = EmergeCLI::VERSION
18
+
19
+ if Gem::Version.new(latest_version) > Gem::Version.new(current_version)
20
+ Logger.warn "A new version of emerge-cli is available (#{latest_version})"
21
+ Logger.warn "You are currently using version #{current_version}"
22
+ Logger.warn "To update, run: gem update emerge\n"
23
+ end
24
+ end
25
+ rescue KeyError
26
+ Logger.error 'Failed to parse version from RubyGems API response'
27
+ rescue StandardError => e
28
+ Logger.error "Failed to check for updates: #{e.message}"
29
+ end
30
+ end
31
+ end
32
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module EmergeCli
2
- VERSION = '0.2.1'.freeze
1
+ module EmergeCLI
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emerge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emerge Tools
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-21 00:00:00.000000000 Z
11
+ date: 2024-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: async
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 2.20.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 2.20.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: async-http
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: 0.83.1
19
+ version: 0.86.0
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: 0.83.1
26
+ version: 0.86.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: chunky_png
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,47 +39,47 @@ dependencies:
53
39
  - !ruby/object:Gem::Version
54
40
  version: 1.4.0
55
41
  - !ruby/object:Gem::Dependency
56
- name: colorize
42
+ name: dry-cli
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: 1.1.0
47
+ version: 1.2.0
62
48
  type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: 1.1.0
54
+ version: 1.2.0
69
55
  - !ruby/object:Gem::Dependency
70
- name: dry-cli
56
+ name: open3
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: 1.2.0
61
+ version: 0.2.1
76
62
  type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: 1.2.0
68
+ version: 0.2.1
83
69
  - !ruby/object:Gem::Dependency
84
- name: open3
70
+ name: ruby_tree_sitter
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: 0.2.1
75
+ version: '1.9'
90
76
  type: :runtime
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: 0.2.1
82
+ version: '1.9'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: tty-prompt
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -136,104 +122,6 @@ dependencies:
136
122
  - - "~>"
137
123
  - !ruby/object:Gem::Version
138
124
  version: 1.27.0
139
- - !ruby/object:Gem::Dependency
140
- name: minitest
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: 5.25.1
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: 5.25.1
153
- - !ruby/object:Gem::Dependency
154
- name: minitest-reporters
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: 1.7.1
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: 1.7.1
167
- - !ruby/object:Gem::Dependency
168
- name: pry
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: 0.15.0
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: 0.15.0
181
- - !ruby/object:Gem::Dependency
182
- name: rake
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - "~>"
186
- - !ruby/object:Gem::Version
187
- version: 13.2.1
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - "~>"
193
- - !ruby/object:Gem::Version
194
- version: 13.2.1
195
- - !ruby/object:Gem::Dependency
196
- name: rspec
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - "~>"
200
- - !ruby/object:Gem::Version
201
- version: 3.13.0
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - "~>"
207
- - !ruby/object:Gem::Version
208
- version: 3.13.0
209
- - !ruby/object:Gem::Dependency
210
- name: rubocop
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: 1.68.0
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - "~>"
221
- - !ruby/object:Gem::Version
222
- version: 1.68.0
223
- - !ruby/object:Gem::Dependency
224
- name: simplecov
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - "~>"
228
- - !ruby/object:Gem::Version
229
- version: 0.22.0
230
- type: :development
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - "~>"
235
- - !ruby/object:Gem::Version
236
- version: 0.22.0
237
125
  description: The official CLI for Emerge Tools
238
126
  email:
239
127
  - support@emergetools.com
@@ -249,12 +137,15 @@ files:
249
137
  - lib/commands/config/snapshots/snapshots_ios.rb
250
138
  - lib/commands/global_options.rb
251
139
  - lib/commands/integrate/fastlane.rb
140
+ - lib/commands/reaper/reaper.rb
252
141
  - lib/commands/upload/snapshots/client_libraries/default.rb
253
142
  - lib/commands/upload/snapshots/client_libraries/paparazzi.rb
254
143
  - lib/commands/upload/snapshots/client_libraries/roborazzi.rb
255
144
  - lib/commands/upload/snapshots/client_libraries/swift_snapshot_testing.rb
256
145
  - lib/commands/upload/snapshots/snapshots.rb
257
146
  - lib/emerge_cli.rb
147
+ - lib/reaper/ast_parser.rb
148
+ - lib/reaper/code_deleter.rb
258
149
  - lib/utils/git.rb
259
150
  - lib/utils/git_info_provider.rb
260
151
  - lib/utils/git_result.rb
@@ -263,7 +154,14 @@ files:
263
154
  - lib/utils/network.rb
264
155
  - lib/utils/profiler.rb
265
156
  - lib/utils/project_detector.rb
157
+ - lib/utils/version_check.rb
266
158
  - lib/version.rb
159
+ - parsers/libtree-sitter-java-darwin-arm64.dylib
160
+ - parsers/libtree-sitter-java-linux-x86_64.so
161
+ - parsers/libtree-sitter-kotlin-darwin-arm64.dylib
162
+ - parsers/libtree-sitter-kotlin-linux-x86_64.so
163
+ - parsers/libtree-sitter-swift-darwin-arm64.dylib
164
+ - parsers/libtree-sitter-swift-linux-x86_64.so
267
165
  homepage: https://github.com/EmergeTools/emerge-cli
268
166
  licenses:
269
167
  - MIT
@@ -271,6 +169,7 @@ metadata:
271
169
  homepage_uri: https://github.com/EmergeTools/emerge-cli
272
170
  source_code_uri: https://github.com/EmergeTools/emerge-cli
273
171
  changelog_uri: https://github.com/EmergeTools/emerge-cli/blob/main/CHANGELOG.md
172
+ rubygems_mfa_required: 'true'
274
173
  post_install_message:
275
174
  rdoc_options: []
276
175
  require_paths:
@@ -286,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
185
  - !ruby/object:Gem::Version
287
186
  version: '0'
288
187
  requirements: []
289
- rubygems_version: 3.4.10
188
+ rubygems_version: 3.5.11
290
189
  signing_key:
291
190
  specification_version: 4
292
191
  summary: Emerge CLI