geet 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -10
  3. data/Gemfile.lock +8 -2
  4. data/README.md +27 -2
  5. data/Rakefile +3 -1
  6. data/bin/geet +37 -17
  7. data/geet.gemspec +3 -1
  8. data/lib/geet/commandline/configuration.rb +18 -5
  9. data/lib/geet/commandline/editor.rb +14 -24
  10. data/lib/geet/git/repository.rb +30 -84
  11. data/lib/geet/github/api_interface.rb +11 -3
  12. data/lib/geet/github/gist.rb +1 -0
  13. data/lib/geet/gitlab/api_interface.rb +5 -2
  14. data/lib/geet/helpers/os_helper.rb +36 -3
  15. data/lib/geet/helpers/summary_helper.rb +20 -0
  16. data/lib/geet/resources/{edit_summary_template.md → templates/edit_summary.md} +0 -3
  17. data/lib/geet/services/create_gist.rb +18 -2
  18. data/lib/geet/services/create_issue.rb +46 -21
  19. data/lib/geet/services/create_label.rb +8 -4
  20. data/lib/geet/services/create_pr.rb +67 -18
  21. data/lib/geet/services/list_issues.rb +9 -5
  22. data/lib/geet/services/list_labels.rb +6 -2
  23. data/lib/geet/services/list_milestones.rb +11 -7
  24. data/lib/geet/services/list_prs.rb +6 -2
  25. data/lib/geet/services/merge_pr.rb +18 -11
  26. data/lib/geet/utils/git_client.rb +160 -0
  27. data/lib/geet/utils/manual_list_selection.rb +41 -23
  28. data/lib/geet/version.rb +1 -1
  29. data/spec/integration/create_gist_spec.rb +2 -5
  30. data/spec/integration/create_issue_spec.rb +10 -10
  31. data/spec/integration/create_label_spec.rb +30 -5
  32. data/spec/integration/create_pr_spec.rb +85 -10
  33. data/spec/integration/list_issues_spec.rb +12 -11
  34. data/spec/integration/list_labels_spec.rb +28 -5
  35. data/spec/integration/list_milestones_spec.rb +30 -3
  36. data/spec/integration/list_prs_spec.rb +8 -7
  37. data/spec/integration/merge_pr_spec.rb +8 -7
  38. data/spec/vcr_cassettes/create_gist_private.yml +1 -1
  39. data/spec/vcr_cassettes/create_gist_public.yml +1 -1
  40. data/spec/vcr_cassettes/create_issue.yml +9 -9
  41. data/spec/vcr_cassettes/create_issue_upstream.yml +3 -3
  42. data/spec/vcr_cassettes/create_label.yml +1 -1
  43. data/spec/vcr_cassettes/create_label_upstream.yml +80 -0
  44. data/spec/vcr_cassettes/create_label_with_random_color.yml +1 -1
  45. data/spec/vcr_cassettes/create_pr.yml +13 -13
  46. data/spec/vcr_cassettes/create_pr_in_auto_mode_create_upstream.yml +235 -0
  47. data/spec/vcr_cassettes/create_pr_in_auto_mode_with_push.yml +235 -0
  48. data/spec/vcr_cassettes/create_pr_upstream.yml +4 -4
  49. data/spec/vcr_cassettes/github_com/list_issues.yml +5 -5
  50. data/spec/vcr_cassettes/github_com/list_issues_upstream.yml +6 -6
  51. data/spec/vcr_cassettes/github_com/list_issues_with_assignee.yml +4 -4
  52. data/spec/vcr_cassettes/github_com/list_labels.yml +1 -1
  53. data/spec/vcr_cassettes/github_com/list_labels_upstream.yml +78 -0
  54. data/spec/vcr_cassettes/gitlab_com/list_issues.yml +5 -5
  55. data/spec/vcr_cassettes/gitlab_com/list_labels.yml +1 -1
  56. data/spec/vcr_cassettes/list_milestones.yml +15 -15
  57. data/spec/vcr_cassettes/list_milestones_upstream.yml +155 -0
  58. data/spec/vcr_cassettes/list_prs.yml +6 -6
  59. data/spec/vcr_cassettes/list_prs_upstream.yml +3 -3
  60. data/spec/vcr_cassettes/merge_pr.yml +2 -2
  61. data/spec/vcr_cassettes/merge_pr_with_branch_deletion.yml +2 -2
  62. metadata +24 -4
  63. data/lib/geet/utils/git.rb +0 -30
