daq_flow 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +62 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +165 -0
  8. data/Rakefile +10 -0
  9. data/bin/daq_flow +23 -0
  10. data/flash_flow.gemspec +28 -0
  11. data/flash_flow.yml.erb.example +42 -0
  12. data/lib/flash_flow.rb +7 -0
  13. data/lib/flash_flow/branch_merger.rb +55 -0
  14. data/lib/flash_flow/cmd_runner.rb +54 -0
  15. data/lib/flash_flow/config.rb +84 -0
  16. data/lib/flash_flow/data.rb +6 -0
  17. data/lib/flash_flow/data/base.rb +89 -0
  18. data/lib/flash_flow/data/bitbucket.rb +152 -0
  19. data/lib/flash_flow/data/branch.rb +124 -0
  20. data/lib/flash_flow/data/collection.rb +211 -0
  21. data/lib/flash_flow/data/github.rb +140 -0
  22. data/lib/flash_flow/data/store.rb +44 -0
  23. data/lib/flash_flow/git.rb +267 -0
  24. data/lib/flash_flow/install.rb +19 -0
  25. data/lib/flash_flow/lock.rb +23 -0
  26. data/lib/flash_flow/merge.rb +6 -0
  27. data/lib/flash_flow/merge/acceptance.rb +154 -0
  28. data/lib/flash_flow/merge/base.rb +116 -0
  29. data/lib/flash_flow/merge_order.rb +27 -0
  30. data/lib/flash_flow/notifier.rb +23 -0
  31. data/lib/flash_flow/options.rb +34 -0
  32. data/lib/flash_flow/resolve.rb +143 -0
  33. data/lib/flash_flow/shadow_repo.rb +44 -0
  34. data/lib/flash_flow/time_helper.rb +32 -0
  35. data/lib/flash_flow/version.rb +4 -0
  36. data/log/.keep +0 -0
  37. data/test/lib/data/test_base.rb +10 -0
  38. data/test/lib/data/test_branch.rb +206 -0
  39. data/test/lib/data/test_collection.rb +308 -0
  40. data/test/lib/data/test_store.rb +70 -0
  41. data/test/lib/lock/test_github.rb +74 -0
  42. data/test/lib/merge/test_acceptance.rb +230 -0
  43. data/test/lib/test_branch_merger.rb +78 -0
  44. data/test/lib/test_config.rb +63 -0
  45. data/test/lib/test_git.rb +73 -0
  46. data/test/lib/test_merge_order.rb +71 -0
  47. data/test/lib/test_notifier.rb +33 -0
  48. data/test/lib/test_resolve.rb +69 -0
  49. data/test/minitest_helper.rb +41 -0
  50. data/update_gem.sh +5 -0
  51. metadata +192 -0
