coaster 1.3.28 → 1.3.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coaster/git/repository.rb +142 -0
- data/lib/coaster/git.rb +9 -0
- data/lib/coaster/version.rb +1 -1
- data/test/test_git.rb +56 -0
- data/test/test_object_translation.rb +1 -1
- data/test/test_standard_error.rb +4 -4
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cee8914e3be8e12b37a81c3217b8d9725737dd505908db7055727cd6d88ef7e8
|
4
|
+
data.tar.gz: 67c6aaec914f4a2ff93b932c575f86d77753b76032ea8e3f369e47500b1c9de1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38d61efdc28e80bb944cc546da9c139a4aa454c65fe6c61166258e911135125d9c9c92ee6493c71f54cd9055e828590d07344deaa672b7d072054823d4232aa5
|
7
|
+
data.tar.gz: 2b2cf7c5738c15875820905b080e35c240b209b0e4a1cc4f454f2f69e46b1e088d55fd96afdb1583d642a1cb5e2ae6dea94cf6bcbc84f2c9a5e69f98cb7c8be2
|
@@ -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
|
data/lib/coaster/git.rb
ADDED
data/lib/coaster/version.rb
CHANGED
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 '
|
27
|
+
assert_equal 'Translation missing: en.class.Coaster.NotTranslated.self', NotTranslated._translate
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_fallback
|
data/test/test_standard_error.rb
CHANGED
@@ -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 "
|
68
|
-
assert_equal "
|
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 '
|
72
|
-
assert_equal "
|
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
|
|
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.
|
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-
|
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
|