coaster 1.3.27 → 1.3.29

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: 2f6845ad78b984bcd3b7e731c99f301cbb9cf988d2252450b0e961af3de2f630
4
- data.tar.gz: 00be20732649e4a1176873079b6d23a25bc0e2ead9b204fb7cc2da4ca2862219
3
+ metadata.gz: cee8914e3be8e12b37a81c3217b8d9725737dd505908db7055727cd6d88ef7e8
4
+ data.tar.gz: 67c6aaec914f4a2ff93b932c575f86d77753b76032ea8e3f369e47500b1c9de1
5
5
  SHA512:
6
- metadata.gz: bc1393903d6481ec4037b3cc71281fbb0d7ae998517065004d281c836effc2e9694e749d8bfe14aea8742e59c92b100002d6c3144cc8926f065d0f6149f13110
7
- data.tar.gz: 8ed7983c0ffde2f9b0817367187d8b719978adf433f29c7584a2d838176813f204deee4406417f9d5d40f5f05b985230f3e4c60eb05c633accc1ac3055cd07d6
6
+ metadata.gz: 38d61efdc28e80bb944cc546da9c139a4aa454c65fe6c61166258e911135125d9c9c92ee6493c71f54cd9055e828590d07344deaa672b7d072054823d4232aa5
7
+ data.tar.gz: 2b2cf7c5738c15875820905b080e35c240b209b0e4a1cc4f454f2f69e46b1e088d55fd96afdb1583d642a1cb5e2ae6dea94cf6bcbc84f2c9a5e69f98cb7c8be2
@@ -86,9 +86,9 @@ class StandardError
86
86
  @level = message.level
87
87
  @tkey = message.tkey
88
88
  @attributes = @attributes.merge(message.attributes || {})
89
- msg = message
89
+ msg = message.message
90
90
  when Exception
91
- msg = message
91
+ msg = message.message
92
92
  when Hash then
93
93
  @coaster = true # coaster 확장을 사용한 에러임을 확인할 수 있음.
94
94
  hash = message.with_indifferent_access rescue message
@@ -120,7 +120,7 @@ class StandardError
120
120
  msg = "{#{cause.message}}" if msg.blank? && cause
121
121
  super(msg)
122
122
  @digest_message = self.class.digest_message(msg)
123
- set_backtrace(msg.backtrace) if msg.is_a?(Exception)
123
+ set_backtrace(message.backtrace) if message.is_a?(Exception)
124
124
  @fingerprint << @digest_message
125
125
  @fingerprint << digest_backtrace
126
126
  @fingerprint.compact!