@@ -0,0 +1,63 @@
1
+ require 'minitest_helper'
2
+
3
+ module FlashFlow
4
+ class TestConfig < Minitest::Test
5
+ def setup
6
+ @config_hash = {
7
+ 'git' => {
8
+ 'use_rerere' => true,
9
+ 'remote' => 'arbitrary_remote',
10
+ 'merge_branch' => 'acceptance',
11
+ 'master_branch' => 'master'
12
+ },
13
+ 'branch_info_file' => 'some_file.txt',
14
+ 'branches' => {
15
+ 'class' => {
16
+ 'name' => 'BranchClass'
17
+ }
18
+ }
19
+ }
20
+
21
+ reset_config!
22
+ end
23
+
24
+ def test_that_it_sets_all_attrs
25
+ File.stub(:read, @config_hash.to_yaml) do
26
+ Config.configure!('unused_file_name.yml')
27
+ assert('some_file.txt' == config.branch_info_file)
28
+ assert({
29
+ 'use_rerere' => true,
30
+ 'remote' => 'arbitrary_remote',
31
+ 'merge_branch' => 'acceptance',
32
+ 'master_branch' => 'master'
33
+ } == config.git)
34
+ assert({ 'class' => { 'name' => 'BranchClass' }} == config.branches)
35
+ end
36
+ end
37
+
38
+ def test_that_it_blows_up
39
+ @config_hash.delete('git')
40
+
41
+ File.stub(:read, @config_hash.to_yaml) do
42
+ assert_raises FlashFlow::Config::IncompleteConfiguration do
43
+ Config.configure!('unused_file_name.yml')
44
+ end
45
+ end
46
+ end
47
+
48
+ def test_that_it_sets_defaults
49
+ File.stub(:read, {'git' => {}}.to_yaml) do
50
+ Config.configure!('unused_file_name.yml')
51
+ assert('README.rdoc' == config.branch_info_file)
52
+ assert_nil(config.notifier)
53
+ assert_nil(config.lock)
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def config
60
+ Config.configuration
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,73 @@
1
+ require 'minitest_helper'
2
+
3
+ module FlashFlow
4
+ class TestGit < Minitest::Test
5
+ def setup
6
+ @git_args = {
7
+ 'merge_branch' => 'acceptance',
8
+ 'remote' => 'origin',
9
+ 'master_branch' => 'master',
10
+ 'use_rerere' => true
11
+ }
12
+ @cmd_runner = setup_cmd_runner
13
+ end
14
+
15
+ def test_initialize_rerere_checks_flag
16
+ @git_args['use_rerere'] = false
17
+
18
+ instance.initialize_rerere
19
+
20
+ @cmd_runner.verify
21
+ end
22
+
23
+ def test_initialize_rerere_runs_commands
24
+ @cmd_runner.expect(:run, true, ['mkdir .git/rr-cache'])
25
+ @cmd_runner.expect(:run, true, ['cp -R rr-cache/* .git/rr-cache/'])
26
+
27
+ instance.initialize_rerere
28
+ @cmd_runner.verify
29
+ end
30
+
31
+ def test_commit_rerere_checks_flag
32
+ @git_args['use_rerere'] = false
33
+ instance.commit_rerere([])
34
+
35
+ @cmd_runner.verify
36
+ end
37
+
38
+ def test_commit_rerere_runs_commands
39
+ @cmd_runner.expect(:run, true, ['mkdir rr-cache'])
40
+ @cmd_runner.expect(:run, true, ['rm -rf rr-cache/*'])
41
+ @cmd_runner.expect(:run, true, ['cp -R .git/rr-cache/xyz rr-cache/'])
42
+ @cmd_runner.expect(:run, true, ['cp -R .git/rr-cache/abc rr-cache/'])
43
+ @cmd_runner.expect(:run, true, ['git add rr-cache/', {}])
44
+ @cmd_runner.expect(:run, true, ["git commit -m 'Update rr-cache'", {}])
45
+
46
+ instance.commit_rerere(['xyz', 'abc'])
47
+ @cmd_runner.verify
48
+ end
49
+
50
+ def test_read_file_from_merge_branch
51
+ @cmd_runner.expect(:run, true, ["git show origin/acceptance:SomeFilename.txt", log: CmdRunner::LOG_CMD])
52
+ @cmd_runner.expect(:last_stdout, 'some_json', [])
53
+ @git_args['use_rerere'] = false
54
+
55
+ assert_equal(instance.read_file_from_merge_branch('SomeFilename.txt'), 'some_json')
56
+ @cmd_runner.verify
57
+ end
58
+
59
+ private
60
+ def instance
61
+ CmdRunner.stub(:new, @cmd_runner) do
62
+ _instance = Git.new(@git_args)
63
+ end
64
+ end
65
+
66
+ def setup_cmd_runner
67
+ cmd_runner = Minitest::Mock.new
68
+ cmd_runner.expect(:run, true, ['git rev-parse --abbrev-ref HEAD', {}])
69
+ cmd_runner.expect(:last_stdout, 'current_branch', [])
70
+ cmd_runner
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,71 @@
1
+ require 'minitest_helper'
2
+ require 'minitest/stub_any_instance'
3
+
4
+ module FlashFlow
5
+ class TestMergeOrder < Minitest::Test
6
+
7
+ def setup
8
+ @git = Minitest::Mock.new
9
+ end
10
+
11
+ def test_get_order_unchanged_shas_get_ordered_as_previous
12
+ mock_working_branch(sample_branches[2])
13
+ mock_current_sha(sample_branches[1], sample_branches[1].sha)
14
+ mock_current_sha(sample_branches[0], sample_branches[0].sha)
15
+ mock_current_sha(sample_branches[2], sample_branches[2].sha)
16
+
17
+ ordered_branches = MergeOrder.new(@git, mergeable_order(1,0,2)).get_order
18
+ assert_equal(ordered_branches.map(&:sha), mergeable_order(1,0,2).map(&:sha))
19
+ end
20
+
21
+ def test_get_order_changed_working_branch_is_always_last
22
+ mock_working_branch(sample_branches[0])
23
+ mock_current_sha(sample_branches[1], sample_branches[1].sha)
24
+ mock_current_sha(sample_branches[0], sample_branches[0].sha)
25
+ mock_current_sha(sample_branches[2], sample_branches[2].sha)
26
+
27
+ sample_branches[0].sha = 'sha0-1'
28
+
29
+ ordered_branches = MergeOrder.new(@git, mergeable_order(1,0,2)).get_order
30
+ assert_equal(ordered_branches.map(&:sha), mergeable_order(1,2,0).map(&:sha))
31
+ end
32
+ #
33
+ def test_get_order_changed_shas_are_between_unchanged_shas_and_changed_working_branch
34
+ mock_working_branch(sample_branches[1])
35
+ mock_current_sha(sample_branches[2], sample_branches[2].sha)
36
+ mock_current_sha(sample_branches[1], sample_branches[1].sha)
37
+ mock_current_sha(sample_branches[0], sample_branches[0].sha)
38
+
39
+ sample_branches[1].sha = 'sha0-1'
40
+ sample_branches[2].sha = 'sha2-1'
41
+
42
+ ordered_branches = MergeOrder.new(@git, mergeable_order(2,1,0)).get_order
43
+ assert_equal(ordered_branches.map(&:sha), mergeable_order(0,2,1).map(&:sha))
44
+ end
45
+
46
+ private
47
+
48
+ def mock_current_sha(branch, sha)
49
+ @git.expect(:remote, 'origin')
50
+ @git.expect(:get_sha, sha, ["origin/#{branch.ref}"])
51
+ end
52
+
53
+ def mock_working_branch(branch)
54
+ sample_branches.count.times { @git.expect(:working_branch, branch.ref) }
55
+ end
56
+
57
+ def sample_branches
58
+ @sample_branches ||= [Data::Branch.from_hash({'ref' => 'branch0', 'sha' => 'sha0', 'merge_order' => 1}),
59
+ Data::Branch.from_hash({'ref' => 'branch1', 'sha' => 'sha1', 'merge_order' => 2}),
60
+ Data::Branch.from_hash({'ref' => 'branch2', 'sha' => 'sha2', 'merge_order' => 3})]
61
+ end
62
+
63
+ def mergeable_order(*order)
64
+ order.map.with_index do |nth, merge_order|
65
+ sample_branches[nth].merge_order = (merge_order == 2 ? nil : merge_order)
66
+ sample_branches[nth]
67
+ end
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,33 @@
1
+ require 'minitest_helper'
2
+ require 'flash_flow/notifier'
3
+
4
+ module FlashFlow
5
+ module Notifier
6
+ class TestBase < Minitest::Test
7
+
8
+ class FakeNotifier
9
+ def initialize(_=nil); end
10
+
11
+ def merge_conflict(_=nil); 'merge conflict';end
12
+ def deleted_branch(_=nil); 'deleted_branch';end
13
+ end
14
+
15
+ def test_notifier_class_not_set
16
+ assert_nil(Notifier::Base.new.merge_conflict(nil))
17
+ assert_nil(Notifier::Base.new.deleted_branch(nil))
18
+ end
19
+
20
+ def test_notifier_class_set
21
+ assert_equal(FakeNotifier.new.merge_conflict, notifier.merge_conflict(nil))
22
+ assert_equal(FakeNotifier.new.deleted_branch, notifier.deleted_branch(nil))
23
+ end
24
+
25
+ private
26
+
27
+ def notifier
28
+ Notifier::Base
29
+ .new('class' => {'name' => 'FlashFlow::Notifier::TestBase::FakeNotifier'})
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,69 @@
1
+ require 'minitest_helper'
2
+
3
+ module FlashFlow
4
+ class TestResolve< Minitest::Test
5
+
6
+ class ResolveTester < Resolve
7
+ def in_working_branch
8
+ yield
9
+ end
10
+
11
+ def working_branch
12
+ 'working_branch'
13
+ end
14
+
15
+ def merge_conflicted
16
+ true
17
+ end
18
+
19
+ def launch_bash
20
+ puts 'launch_bash'
21
+ end
22
+
23
+ def rerere
24
+ puts 'rerere'
25
+ end
26
+
27
+ def git_reset
28
+ puts 'git_reset'
29
+ end
30
+
31
+ def branch
32
+ Data::Branch.from_hash({ 'metadata' => { 'conflict_sha' => '123' }})
33
+ end
34
+ end
35
+
36
+ def setup
37
+ @resolve_tester = ResolveTester.new({ 'merge_branch' => 'test_acceptance',
38
+ 'remote' => 'test_remote',
39
+ 'master_branch' => 'test_master',
40
+ 'use_rerere' => true
41
+ }, 'some_file')
42
+
43
+ @resolve = Resolve.new({ 'merge_branch' => 'test_acceptance',
44
+ 'remote' => 'test_remote',
45
+ 'master_branch' => 'test_master',
46
+ 'use_rerere' => true
47
+ }, 'some_file')
48
+ end
49
+
50
+ def test_no_conflict_sha
51
+ @resolve_tester.stub(:branch, Data::Branch.from_hash({ 'metadata' => { }})) do
52
+ assert_raises(Resolve::NothingToResolve) { @resolve_tester.start }
53
+ end
54
+ end
55
+
56
+ def test_conflicts_already_resolved
57
+ @resolve_tester.stub(:unresolved_conflicts, []) do
58
+ assert_output(/You have already resolved all conflicts/) { @resolve_tester.start }
59
+ end
60
+ end
61
+
62
+ def test_user_did_not_resolve_conflicts
63
+ @resolve_tester.stub(:unresolved_conflicts, ['conflict']) do
64
+ assert_output(/launch_bash.*rerere.*There are still.*git_reset/m) { @resolve_tester.start }
65
+ end
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,41 @@
1
+ require 'minitest'
2
+ require 'minitest/autorun'
3
+ require 'flash_flow'
4
+
5
+ ENV['GH_TOKEN'] = 'fake_token'
6
+
7
+ class Minitest::Test
8
+
9
+ class TestCmdRunner < Minitest::Mock
10
+ LOG_NONE = :log_none
11
+ LOG_CMD = :log_cmd
12
+
13
+ def initialize(opts={}); super(); end
14
+ def run(_, opts={}); end
15
+ def last_success?; true; end
16
+ def dir=(other); other; end
17
+ def last_stdout; ''; end
18
+ def last_stderr; ''; end
19
+ def last_command; ''; end
20
+ end
21
+
22
+ FlashFlow.send(:remove_const, :CmdRunner) if FlashFlow.const_defined?(:CmdRunner)
23
+ FlashFlow::CmdRunner = TestCmdRunner
24
+
25
+ def reset_config!
26
+ config = FlashFlow::Config.send(:instance)
27
+
28
+ config.instance_variables.each do |i|
29
+ config.remove_instance_variable(i)
30
+ end
31
+ end
32
+
33
+ def config!(config_hash)
34
+ reset_config!
35
+
36
+ File.stub(:read, config_hash.to_yaml) do
37
+ FlashFlow::Config.configure!('fake_file.txt')
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,5 @@
1
+ gem uninstall -x flash_flow
2
+ gem build flash_flow.gemspec
3
+ export VERSION=`ruby -r./lib/flash_flow/version -e "puts FlashFlow::VERSION"`
4
+ gem install flash_flow-$VERSION.gem --no-ri --no-rdoc
5
+ rbenv rehash
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: daq_flow
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Brad Bennett
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tb-bjb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-stub_any_instance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Flash flow is a command line tool for keeping your acceptance environment
98
+ up to date
99
+ email:
100
+ - bradleyjaybennett@gmail.com
101
+ executables:
102
+ - daq_flow
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".ruby-version"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/daq_flow
114
+ - flash_flow.gemspec
115
+ - flash_flow.yml.erb.example
116
+ - lib/flash_flow.rb
117
+ - lib/flash_flow/branch_merger.rb
118
+ - lib/flash_flow/cmd_runner.rb
119
+ - lib/flash_flow/config.rb
120
+ - lib/flash_flow/data.rb
121
+ - lib/flash_flow/data/base.rb
122
+ - lib/flash_flow/data/bitbucket.rb
123
+ - lib/flash_flow/data/branch.rb
124
+ - lib/flash_flow/data/collection.rb
125
+ - lib/flash_flow/data/github.rb
126
+ - lib/flash_flow/data/store.rb
127
+ - lib/flash_flow/git.rb
128
+ - lib/flash_flow/install.rb
129
+ - lib/flash_flow/lock.rb
130
+ - lib/flash_flow/merge.rb
131
+ - lib/flash_flow/merge/acceptance.rb
132
+ - lib/flash_flow/merge/base.rb
133
+ - lib/flash_flow/merge_order.rb
134
+ - lib/flash_flow/notifier.rb
135
+ - lib/flash_flow/options.rb
136
+ - lib/flash_flow/resolve.rb
137
+ - lib/flash_flow/shadow_repo.rb
138
+ - lib/flash_flow/time_helper.rb
139
+ - lib/flash_flow/version.rb
140
+ - log/.keep
141
+ - test/lib/data/test_base.rb
142
+ - test/lib/data/test_branch.rb
143
+ - test/lib/data/test_collection.rb
144
+ - test/lib/data/test_store.rb
145
+ - test/lib/lock/test_github.rb
146
+ - test/lib/merge/test_acceptance.rb
147
+ - test/lib/test_branch_merger.rb
148
+ - test/lib/test_config.rb
149
+ - test/lib/test_git.rb
150
+ - test/lib/test_merge_order.rb
151
+ - test/lib/test_notifier.rb
152
+ - test/lib/test_resolve.rb
153
+ - test/minitest_helper.rb
154
+ - update_gem.sh
155
+ homepage: https://github.com/bradleyjucsc/flash_flow
156
+ licenses:
157
+ - MIT
158
+ metadata: {}
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.7.6
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: Merge your open prs together
179
+ test_files:
180
+ - test/lib/data/test_base.rb
181
+ - test/lib/data/test_branch.rb
182
+ - test/lib/data/test_collection.rb
183
+ - test/lib/data/test_store.rb
184
+ - test/lib/lock/test_github.rb
185
+ - test/lib/merge/test_acceptance.rb
186
+ - test/lib/test_branch_merger.rb
187
+ - test/lib/test_config.rb
188
+ - test/lib/test_git.rb
189
+ - test/lib/test_merge_order.rb
190
+ - test/lib/test_notifier.rb
191
+ - test/lib/test_resolve.rb
192
+ - test/minitest_helper.rb