roku_builder 3.6.6 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ea74584f4460f3ab03af626f3005087d00b0229
4
- data.tar.gz: e03c93389a91258cb1c7951c090a1f7c04b340b3
3
+ metadata.gz: b77bdbc22da34e8fdcdc5c1f975f656dd696d902
4
+ data.tar.gz: ac97ad95bf1b3ce94a112caccdad8190158ebb14
5
5
  SHA512:
6
- metadata.gz: a909febdefc33b6a39d15b83a20b0cb0eda96bab9ef3f25cc79b823158539e8975c4bff6466aa0cef0d96057b260ee3f62dd383f70d5e10ada267e345789aa6a
7
- data.tar.gz: 7e3ff144e18c67c3c87c0f6f9aba9f44240b9fbafba7497bd40c6cb7a7d3b655ddc76cfff98c40e6d4562636335682cd2856a20684f8348415475f0837f53e3b
6
+ metadata.gz: d20c6095f900ef0165ee91283d04dd655cb8b8a520cca07a556c2c163d3998752a684abb861ad33a5da099b4193455d9eaba1b86fd3fa1639023cfd166f5f1e9
7
+ data.tar.gz: 86be7326237f15678c14565df9f93c94aa5a504c21f9aab701ae7deeaa9e0693bbc8d3d088a38260e8680a0b11181d808231c4bf2c0891272cc41e4bade84410
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- roku_builder (3.6.6)
4
+ roku_builder (3.7.0)
5
5
  faraday (~> 0.9)
6
6
  faraday-digestauth (~> 0.2)
7
7
  git (~> 1.3)
data/bin/roku CHANGED
@@ -72,6 +72,14 @@ OptionParser.new do |opts|
72
72
  options[:print] = a
73
73
  end
74
74
 
75
+ opts.on("--do-stage", "Command: Run the stager. Used for scripting. Alwasy run --do-unscript after") do
76
+ options[:dostage] = true
77
+ end
78
+
79
+ opts.on("--do-unstage", "Command: Run the unstager. Used for scripting. Alwasy run --do-script first") do
80
+ options[:dounstage] = true
81
+ end
82
+
75
83
  opts.on("--screen SCREEN", "Command: show a screen") do |s|
76
84
  options[:screen] = s
77
85
  end
@@ -14,6 +14,8 @@ require "zip"
14
14
  require "git"
15
15
  #config_manager
16
16
  require 'json'
17
+ #stager
18
+ require 'pstore'
17
19
 
18
20
  require "roku_builder/controller"
19
21
  require "roku_builder/controller_commands"
@@ -158,3 +160,30 @@ class ::Hash
158
160
  self.merge(second, &merger)
159
161
  end
160
162
  end
163
+
164
+ module Git
165
+ class Stashes
166
+ def pop(index=nil)
167
+ @base.lib.stash_pop(index)
168
+ end
169
+ def drop(index=nil)
170
+ @base.lib.stash_drop(index)
171
+ end
172
+ end
173
+ class Lib
174
+ def stash_pop(id = nil)
175
+ if id
176
+ command('stash pop', [id])
177
+ else
178
+ command('stash pop')
179
+ end
180
+ end
181
+ def stash_drop(id = nil)
182
+ if id
183
+ command('stash drop', [id])
184
+ else
185
+ command('stash drop')
186
+ end
187
+ end
188
+ end
189
+ end
@@ -162,7 +162,7 @@ module RokuBuilder
162
162
  def self.commands
163
163
  [:sideload, :package, :test, :deeplink,:configure, :validate, :delete,
164
164
  :navigate, :text, :build, :monitor, :update, :screencapture, :key, :screen,
165
- :screens, :applist, :print]
165
+ :screens, :applist, :print, :dostage, :dounstage]
166
166
  end
167
167
 
168
168
  # List of depricated options
@@ -163,6 +163,16 @@ module RokuBuilder
163
163
  code
164
164
  end
165
165
 
166
+ def self.dostage(configs:)
167
+ stager = Stager.new(**configs[:stage_config])
168
+ stager.stage
169
+ end
170
+
171
+ def self.dounstage(configs:)
172
+ stager = Stager.new(**configs[:stage_config])
173
+ stager.unstage
174
+ end
175
+
166
176
  # Run a simple command
167
177
  # @param klass [Class] class of object to create
168
178
  # @param method [Symbol] methog to run on klass
@@ -11,7 +11,7 @@ module RokuBuilder
11
11
  @root_dir = root_dir
12
12
  @logger = logger
13
13
  @stage_success = true
14
- @orginal_directory = Dir.pwd
14
+ @stash_key = "roku-builder-temp-stash"
15
15
  end
16
16
 
17
17
  # Helper method to get the staging method being used
@@ -24,6 +24,7 @@ module RokuBuilder
24
24
  # Change the stage of the app depending on the method
25
25
  # @return [Boolean] whether the staging was successful or not