@@ -0,0 +1,142 @@
1
+ module Coaster
2
+ module Git
3
+ class Repository
4
+ class << self
5
+ def option_parser(options)
6
+ opts = []
7
+
8
+ # multiple options can be passed by set
9
+ options.map do |k, v|
10
+ if v.is_a?(Set)
11
+ v.each {|set_v| opts << [k, set_v]}
12
+ else
13
+ opts << [k, v]
14
+ end
15
+ end
16
+
17
+ parsed = opts.map do |k, v|
18
+ v = case v
19
+ when Hash then v.map{|vk,vv| "#{vk}=#{vv}"}.join(',')
20
+ when Array then v.join(',')
21
+ else v
22
+ end
23
+ v = v.strip
24
+ if k.start_with?('--')
25
+ "#{k}#{v.length > 0 ? "=#{v}" : ''}" # ex, --config-env=<name>=<envvar>
26
+ else
27
+ "#{k} #{v.length > 0 ? "#{v}" : ''}" # ex, -c <name>=<value>
28
+ end
29
+ end
30
+
31
+ parsed.join(' ')
32
+ end
33
+
34
+ def run_cmd(path, command)
35
+ puts "Run command: #{command}"
36
+ stdout, stderr, status = Open3.capture3(command, chdir: path)
37
+ if status.success?
38
+ puts " ↳ success: #{stdout}"
39
+ stdout
40
+ else
41
+ raise "Error executing command: #{command}\n ↳ #{stderr}"
42
+ end
43
+ end
44
+
45
+ def create(path)
46
+ run_cmd(path.split('/')[0..-2].join('/'), "git init #{path}")
47
+ run_cmd(path, "git commit --allow-empty -m 'initial commit'")
48
+ new(path)
49
+ end
50
+ end
51
+
52
+ attr_reader :path
53
+
54
+ def initialize(path)
55
+ @path = path
56
+ @sha = current_sha
57
+ end
58
+
59
+ def run_cmd(command)
60
+ self.class.run_cmd(path, command)
61
+ end
62
+
63
+ def run_git_cmd(command, **options)
64
+ cmd = "git #{self.class.option_parser(options)} #{command}"
65
+ run_cmd(cmd)
66
+ end
67
+
68
+ def add!
69
+ run_git_cmd('add .')
70
+ end
71
+
72
+ def commit!(message)
73
+ run_git_cmd("commit -m \"#{message}\"")
74
+ end
75
+
76
+ def branch!(name)
77
+ run_git_cmd("branch #{name}")
78
+ end
79
+
80
+ def checkout!(name)
81
+ run_git_cmd("checkout #{name}")
82
+ end
83
+
84
+ def submodule_add!(path, url, git_options: {})
85
+ run_git_cmd("submodule add #{url} #{path}", **git_options)
86
+ end
87
+
88
+ def submodule_init!(path)
89
+ run_git_cmd("submodule init #{path}")
90
+ end
91
+
92
+ def submodule_update!(*paths, options: {})
93
+ run_git_cmd("submodule update #{self.class.option_parser(options)} #{paths.join(' ')}")
94
+ end
95
+
96
+ def current_sha
97
+ run_git_cmd('rev-parse HEAD').strip
98
+ end
99
+
100
+ def submodule_paths
101
+ @submodule_paths ||= run_git_cmd('submodule status --recursive').split("\n").map do |line|
102
+ line.split(' ')[1]
103
+ end
104
+ end
105
+
106
+ def submodules
107
+ @submodules ||= submodule_paths.map do |path|
108
+ [path, Git::Repository.new(File.join(@path, path))]
109
+ end.to_h
110
+ end
111
+
112
+ def merge(pointer)
113
+ pointers = pointers(pointer).join(',')
114
+ puts "#{path} merged deploy, #{pointers}"
115
+ run_git_cmd("merge #{pointer} --commit -m \"merged deploy, #{pointers}\"")
116
+ end
117
+
118
+ def submodule_sha(path, pointer: nil)
119
+ pointer ||= @sha
120
+ run_git_cmd("ls-tree #{pointer} #{path}").split(' ')[2]
121
+ end
122
+
123
+ def deep_merge(pointer)
124
+ submodules.values.each do |submodule|
125
+ sm_sha = submodule_sha(submodule.path, pointer: pointer)
126
+ submodule.merge(sm_sha)
127
+ end
128
+ merge(pointer)
129
+ end
130
+
131
+ def pointers(sha)
132
+ run_git_cmd("branch --contains #{sha}").split("\n").map do |br|
133
+ (br.start_with?('*') ? br[2..-1] : br).strip
134
+ end
135
+ end
136
+
137
+ def remove
138
+ self.class.run_cmd(path.split('/')[0..-2].join('/'), "rm -rf #{path}")
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,9 @@
1
+ require 'open3'
2
+
3
+ module Coaster
4
+ module Git
5
+
6
+ end
7
+ end
8
+
9
+ require 'coaster/git/repository'
@@ -1,3 +1,3 @@
1
1
  module Coaster
2
- VERSION = '1.3.27'
2
+ VERSION = '1.3.29'
3
3
  end
data/test/test_git.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+ require 'minitest/autorun'
3
+ require 'coaster/git'
4
+
5
+ module Coaster
6
+ class TestGit < Minitest::Test
7
+ def setup
8
+ super
9
+ @test_repo_root = File.expand_path('../../tmp/test_repo', __FILE__)
10
+ FileUtils.rm_rf(@test_repo_root)
11
+ FileUtils.mkdir_p(@test_repo_root)
12
+ @beta = Git::Repository.create(File.join(@test_repo_root, 'beta'))
13
+ @beta.run_cmd('echo "hello beta" > README.md')
14
+ @beta.run_git_cmd('add .')
15
+ @beta.run_git_cmd('commit -m "hello"')
16
+ @beta.branch!('beta_feature')
17
+ @beta.checkout!('beta_feature')
18
+ @beta.run_cmd('echo "beta_feature" >> README.md')
19
+ @beta.run_git_cmd('add .')
20
+ @beta.run_git_cmd('commit -m "beta_feature"')
21
+ @beta.run_git_cmd('checkout main')
22
+
23
+ @alpha = Git::Repository.create(File.join(@test_repo_root, 'alpha'))
24
+ @alpha.submodule_add!('sb/beta', @beta.path, git_options: {'-c' => {'protocol.file.allow' => 'always'}})
25
+ @alpha.submodule_update!('sb/beta')
26
+ @alpha.run_cmd('echo "hello alpha" > README.md')
27
+ @alpha.run_git_cmd('add .')
28
+ @alpha.run_git_cmd('commit -m "hello"')
29
+ end
30
+
31
+ def teardown
32
+ FileUtils.rm_rf(@test_repo_root)
33
+ super
34
+ end
35
+
36
+ def test_git_deep_merge
37
+ assert_equal "hello alpha\n", @alpha.run_cmd('cat README.md')
38
+ assert_equal "hello beta\n", @alpha.run_cmd('cat sb/beta/README.md')
39
+
40
+ @alpha.branch!('alpha_feature')
41
+ @alpha.checkout!('alpha_feature')
42
+ @alpha.run_cmd('echo "alpha_feature" >> README.md')
43
+ @alpha.submodules['sb/beta'].run_git_cmd('checkout beta_feature')
44
+ @alpha.run_git_cmd('add .')
45
+ @alpha.run_git_cmd('commit -m "alpha_feature"')
46
+ assert_equal "README.md\nsb/beta\n", @alpha.run_git_cmd('diff --name-only HEAD~1 HEAD')
47
+
48
+ @alpha.checkout!('main')
49
+ @alpha.submodule_update!
50
+ assert_equal "hello beta\n", @alpha.run_cmd('cat sb/beta/README.md')
51
+ @alpha.deep_merge('alpha_feature')
52
+ assert_equal "hello alpha\nalpha_feature\n", @alpha.run_cmd('cat README.md')
53
+ assert_equal "hello beta\nbeta_feature\n", @alpha.run_cmd('cat sb/beta/README.md')
54
+ end
55
+ end
56
+ end
@@ -24,7 +24,7 @@ module Coaster
24
24
  end