@@ -6,11 +6,13 @@ require_relative '../../lib/geet/git/repository'
6
6
  require_relative '../../lib/geet/services/create_label'
7
7
 
8
8
  describe Geet::Services::CreateLabel do
9
- let(:repository) { Geet::Git::Repository.new }
9
+ let(:git_client) { Geet::Utils::GitClient.new }
10
+ let(:repository) { Geet::Git::Repository.new(git_client: git_client) }
11
+ let(:upstream_repository) { Geet::Git::Repository.new(upstream: true, git_client: git_client) }
10
12
 
11
13
  context 'with user-specified color' do
12
14
  it 'should create a label' do
13
- allow(repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
15
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
14
16
 
15
17
  expected_output = <<~STR
16
18
  Creating label...
@@ -20,7 +22,7 @@ describe Geet::Services::CreateLabel do
20
22
  actual_output = StringIO.new
21
23
 
22
24
  actual_created_label = VCR.use_cassette('create_label') do
23
- described_class.new.execute(repository, 'my_label', color: 'c64c64', output: actual_output)
25
+ described_class.new(repository).execute('my_label', color: 'c64c64', output: actual_output)
24
26
  end
25
27
 
26
28
  expect(actual_output.string).to eql(expected_output)
@@ -28,11 +30,34 @@ describe Geet::Services::CreateLabel do
28
30
  expect(actual_created_label.name).to eql('my_label')
29
31
  expect(actual_created_label.color).to eql('c64c64')
30
32
  end
33
+
34
+ context 'upstream' do
35
+ it 'should create a label' do
36
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
37
+ allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:donaldduck-fr/testrepo_gh')
38
+
39
+ expected_output = <<~STR
40
+ Creating label...
41
+ Created with color #c64c64
42
+ STR
43
+
44
+ actual_output = StringIO.new
45
+
46
+ actual_created_label = VCR.use_cassette('create_label_upstream') do
47
+ described_class.new(upstream_repository).execute('my_label', color: 'c64c64', output: actual_output)
48
+ end
49
+
50
+ expect(actual_output.string).to eql(expected_output)
51
+
52
+ expect(actual_created_label.name).to eql('my_label')
53
+ expect(actual_created_label.color).to eql('c64c64')
54
+ end
55
+ end
31
56
  end
32
57
 
33
58
  context 'with auto-generated color' do
34
59
  it 'should create a label' do
35
- allow(repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
60
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
36
61
 
37
62
  expected_output_template = <<~STR
38
63
  Creating label...
@@ -42,7 +67,7 @@ describe Geet::Services::CreateLabel do
42
67
  actual_output = StringIO.new
43
68
 
44
69
  actual_created_label = VCR.use_cassette('create_label_with_random_color') do
45
- described_class.new.execute(repository, 'my_label', output: actual_output)
70
+ described_class.new(repository).execute('my_label', output: actual_output)
46
71
  end
47
72
 
48
73
  expected_output = format(expected_output_template, color: actual_created_label.color)
@@ -6,13 +6,14 @@ require_relative '../../lib/geet/git/repository'
6
6
  require_relative '../../lib/geet/services/create_pr'
7
7
 
8
8
  describe Geet::Services::CreatePr do
9
- let(:repository) { Geet::Git::Repository.new }
10
- let(:upstream_repository) { Geet::Git::Repository.new(upstream: true) }
9
+ let(:git_client) { Geet::Utils::GitClient.new }
10
+ let(:repository) { Geet::Git::Repository.new(git_client: git_client, warnings: false) }
11
+ let(:upstream_repository) { Geet::Git::Repository.new(upstream: true, git_client: git_client, warnings: false) }
11
12
 
12
13
  context 'with labels, reviewers and milestones' do
13
14
  it 'should create a PR' do
14
- allow(repository).to receive(:current_branch).and_return('mybranch1')
15
- allow(repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
15
+ allow(git_client).to receive(:current_branch).and_return('mybranch1')
16
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
16
17
 
17
18
  expected_output = <<~STR
18
19
  Finding labels...
@@ -29,8 +30,9 @@ describe Geet::Services::CreatePr do
29
30
  actual_output = StringIO.new
30
31
 
31
32
  actual_created_pr = VCR.use_cassette('create_pr') do
32
- described_class.new.execute(
33
- repository, 'Title', 'Description',
33
+ service_instance = described_class.new(repository, git_client: git_client)
34
+ service_instance.execute(
35
+ 'Title', 'Description',
34
36
  label_patterns: '_bug,invalid', milestone_pattern: '0.0.1', reviewer_patterns: 'nald-ts,nald-fr',
35
37
  no_open_pr: true, output: actual_output
36
38
  )
@@ -45,9 +47,9 @@ describe Geet::Services::CreatePr do
45
47
  end
46
48
 
47
49
  it 'should create an upstream PR' do
48
- allow(upstream_repository).to receive(:current_branch).and_return('mybranch')
49
- allow(upstream_repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_2f')
50
- allow(upstream_repository).to receive(:remote).with('upstream').and_return('git@github.com:donald-fr/testrepo_u')
50
+ allow(git_client).to receive(:current_branch).and_return('mybranch')
51
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_2f')
52
+ allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:donald-fr/testrepo_u')
51
53
 
52
54
  expected_output = <<~STR
53
55
  Creating PR...
@@ -58,7 +60,8 @@ describe Geet::Services::CreatePr do
58
60
  actual_output = StringIO.new
59
61
 
60
62
  actual_created_pr = VCR.use_cassette('create_pr_upstream') do
61
- described_class.new.execute(upstream_repository, 'Title', 'Description', no_open_pr: true, output: actual_output)
63
+ service_instance = described_class.new(upstream_repository, git_client: git_client)
64
+ service_instance.execute('Title', 'Description', no_open_pr: true, output: actual_output)
62
65
  end
63
66
 
64
67
  expect(actual_output.string).to eql(expected_output)
@@ -67,4 +70,76 @@ describe Geet::Services::CreatePr do
67
70
  expect(actual_created_pr.title).to eql('Title')
68
71
  expect(actual_created_pr.link).to eql('https://github.com/donald-fr/testrepo_u/pull/4')
69
72
  end
73
+
74
+ context 'in automated mode' do
75
+ it 'should raise an error when the working tree is dirty' do
76
+ allow(git_client).to receive(:working_tree_clean?).and_return(false)
77
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_2f')
78
+
79
+ expected_output = <<~STR
80
+ Error! Saved summary to /tmp/last_geet_edited_summary.md
81
+ STR
82
+
83
+ actual_output = StringIO.new
84
+
85
+ operation = -> do
86
+ service_instance = described_class.new(repository, git_client: git_client)
87
+ service_instance.execute('Title', 'Description', output: actual_output, automated_mode: true, no_open_pr: true)
88
+ end
89
+
90
+ expect(operation).to raise_error(RuntimeError, 'The working tree is not clean!')
91
+
92
+ expect(actual_output.string).to eql(expected_output)
93
+ end
94
+
95
+ it 'should push to the upstream branch' do
96
+ allow(git_client).to receive(:working_tree_clean?).and_return(true)
97
+ allow(git_client).to receive(:current_branch).and_return('mybranch')
98
+ expect(git_client).to receive(:upstream_branch).and_return('mybranch')
99
+ expect(git_client).to receive(:push)
100
+
101
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
102
+
103
+ expected_output = <<~STR
104
+ Pushing to upstream branch...
105
+ Creating PR...
106
+ Assigning authenticated user...
107
+ PR address: https://github.com/donaldduck/testrepo/pull/29
108
+ STR
109
+
110
+ actual_output = StringIO.new
111
+
112
+ actual_created_pr = VCR.use_cassette('create_pr_in_auto_mode_with_push') do
113
+ service_instance = described_class.new(repository, git_client: git_client)
114
+ service_instance.execute('Title', 'Description', output: actual_output, automated_mode: true, no_open_pr: true)
115
+ end
116
+
117
+ expect(actual_output.string).to eql(expected_output)
118
+ end
119
+
120
+ it "should create an upstream branch, when there isn't one" do
121
+ allow(git_client).to receive(:working_tree_clean?).and_return(true)
122
+ allow(git_client).to receive(:current_branch).and_return('mybranch')
123
+ expect(git_client).to receive(:upstream_branch).and_return(nil)
124
+ expect(git_client).to receive(:push).with(upstream_branch: 'mybranch')
125
+
126
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
127
+
128
+ expected_output = <<~STR
129
+ Creating upstream branch "mybranch"...
130
+ Creating PR...
131
+ Assigning authenticated user...
132
+ PR address: https://github.com/donaldduck/testrepo/pull/30
133
+ STR
134
+
135
+ actual_output = StringIO.new
136
+
137
+ actual_created_pr = VCR.use_cassette('create_pr_in_auto_mode_create_upstream') do
138
+ service_instance = described_class.new(repository, git_client: git_client)
139
+ service_instance.execute('Title', 'Description', output: actual_output, automated_mode: true, no_open_pr: true)
140
+ end
141
+
142
+ expect(actual_output.string).to eql(expected_output)
143
+ end
144
+ end
70
145
  end
@@ -6,12 +6,13 @@ require_relative '../../lib/geet/git/repository'
6
6
  require_relative '../../lib/geet/services/list_issues'
7
7
 
8
8
  describe Geet::Services::ListIssues do
9
- let(:repository) { Geet::Git::Repository.new }
10
- let(:upstream_repository) { Geet::Git::Repository.new(upstream: true) }
9
+ let(:git_client) { Geet::Utils::GitClient.new }
10
+ let(:repository) { Geet::Git::Repository.new(git_client: git_client) }
11
+ let(:upstream_repository) { Geet::Git::Repository.new(upstream: true, git_client: git_client) }
11
12
 
12
13
  context 'with github.com' do
13
14
  it 'should list the default issues' do
14
- allow(repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
15
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
15
16
 
16
17
  expected_output = <<~STR
17
18
  5. Title 2 (https://github.com/donaldduck/testrepo/issues/5)
@@ -22,7 +23,7 @@ describe Geet::Services::ListIssues do
22
23
  actual_output = StringIO.new
23
24
 
24
25
  service_result = VCR.use_cassette('github_com/list_issues') do
25
- described_class.new.execute(repository, output: actual_output)
26
+ described_class.new(repository).execute(output: actual_output)
26
27
  end
27
28
 
28
29
  actual_issue_numbers = service_result.map(&:number)
@@ -33,7 +34,7 @@ describe Geet::Services::ListIssues do
33
34
 
34
35
  context 'with assignee filtering' do
35
36
  it 'should list the issues' do
36
- allow(repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_gh')
37
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_gh')
37
38
 
38
39
  expected_output = <<~STR
39
40
  Finding assignee...
@@ -45,7 +46,7 @@ describe Geet::Services::ListIssues do
45
46
  actual_output = StringIO.new
46
47
 
47
48
  service_result = VCR.use_cassette('github_com/list_issues_with_assignee') do
48
- described_class.new.execute(repository, assignee_pattern: 'donald-fr', output: actual_output)
49
+ described_class.new(repository).execute(assignee_pattern: 'donald-fr', output: actual_output)
49
50
  end
50
51
 
51
52
  actual_issue_numbers = service_result.map(&:number)
@@ -56,8 +57,8 @@ describe Geet::Services::ListIssues do
56
57
  end
57
58
 
58
59
  it 'should list the upstream issues' do
59
- allow(upstream_repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_2f')
60
- allow(upstream_repository).to receive(:remote).with('upstream').and_return('git@github.com:donald-fr/testrepo_u')
60
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_2f')
61
+ allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:donald-fr/testrepo_u')
61
62
 
62
63
  expected_output = <<~STR
63
64
  2. Title 2 U (https://github.com/donald-fr/testrepo_u/issues/2)
@@ -68,7 +69,7 @@ describe Geet::Services::ListIssues do
68
69
  actual_output = StringIO.new
69
70
 
70
71
  service_result = VCR.use_cassette('github_com/list_issues_upstream') do
71
- described_class.new.execute(upstream_repository, output: actual_output)
72
+ described_class.new(upstream_repository).execute(output: actual_output)
72
73
  end
73
74
 
74
75
  actual_issue_numbers = service_result.map(&:number)
@@ -80,7 +81,7 @@ describe Geet::Services::ListIssues do
80
81
 
81
82
  context 'with gitlab.com' do
82
83
  it 'should list the issues' do
83
- allow(repository).to receive(:remote).with('origin').and_return('git@gitlab.com:donaldduck/testproject')
84
+ allow(git_client).to receive(:remote).with('origin').and_return('git@gitlab.com:donaldduck/testproject')
84
85
 
85
86
  expected_output = <<~STR
86
87
  2. I like more pizza (https://gitlab.com/donaldduck/testproject/issues/2)
@@ -91,7 +92,7 @@ describe Geet::Services::ListIssues do
91
92
  actual_output = StringIO.new
92
93
 
93
94
  service_result = VCR.use_cassette('gitlab_com/list_issues') do
94
- described_class.new.execute(repository, output: actual_output)
95
+ described_class.new(repository).execute(output: actual_output)
95
96
  end
96
97
 
97
98
  actual_issue_numbers = service_result.map(&:number)
@@ -6,11 +6,13 @@ require_relative '../../lib/geet/git/repository'
6
6
  require_relative '../../lib/geet/services/list_labels'
7
7
 
8
8
  describe Geet::Services::ListLabels do
9
- let(:repository) { Geet::Git::Repository.new }
9
+ let(:git_client) { Geet::Utils::GitClient.new }
10
+ let(:repository) { Geet::Git::Repository.new(git_client: git_client) }
11
+ let(:upstream_repository) { Geet::Git::Repository.new(upstream: true, git_client: git_client) }
10
12
 
11
13
  context 'with github.com' do
12
14
  it 'should list the labels' do
13
- allow(repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/geet')
15
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/geet')
14
16
 
15
17
  expected_output = <<~STR
16
18
  - bug (#ee0701)
@@ -22,7 +24,28 @@ describe Geet::Services::ListLabels do
22
24
 
23
25
  actual_output = StringIO.new
24
26
  actual_labels = VCR.use_cassette('github.com/list_labels') do
25
- described_class.new.execute(repository, output: actual_output)
27
+ described_class.new(repository).execute(output: actual_output)
28
+ end
29
+
30
+ actual_label_names = actual_labels.map(&:name)
31
+
32
+ expect(actual_output.string).to eql(expected_output)
33
+ expect(actual_label_names).to eql(expected_label_names)
34
+ end
35
+
36
+ it 'should list the upstream labels' do
37
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/geet')
38
+ allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:donaldduck-fr/testrepo_u')
39
+
40
+ expected_output = <<~STR
41
+ - bug (#ee0701)
42
+ - enhancement (#c2e0c6)
43
+ STR
44
+ expected_label_names = %w[bug enhancement]
45
+
46
+ actual_output = StringIO.new
47
+ actual_labels = VCR.use_cassette('github.com/list_labels_upstream') do
48
+ described_class.new(upstream_repository).execute(output: actual_output)
26
49
  end
27
50
 
28
51
  actual_label_names = actual_labels.map(&:name)
@@ -34,7 +57,7 @@ describe Geet::Services::ListLabels do
34
57
 
35
58
  context 'with gitlab.com' do
36
59
  it 'should list the labels' do
37
- allow(repository).to receive(:remote).with('origin').and_return('git@gitlab.com:donaldduck/testproject')
60
+ allow(git_client).to receive(:remote).with('origin').and_return('git@gitlab.com:donaldduck/testproject')
38
61
 
39
62
  expected_output = <<~STR
40
63
  - bug (#d9534f)
@@ -50,7 +73,7 @@ describe Geet::Services::ListLabels do
50
73
 
51
74
  actual_output = StringIO.new
52
75
  actual_labels = VCR.use_cassette('gitlab.com/list_labels') do
53
- described_class.new.execute(repository, output: actual_output)
76
+ described_class.new(repository).execute(output: actual_output)
54
77
  end
55
78
 
56
79
  actual_label_names = actual_labels.map(&:name)
@@ -6,10 +6,12 @@ require_relative '../../lib/geet/git/repository'
6
6
  require_relative '../../lib/geet/services/list_milestones'
7
7
 
8
8
  describe Geet::Services::ListMilestones do
9
- let(:repository) { Geet::Git::Repository.new }
9
+ let(:git_client) { Geet::Utils::GitClient.new }
10
+ let(:repository) { Geet::Git::Repository.new(git_client: git_client) }
11
+ let(:upstream_repository) { Geet::Git::Repository.new(upstream: true, git_client: git_client) }
10
12
 
11
13
  it 'should list the milestones' do
12
- allow(repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/geet')
14
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/geet')
13
15
 
14
16
  expected_output = <<~STR
15
17
  Finding milestones...
@@ -34,7 +36,32 @@ describe Geet::Services::ListMilestones do
34
36
  actual_output = StringIO.new
35
37
 
36
38
  service_result = VCR.use_cassette('list_milestones') do
37
- described_class.new.execute(repository, output: actual_output)
39
+ described_class.new(repository).execute(output: actual_output)
40
+ end
41
+
42
+ actual_milestone_numbers = service_result.map(&:number)
43
+
44
+ expect(actual_output.string).to eql(expected_output)
45
+ expect(actual_milestone_numbers).to eql(expected_milestone_numbers)
46
+ end
47
+
48
+ it 'should list the upstream milestones' do
49
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/geet')
50
+ allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:donald-fr/testrepo_u')
51
+
52
+ expected_output = <<~STR
53
+ Finding milestones...
54
+ Finding issues...
55
+
56
+ 1. Milestone 1 Up
57
+ 32. t (https://github.com/donald-fr/testrepo_u/issues/32)
58
+ STR
59
+ expected_milestone_numbers = [1]
60
+
61
+ actual_output = StringIO.new
62
+
63
+ service_result = VCR.use_cassette('list_milestones_upstream') do
64
+ described_class.new(upstream_repository).execute(output: actual_output)
38
65
  end
39
66
 
40
67
  actual_milestone_numbers = service_result.map(&:number)
@@ -6,11 +6,12 @@ require_relative '../../lib/geet/git/repository'
6
6
  require_relative '../../lib/geet/services/list_prs'
7
7
 
8
8
  describe Geet::Services::ListPrs do
9
- let(:repository) { Geet::Git::Repository.new }
10
- let(:upstream_repository) { Geet::Git::Repository.new(upstream: true) }
9
+ let(:git_client) { Geet::Utils::GitClient.new }
10
+ let(:repository) { Geet::Git::Repository.new(git_client: git_client) }
11
+ let(:upstream_repository) { Geet::Git::Repository.new(upstream: true, git_client: git_client) }
11
12
 
12
13
  it 'should list the PRs' do
13
- allow(repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
14
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
14
15
 
15
16
  expected_output = <<~STR
16
17
  6. Title 2 (https://github.com/donaldduck/testrepo/pull/6)
@@ -21,7 +22,7 @@ describe Geet::Services::ListPrs do
21
22
  actual_output = StringIO.new
22
23
 
23
24
  service_result = VCR.use_cassette('list_prs') do
24
- described_class.new.execute(repository, output: actual_output)
25
+ described_class.new(repository).execute(output: actual_output)
25
26
  end
26
27
 
27
28
  actual_pr_numbers = service_result.map(&:number)
@@ -31,8 +32,8 @@ describe Geet::Services::ListPrs do
31
32
  end
32
33
 
33
34
  it 'should list the upstream PRs' do
34
- allow(upstream_repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_2f')
35
- allow(upstream_repository).to receive(:remote).with('upstream').and_return('git@github.com:donald-fr/testrepo_u')
35
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_2f')
36
+ allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:donald-fr/testrepo_u')
36
37
 
37
38
  expected_output = <<~STR
38
39
  5. Title 2 (https://github.com/donald-fr/testrepo_u/pull/5)
@@ -43,7 +44,7 @@ describe Geet::Services::ListPrs do
43
44
  actual_output = StringIO.new
44
45
 
45
46
  service_result = VCR.use_cassette('list_prs_upstream') do
46
- described_class.new.execute(upstream_repository, output: actual_output)
47
+ described_class.new(upstream_repository).execute(output: actual_output)
47
48
  end
48
49
 
49
50
  actual_pr_numbers = service_result.map(&:number)
@@ -6,11 +6,12 @@ require_relative '../../lib/geet/git/repository'
6
6
  require_relative '../../lib/geet/services/merge_pr'
7
7
 
8
8
  describe Geet::Services::MergePr do
9
- let(:repository) { Geet::Git::Repository.new }
9
+ let(:git_client) { Geet::Utils::GitClient.new }
10
+ let(:repository) { Geet::Git::Repository.new(git_client: git_client) }
10
11
 
11
12
  it 'should merge the PR for the current branch' do
12
- allow(repository).to receive(:current_branch).and_return('mybranch1')
13
- allow(repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
13
+ allow(git_client).to receive(:current_branch).and_return('mybranch1')
14
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
14
15
 
15
16
  expected_output = <<~STR
16
17
  Finding PR with head (mybranch1)...
@@ -21,7 +22,7 @@ describe Geet::Services::MergePr do
21
22
  actual_output = StringIO.new
22
23
 
23
24
  service_result = VCR.use_cassette('merge_pr') do
24
- described_class.new.execute(repository, output: actual_output)
25
+ described_class.new(repository, git_client: git_client).execute(output: actual_output)
25
26
  end
26
27
 
27
28
  actual_pr_number = service_result.number
@@ -31,8 +32,8 @@ describe Geet::Services::MergePr do
31
32
  end
32
33
 
33
34
  it 'should merge the PR for the current branch, with branch deletion' do
34
- allow(repository).to receive(:current_branch).and_return('mybranch')
35
- allow(repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
35
+ allow(git_client).to receive(:current_branch).and_return('mybranch')
36
+ allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
36
37
 
37
38
  expected_output = <<~STR
38
39
  Finding PR with head (mybranch)...
@@ -44,7 +45,7 @@ describe Geet::Services::MergePr do
44
45
  actual_output = StringIO.new
45
46
 
46
47
  service_result = VCR.use_cassette('merge_pr_with_branch_deletion') do
47
- described_class.new.execute(repository, delete_branch: true, output: actual_output)
48
+ described_class.new(repository, git_client: git_client).execute(delete_branch: true, output: actual_output)
48
49
  end
49
50
 
50
51
  actual_pr_number = service_result.number