26
26
  def stage
27
+ @orginal_directory = Dir.pwd
27
28
  Dir.chdir(@root_dir) unless @root_dir == @orginal_directory
28
29
  case @method
29
30
  when :current
@@ -46,6 +47,8 @@ module RokuBuilder
46
47
  # Revert the change that the stage method made
47
48
  # @return [Boolean] whether the revert was successful or not
48
49
  def unstage
50
+ @orginal_directory ||= Dir.pwd
51
+ Dir.chdir(@root_dir) unless @root_dir == @orginal_directory
49
52
  unstage_success = true
50
53
  case @method
51
54
  when :current
@@ -73,10 +76,11 @@ module RokuBuilder
73
76
  def git_switch_to(branch:)
74
77
  if branch
75
78
  @git ||= Git.open(@root_dir)
76
- if branch != @git.current_branch
79
+ if @git and branch != @git.current_branch
77
80
  @current_branch = @git.current_branch
78
- @stash = @git.branch.stashes.save("roku-builder-temp-stash")
81
+ @git.branch.stashes.save(@stash_key)
79
82
  @git.checkout(branch)
83
+ save_state
80
84
  end
81
85
  end
82
86
  end
@@ -85,13 +89,45 @@ module RokuBuilder
85
89
  # @param branch [String] teh branch to switch from
86
90
  # @param checkout [Boolean] whether to actually run the checkout command
87
91
  def git_switch_from(branch:, checkout: true)
92
+ @current_branch ||= nil
88
93
  if branch
89
94
  @git ||= Git.open(@root_dir)
90
- if @git and @current_branch
95
+ if @git and (@current_branch or load_state)
91
96
  @git.checkout(@current_branch) if checkout
92
- @git.branch.stashes.apply if @stash
97
+ index = 0
98
+ @git.branch.stashes.each do |stash|
99
+ if stash.message == @stash_key
100
+ @git.branch.stashes.pop("stash@{#{index}}")
101
+ break
102
+ end
103
+ index += 1
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ # Save staging state to file
110
+ def save_state
111
+ store = PStore.new(File.expand_path("~/.roku_pstore"))
112
+ store.transaction do
113
+ store[:current_branch] = @current_branch.to_s
114
+ end
115
+ end
116
+
117
+ # Load staging state from file
118
+ def load_state
119
+ store = PStore.new(File.expand_path("~/.roku_pstore"))
120
+ store.transaction do
121
+ @git.branches.each do |branch|
122
+ if branch.to_s == store[:current_branch]
123
+ @current_branch = branch
124
+ store[:current_branch] = nil
125
+ break
126
+ end
93
127
  end
128
+ !!@current_branch
94
129
  end
130
+ !!@current_branch
95
131
  end
96
132
 
97
133
  # Called if resuce from git exception
@@ -2,5 +2,5 @@
2
2
 
3
3
  module RokuBuilder
4
4
  # Version of the RokuBuilder Gem
5
- VERSION = "3.6.6"
5
+ VERSION = "3.7.0"
6
6
  end
@@ -45,6 +45,7 @@ class StagerTest < Minitest::Test
45
45
  git = Minitest::Mock.new
46
46
  branch = Minitest::Mock.new
47
47
  stashes = Minitest::Mock.new
48
+ stash = Minitest::Mock.new
48
49
 