25
25
 
26
26
  def test_translation_missing
27
- assert_equal 'translation missing: en.class.Coaster.NotTranslated.self', NotTranslated._translate
27
+ assert_equal 'Translation missing: en.class.Coaster.NotTranslated.self', NotTranslated._translate
28
28
  end
29
29
 
30
30
  def test_fallback
@@ -64,12 +64,12 @@ module Coaster
64
64
  assert_equal 'user message', e.user_message
65
65
  assert_equal 'standard error title', e.title
66
66
  e = UntitledError.new(tkey: 'no.translation')
67
- assert_equal "translation missing: en.no.translation (Coaster::TestStandardError::UntitledError)", e.to_s
68
- assert_equal "translation missing: en.no.translation (Coaster::TestStandardError::UntitledError)", e.message
67
+ assert_equal "Translation missing: en.no.translation (Coaster::TestStandardError::UntitledError)", e.to_s
68
+ assert_equal "Translation missing: en.no.translation (Coaster::TestStandardError::UntitledError)", e.message
69
69
  assert_nil e.description
70
70
  assert_nil e.desc
71
- assert_equal 'translation missing: en.no.translation', e._translate
72
- assert_equal "translation missing: en.no.translation", e.user_message
71
+ assert_equal 'Translation missing: en.no.translation', e._translate
72
+ assert_equal "Translation missing: en.no.translation", e.user_message
73
73
  assert_equal 'standard error title', e.title
74
74
  end
75
75
 
@@ -316,7 +316,7 @@ LOG
316
316
  assert_equal 'NameError', e.to_hash['type']
317
317
  assert_equal 999999, e.to_hash['status']
318
318
  assert_equal 500, e.to_hash['http_status']
319
- assert_equal "standard error translation (bc1746 #{bt})", e.user_message
319
+ assert_equal "standard error translation (3dd84e #{bt})", e.user_message
320
320
  assert_match(/undefined local variable or method `aa'/, e.to_hash['message'])
321
321
  end
322
322
 
@@ -387,5 +387,11 @@ LOG
387
387
  assert_equal "Test sample error (58ee3f #{bt})", e.user_message
388
388
  end
389
389
  end
390
+
391
+ def test_wrapping_digest
392
+ a = StandardError.new('#<Abc:0x111>')
393
+ b = StandardError.new(a)
394
+ assert_equal '#<Abc:0x111>', b.message
395
+ end
390
396
  end
391
397
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coaster
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.27
4
+ version: 1.3.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - buzz jung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-12 00:00:00.000000000 Z
11
+ date: 2023-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -197,6 +197,8 @@ files:
197
197
  - lib/coaster/core_ext/standard_error.rb
198
198
  - lib/coaster/core_ext/standard_error/raven.rb
199
199
  - lib/coaster/core_ext/standard_error/sentry.rb
200
+ - lib/coaster/git.rb
201
+ - lib/coaster/git/repository.rb
200
202
  - lib/coaster/rails_ext.rb
201
203
  - lib/coaster/rails_ext/backtrace_cleaner.rb
202
204
  - lib/coaster/safe_yaml_serializer.rb
@@ -207,6 +209,7 @@ files:
207
209
  - test/support/models.rb
208
210
  - test/support/schema.rb
209
211
  - test/test_backtrace.rb
212
+ - test/test_git.rb
210
213
  - test/test_helper.rb
211
214
  - test/test_month.rb
212
215
  - test/test_object_translation.rb
@@ -241,6 +244,7 @@ test_files:
241
244
  - test/support/models.rb
242
245
  - test/support/schema.rb
243
246
  - test/test_backtrace.rb
247
+ - test/test_git.rb
244
248
  - test/test_helper.rb
245
249
  - test/test_month.rb
246
250
  - test/test_object_translation.rb