49
50
  stager_config = {
50
51
  method: :git,
@@ -59,10 +60,13 @@ class StagerTest < Minitest::Test
59
60
  branch.expect(:stashes, stashes)
60
61
  stashes.expect(:save, true, ["roku-builder-temp-stash"])
61
62
  git.expect(:checkout, nil, [branch_name])
63
+ git.expect(:branch, branch)
64
+ branch.expect(:stashes, [stash])
62
65
  git.expect(:checkout, nil, ['other_branch'])
63
66
  git.expect(:branch, branch)
67
+ stash.expect(:message, "roku-builder-temp-stash")
64
68
  branch.expect(:stashes, stashes)
65
- stashes.expect(:apply, nil)
69
+ stashes.expect(:pop, nil, ["stash@{0}"])
66
70
 
67
71
  Git.stub(:open, git) do
68
72
  stager = RokuBuilder::Stager.new(**stager_config)
@@ -72,6 +76,7 @@ class StagerTest < Minitest::Test
72
76
  git.verify
73
77
  branch.verify
74
78
  stashes.verify
79
+ stash.verify
75
80
  end
76
81
 
77
82
  def test_stager_stage_git_no_stash
@@ -94,7 +99,10 @@ class StagerTest < Minitest::Test
94
99
  branch.expect(:stashes, stashes)
95
100
  stashes.expect(:save, nil, ["roku-builder-temp-stash"])
96
101
  git.expect(:checkout, nil, [branch_name])
102
+
97
103
  git.expect(:checkout, nil, ['other_branch'])
104
+ git.expect(:branch, branch)
105
+ branch.expect(:stashes, [])
98
106
 
99
107
  Git.stub(:open, git) do
100
108
  stager = RokuBuilder::Stager.new(**stager_config)
@@ -112,6 +120,7 @@ class StagerTest < Minitest::Test
112
120
  git = Minitest::Mock.new
113
121
  branch = Minitest::Mock.new
114
122
  stashes = Minitest::Mock.new
123
+ stash = Minitest::Mock.new
115
124
  logger = Minitest::Mock.new
116
125
 
117
126
  stager_config = {
@@ -132,8 +141,11 @@ class StagerTest < Minitest::Test
132
141
  stashes.expect(:save, true, ["roku-builder-temp-stash"])
133
142
  logger.expect(:error, nil, ["Branch or ref does not exist"])
134
143
  git.expect(:branch, branch)
144
+ branch.expect(:stashes, [stash])
145
+ git.expect(:branch, branch)
146
+ stash.expect(:message, "roku-builder-temp-stash")
135
147
  branch.expect(:stashes, stashes)
136
- stashes.expect(:apply, nil)
148
+ stashes.expect(:pop, nil, ["stash@{0}"])
137
149
 
138
150
  Git.stub(:open, git) do
139
151
  stager = RokuBuilder::Stager.new(**stager_config)
@@ -143,6 +155,7 @@ class StagerTest < Minitest::Test
143
155
  git.verify
144
156
  branch.verify
145
157
  stashes.verify
158
+ stash.verify
146
159
  logger.verify
147
160
  end
148
161
 
@@ -188,5 +201,89 @@ class StagerTest < Minitest::Test
188
201
  assert stager.unstage
189
202
  end
190
203
  end
204
+
205
+ def test_stager_save_state
206
+ root_dir = File.join(File.dirname(__FILE__), "test_files", "stager_test")
207
+ branch_name = 'branch'
208
+ git = Minitest::Mock.new
209
+ branch = Minitest::Mock.new
210
+ stashes = Minitest::Mock.new
211
+ pstore = Minitest::Mock.new
212
+
213
+ stager_config = {
214
+ method: :git,
215
+ root_dir: root_dir,
216
+ key: branch_name,
217
+ logger: nil
218
+ }
219
+
220
+ git.expect(:current_branch, 'other_branch')
221
+ git.expect(:current_branch, 'other_branch')
222
+ git.expect(:branch, branch)
223
+ branch.expect(:stashes, stashes)
224
+ stashes.expect(:save, 'stash', ["roku-builder-temp-stash"])
225
+ git.expect(:checkout, nil, [branch_name])
226
+
227
+ pstore.expect(:transaction, nil) do |&block|
228
+ block.call
229
+ end
230
+ pstore.expect(:[]=, nil, [:current_branch, 'other_branch'])
231
+
232
+
233
+ Git.stub(:open, git) do
234
+ PStore.stub(:new, pstore) do
235
+ stager = RokuBuilder::Stager.new(**stager_config)
236
+ assert stager.stage
237
+ end
238
+ end
239
+ git.verify
240
+ branch.verify
241
+ stashes.verify
242
+ pstore.verify
243
+ end
244
+
245
+ def test_stager_load_state
246
+ root_dir = File.join(File.dirname(__FILE__), "test_files", "stager_test")
247
+ branch_name = 'branch'
248
+ git = Minitest::Mock.new
249
+ branch = Minitest::Mock.new
250
+ stashes = Minitest::Mock.new
251
+ stash = Minitest::Mock.new
252
+ pstore = Minitest::Mock.new
253
+
254
+ stager_config = {
255
+ method: :git,
256
+ root_dir: root_dir,
257
+ key: branch_name,
258
+ logger: nil
259
+ }
260
+
261
+ pstore.expect(:transaction, nil) do |&block|
262
+ block.call
263
+ end
264
+ git.expect(:branches, ['other_branch'])
265
+ pstore.expect(:[], 'other_branch', [:current_branch])
266
+ pstore.expect(:[]=, nil, [:current_branch, nil])
267
+
268
+ git.expect(:branch, branch)
269
+ branch.expect(:stashes, [stash])
270
+ git.expect(:checkout, nil, ['other_branch'])
271
+ git.expect(:branch, branch)
272
+ stash.expect(:message, "roku-builder-temp-stash")
273
+ branch.expect(:stashes, stashes)
274
+ stashes.expect(:pop, nil, ["stash@{0}"])
275
+
276
+ Git.stub(:open, git) do
277
+ PStore.stub(:new, pstore) do
278
+ stager = RokuBuilder::Stager.new(**stager_config)
279
+ assert stager.unstage
280
+ end
281
+ end
282
+ git.verify
283
+ branch.verify
284
+ stashes.verify
285
+ stash.verify
286
+ pstore.verify
287
+ end
191
288
  end
192
289
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roku_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.6
4
+ version: 3.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - greeneca