geet 0.3.15 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +7 -0
  4. data/README.md +4 -9
  5. data/bin/geet +19 -8
  6. data/geet.gemspec +1 -1
  7. data/lib/geet/commandline/commands.rb +3 -0
  8. data/lib/geet/commandline/configuration.rb +20 -1
  9. data/lib/geet/git/repository.rb +17 -3
  10. data/lib/geet/github/api_interface.rb +2 -0
  11. data/lib/geet/github/branch.rb +1 -1
  12. data/lib/geet/github/issue.rb +2 -2
  13. data/lib/geet/github/label.rb +2 -2
  14. data/lib/geet/github/milestone.rb +16 -3
  15. data/lib/geet/github/pr.rb +2 -3
  16. data/lib/geet/github/remote_repository.rb +37 -0
  17. data/lib/geet/github/user.rb +2 -2
  18. data/lib/geet/gitlab/api_interface.rb +2 -0
  19. data/lib/geet/gitlab/label.rb +2 -2
  20. data/lib/geet/gitlab/milestone.rb +1 -1
  21. data/lib/geet/gitlab/user.rb +1 -1
  22. data/lib/geet/helpers/os_helper.rb +4 -3
  23. data/lib/geet/services/add_upstream_repo.rb +37 -0
  24. data/lib/geet/services/close_milestones.rb +46 -0
  25. data/lib/geet/services/create_issue.rb +5 -3
  26. data/lib/geet/services/create_pr.rb +11 -7
  27. data/lib/geet/services/list_issues.rb +4 -1
  28. data/lib/geet/services/merge_pr.rb +55 -4
  29. data/lib/geet/services/open_repo.rb +50 -0
  30. data/lib/geet/shared/selection.rb +3 -0
  31. data/lib/geet/utils/attributes_selection_manager.rb +12 -3
  32. data/lib/geet/utils/git_client.rb +122 -29
  33. data/lib/geet/version.rb +1 -1
  34. data/spec/integration/comment_pr_spec.rb +1 -1
  35. data/spec/integration/create_issue_spec.rb +4 -4
  36. data/spec/integration/create_label_spec.rb +5 -5
  37. data/spec/integration/create_milestone_spec.rb +1 -1
  38. data/spec/integration/create_pr_spec.rb +13 -8
  39. data/spec/integration/list_issues_spec.rb +6 -6
  40. data/spec/integration/list_labels_spec.rb +4 -4
  41. data/spec/integration/list_milestones_spec.rb +4 -4
  42. data/spec/integration/list_prs_spec.rb +3 -3
  43. data/spec/integration/merge_pr_spec.rb +33 -4
  44. data/spec/integration/open_pr_spec.rb +1 -1
  45. data/spec/integration/open_repo_spec.rb +46 -0
  46. data/spec/vcr_cassettes/create_issue.yml +1 -1
  47. data/spec/vcr_cassettes/create_issue_upstream.yml +1 -1
  48. data/spec/vcr_cassettes/github_com/create_pr.yml +1 -1
  49. data/spec/vcr_cassettes/github_com/create_pr_in_auto_mode_create_upstream.yml +1 -1
  50. data/spec/vcr_cassettes/github_com/create_pr_in_auto_mode_with_push.yml +1 -1
  51. data/spec/vcr_cassettes/github_com/create_pr_upstream.yml +1 -1
  52. data/spec/vcr_cassettes/github_com/create_pr_upstream_without_write_permissions.yml +1 -1
  53. metadata +8 -3
data/lib/geet/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Geet
4
- VERSION = '0.3.15'
4
+ VERSION = '0.4.1'
5
5
  end
@@ -17,7 +17,7 @@ describe Geet::Services::CommentPr do
17
17
 
18
18
  it 'should add a comment to the PR for the current branch' do
19
19
  allow(git_client).to receive(:current_branch).and_return(branch)
20
- allow(git_client).to receive(:remote).with('origin').and_return("git@github.com:#{owner}/#{repository_name}")
20
+ allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:#{owner}/#{repository_name}")
21
21
 
22
22
  expected_pr_number = 3
23
23
  expected_output = <<~STR
@@ -12,7 +12,7 @@ describe Geet::Services::CreateIssue do
12
12
 
13
13
  context 'with labels, assignees and milestones' do
14
14
  it 'should create an issue' do
15
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_f')
15
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
16
16
 
17
17
  expected_output = <<~STR
18
18
  Finding labels...
@@ -47,8 +47,8 @@ describe Geet::Services::CreateIssue do
47
47
  context 'without labels, assignees and milestones' do
48
48
  it 'should create an upstream issue' do
49
49
  allow(git_client).to receive(:current_branch).and_return('mybranch')
50
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
51
- allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:momcorp/therepo')
50
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo')
51
+ allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:momcorp/therepo')
52
52
 
53
53
  expected_output = <<~STR
54
54
  Creating the issue...
@@ -59,7 +59,7 @@ describe Geet::Services::CreateIssue do
59
59
 
60
60
  actual_created_issue = VCR.use_cassette('create_issue_upstream') do
61
61
  create_options = { no_open_issue: true, out: actual_output }
62
- described_class.new(upstream_repository, out: actual_output).execute('Title', 'Description', create_options)
62
+ described_class.new(upstream_repository, out: actual_output).execute('Title', 'Description', **create_options)
63
63
  end
64
64
 
65
65
  expect(actual_output.string).to eql(expected_output)
@@ -13,7 +13,7 @@ describe Geet::Services::CreateLabel do
13
13
  context 'with github.com' do
14
14
  context 'with user-specified color' do
15
15
  it 'should create a label' do
16
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
16
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo')
17
17
 
18
18
  expected_output = <<~STR
19
19
  Creating label...
@@ -34,8 +34,8 @@ describe Geet::Services::CreateLabel do
34
34
 
35
35
  context 'upstream' do
36
36
  it 'should create a label' do
37
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
38
- allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:donaldduck-fr/testrepo_gh')
37
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo')
38
+ allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:donaldduck-fr/testrepo_gh')
39
39
 
40
40
  expected_output = <<~STR
41
41
  Creating label...
@@ -58,7 +58,7 @@ describe Geet::Services::CreateLabel do
58
58
 
59
59
  context 'with auto-generated color' do
60
60
  it 'should create a label' do
61
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
61
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo')
62
62
 
63
63
  actual_output = StringIO.new
64
64
 
@@ -87,7 +87,7 @@ describe Geet::Services::CreateLabel do
87
87
 
88
88
  context 'with gitlab.com' do
89
89
  it 'should create a label' do
90
- allow(git_client).to receive(:remote).with('origin').and_return('git@gitlab.com:donaldduck/testproject')
90
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@gitlab.com:donaldduck/testproject')
91
91
 
92
92
  expected_output = <<~STR
93
93
  Creating label...
@@ -12,7 +12,7 @@ describe Geet::Services::CreateMilestone do
12
12
 
13
13
  context 'with github.com' do
14
14
  it 'should create a milestone' do
15
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_upstream')
15
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_upstream')
16
16
 
17
17
  expected_output = <<~STR
18
18
  Creating milestone...
@@ -14,7 +14,8 @@ describe Geet::Services::CreatePr do
14
14
  context 'with labels, reviewers and milestones' do
15
15
  it 'should create a PR' do
16
16
  allow(git_client).to receive(:current_branch).and_return('mybranch')
17
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_f')
17
+ allow(git_client).to receive(:main_branch).and_return('master')
18
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
18
19
 
19
20
  expected_output = <<~STR
20
21
  Finding labels...
@@ -50,8 +51,9 @@ describe Geet::Services::CreatePr do
50
51
  context 'on an upstream repository' do
51
52
  it 'should create an upstream PR' do
52
53
  allow(git_client).to receive(:current_branch).and_return('mybranch')
53
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_f')
54
- allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:donald-fr/testrepo_u')
54
+ allow(git_client).to receive(:main_branch).and_return('master')
55
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
56
+ allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:donald-fr/testrepo_u')
55
57
 
56
58
  expected_output = <<~STR
57
59
  Creating PR...
@@ -80,8 +82,9 @@ describe Geet::Services::CreatePr do
80
82
  context 'without labels, reviewers and milestones' do
81
83
  it 'should create a PR' do
82
84
  allow(git_client).to receive(:current_branch).and_return('mybranch')
83
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_f')
84
- allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:donald-fr/testrepo_u')
85
+ allow(git_client).to receive(:main_branch).and_return('master')
86
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
87
+ allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:donald-fr/testrepo_u')
85
88
 
86
89
  expected_output = <<~STR
87
90
  Creating PR...
@@ -112,7 +115,7 @@ describe Geet::Services::CreatePr do
112
115
  context 'in automated mode' do
113
116
  it 'should raise an error when the working tree is dirty' do
114
117
  allow(git_client).to receive(:working_tree_clean?).and_return(false)
115
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_f')
118
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
116
119
 
117
120
  expected_output = <<~STR
118
121
  Error! Saved summary to /tmp/last_geet_edited_summary.md
@@ -133,10 +136,11 @@ describe Geet::Services::CreatePr do
133
136
  it 'should push to the upstream branch' do
134
137
  allow(git_client).to receive(:working_tree_clean?).and_return(true)
135
138
  allow(git_client).to receive(:current_branch).and_return('mybranch')
139
+ allow(git_client).to receive(:main_branch).and_return('master')
136
140
  expect(git_client).to receive(:upstream_branch).and_return('mybranch')
137
141
  expect(git_client).to receive(:push)
138
142
 
139
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_f')
143
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
140
144
 
141
145
  expected_output = <<~STR
142
146
  Pushing to upstream branch...
@@ -158,10 +162,11 @@ describe Geet::Services::CreatePr do
158
162
  it "should create an upstream branch, when there isn't one (is not tracked)" do
159
163
  allow(git_client).to receive(:working_tree_clean?).and_return(true)
160
164
  allow(git_client).to receive(:current_branch).and_return('mybranch')
165
+ allow(git_client).to receive(:main_branch).and_return('master')
161
166
  expect(git_client).to receive(:upstream_branch).and_return(nil)
162
167
  expect(git_client).to receive(:push).with(upstream_branch: 'mybranch')
163
168
 
164
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_f')
169
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
165
170
 
166
171
  expected_output = <<~STR
167
172
  Creating upstream branch "mybranch"...
@@ -12,7 +12,7 @@ describe Geet::Services::ListIssues do
12
12
 
13
13
  context 'with github.com' do
14
14
  it 'should list the default issues' do
15
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')
15
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo')
16
16
 
17
17
  expected_output = <<~STR
18
18
  5. Title 2 (https://github.com/donaldduck/testrepo/issues/5)
@@ -34,7 +34,7 @@ describe Geet::Services::ListIssues do
34
34
 
35
35
  context 'with assignee filtering' do
36
36
  it 'should list the issues' do
37
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo_gh')
37
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_gh')
38
38
 
39
39
  expected_output = <<~STR
40
40
  Finding collaborators...
@@ -57,8 +57,8 @@ describe Geet::Services::ListIssues do
57
57
  end
58
58
 
59
59
  it 'should list the upstream issues' do
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')
60
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_2f')
61
+ allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:donald-fr/testrepo_u')
62
62
 
63
63
  expected_output = <<~STR
64
64
  2. Title 2 U (https://github.com/donald-fr/testrepo_u/issues/2)
@@ -81,7 +81,7 @@ describe Geet::Services::ListIssues do
81
81
 
82
82
  context 'with gitlab.com' do
83
83
  it 'should list the issues' do
84
- allow(git_client).to receive(:remote).with('origin').and_return('git@gitlab.com:donaldduck/testproject')
84
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@gitlab.com:donaldduck/testproject')
85
85
 
86
86
  expected_output = <<~STR
87
87
  2. I like more pizza (https://gitlab.com/donaldduck/testproject/issues/2)
@@ -103,7 +103,7 @@ describe Geet::Services::ListIssues do
103
103
 
104
104
  context 'with assignee filtering' do
105
105
  it 'should list the issues' do
106
- allow(git_client).to receive(:remote).with('origin').and_return('git@gitlab.com:donaldduck/testproject')
106
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@gitlab.com:donaldduck/testproject')
107
107
 
108
108
  expected_output = <<~STR
109
109
  Finding collaborators...
@@ -12,7 +12,7 @@ describe Geet::Services::ListLabels do
12
12
 
13
13
  context 'with github.com' do
14
14
  it 'should list the labels' do
15
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/geet')
15
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/geet')
16
16
 
17
17
  expected_output = <<~STR
18
18
  - bug (#ee0701)
@@ -34,8 +34,8 @@ describe Geet::Services::ListLabels do
34
34
  end
35
35
 
36
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')
37
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/geet')
38
+ allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:donaldduck-fr/testrepo_u')
39
39
 
40
40
  expected_output = <<~STR
41
41
  - bug (#ee0701)
@@ -57,7 +57,7 @@ describe Geet::Services::ListLabels do
57
57
 
58
58
  context 'with gitlab.com' do
59
59
  it 'should list the labels' do
60
- allow(git_client).to receive(:remote).with('origin').and_return('git@gitlab.com:donaldduck/testproject')
60
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@gitlab.com:donaldduck/testproject')
61
61
 
62
62
  expected_output = <<~STR
63
63
  - bug (#d9534f)
@@ -12,7 +12,7 @@ describe Geet::Services::ListMilestones do
12
12
 
13
13
  context 'with github.com' do
14
14
  it 'should list the milestones' do
15
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/geet')
15
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/geet')
16
16
 
17
17
  expected_output = <<~STR
18
18
  Finding milestones...
@@ -50,8 +50,8 @@ describe Geet::Services::ListMilestones do
50
50
  end
51
51
 
52
52
  it 'should list the upstream milestones' do
53
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donald-fr/testrepo_downstream')
54
- allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:donaldduck/testrepo_upstream')
53
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donald-fr/testrepo_downstream')
54
+ allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:donaldduck/testrepo_upstream')
55
55
 
56
56
  expected_output = <<~STR
57
57
  Finding milestones...
@@ -80,7 +80,7 @@ describe Geet::Services::ListMilestones do
80
80
 
81
81
  context 'with gitlab.com' do
82
82
  it 'should list the milestones' do
83
- allow(git_client).to receive(:remote).with('origin').and_return('git@gitlab.com:donaldduck/testproject')
83
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@gitlab.com:donaldduck/testproject')
84
84
 
85
85
  expected_output = <<~STR
86
86
  Finding milestones...
@@ -11,7 +11,7 @@ describe Geet::Services::ListPrs do
11
11
  let(:upstream_repository) { Geet::Git::Repository.new(upstream: true, git_client: git_client) }
12
12
 
13
13
  it 'should list the PRs' do
14
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donald-fr/testrepo_downstream')
14
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donald-fr/testrepo_downstream')
15
15
 
16
16
  expected_output = <<~STR
17
17
  2. Add testfile3 (downstream) (https://github.com/donald-fr/testrepo_downstream/pull/2)
@@ -32,8 +32,8 @@ describe Geet::Services::ListPrs do
32
32
  end
33
33
 
34
34
  it 'should list the upstream PRs' do
35
- allow(git_client).to receive(:remote).with('origin').and_return('git@github.com:donald-fr/testrepo_downstream')
36
- allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:donaldduck/testrepo_upstream')
35
+ allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donald-fr/testrepo_downstream')
36
+ allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:donaldduck/testrepo_upstream')
37
37
 
38
38
  expected_output = <<~STR
39
39
  2. Add testfile3 (upstream) (https://github.com/donaldduck/testrepo_upstream/pull/2)
@@ -5,23 +5,42 @@ require 'spec_helper'
5
5
  require_relative '../../lib/geet/git/repository'
6
6
  require_relative '../../lib/geet/services/merge_pr'
7
7
 
8
+ # Currently disabled: it requires updates following the addition of the automatic removal of the local
9
+ # branch.
10
+ # Specifically, `GitClient#upstream_branch_gone?` needs to be handled, since it returns the current
11
+ # branch, while it's supposed to return
12
+ #
8
13
  describe Geet::Services::MergePr do
9
14
  let(:git_client) { Geet::Utils::GitClient.new }
10
15
  let(:repository) { Geet::Git::Repository.new(git_client: git_client) }
11
16
  let(:owner) { 'donaldduck' }
12
17
  let(:branch) { 'mybranch' }
18
+ let(:main_branch) { 'main' }
19
+
20
+ before :each do
21
+ expect(git_client).to receive(:fetch)
22
+ expect(git_client).to receive(:upstream_branch_gone?).and_return(true)
23
+ expect(git_client).to receive(:checkout).with(main_branch)
24
+ expect(git_client).to receive(:rebase)
25
+ expect(git_client).to receive(:delete_branch).with('mybranch')
26
+ end
13
27
 
14
28
  context 'with github.com' do
15
29
  let(:repository_name) { 'testrepo_upstream' }
16
30
 
17
31
  it 'should merge the PR for the current branch' do
18
32
  allow(git_client).to receive(:current_branch).and_return(branch)
19
- allow(git_client).to receive(:remote).with('origin').and_return("git@github.com:#{owner}/#{repository_name}")
33
+ allow(git_client).to receive(:main_branch).and_return(main_branch)
34
+ allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:#{owner}/#{repository_name}")
20
35
 
21
36
  expected_pr_number = 1
22
37
  expected_output = <<~STR
23
38
  Finding PR with head (#{owner}:#{branch})...
24
39
  Merging PR ##{expected_pr_number}...
40
+ Fetching repository...
41
+ Checking out #{main_branch}...
42
+ Rebasing...
43
+ Deleting local branch mybranch...
25
44
  STR
26
45
 
27
46
  actual_output = StringIO.new
@@ -38,13 +57,18 @@ describe Geet::Services::MergePr do
38
57
 
39
58
  it 'should merge the PR for the current branch, with branch deletion' do
40
59
  allow(git_client).to receive(:current_branch).and_return(branch)
41
- allow(git_client).to receive(:remote).with('origin').and_return("git@github.com:#{owner}/#{repository_name}")
60
+ allow(git_client).to receive(:main_branch).and_return(main_branch)
61
+ allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:#{owner}/#{repository_name}")
42
62
 
43
63
  expected_pr_number = 2
44
64
  expected_output = <<~STR
45
65
  Finding PR with head (#{owner}:#{branch})...
46
66
  Merging PR ##{expected_pr_number}...
47
- Deleting branch #{branch}...
67
+ Deleting remote branch #{branch}...
68
+ Fetching repository...
69
+ Checking out #{main_branch}...
70
+ Rebasing...
71
+ Deleting local branch mybranch...
48
72
  STR
49
73
 
50
74
  actual_output = StringIO.new
@@ -65,12 +89,17 @@ describe Geet::Services::MergePr do
65
89
 
66
90
  it 'should merge the PR for the current branch' do
67
91
  allow(git_client).to receive(:current_branch).and_return(branch)
68
- allow(git_client).to receive(:remote).with('origin').and_return("git@gitlab.com:#{owner}/#{repository_name}")
92
+ allow(git_client).to receive(:main_branch).and_return(main_branch)
93
+ allow(git_client).to receive(:remote).with(no_args).and_return("git@gitlab.com:#{owner}/#{repository_name}")
69
94
 
70
95
  expected_pr_number = 4
71
96
  expected_output = <<~STR
72
97
  Finding PR with head (#{owner}:#{branch})...
73
98
  Merging PR ##{expected_pr_number}...
99
+ Fetching repository...
100
+ Checking out #{main_branch}...
101
+ Rebasing...
102
+ Deleting local branch mybranch...
74
103
  STR
75
104
 
76
105
  actual_output = StringIO.new
@@ -16,7 +16,7 @@ describe Geet::Services::OpenPr do
16
16
 
17
17
  it 'should open the PR for the current branch' do
18
18
  allow(git_client).to receive(:current_branch).and_return(branch)
19
- allow(git_client).to receive(:remote).with('origin').and_return("git@github.com:#{owner}/#{repository_name}")
19
+ allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:#{owner}/#{repository_name}")
20
20
 
21
21
  expected_pr_number = 3
22
22
  expected_output = <<~STR
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ require_relative '../../lib/geet/git/repository'
6
+ require_relative '../../lib/geet/services/open_repo'
7
+
8
+ module Geet
9
+ describe Services::OpenRepo do
10
+ let(:git_client) { Utils::GitClient.new }
11
+ let(:repository) { Git::Repository.new(git_client: git_client) }
12
+
13
+ OWNER = 'donaldduck'
14
+ REPOSITORY_NAME = 'testrepo'
15
+
16
+ REMOTE_URLS = {
17
+ 'git' => "git@github.com:#{OWNER}/#{REPOSITORY_NAME}",
18
+ 'https' => "https://github.com/#{OWNER}/#{REPOSITORY_NAME}",
19
+ }
20
+
21
+ context 'should open the PR for the current branch' do
22
+ REMOTE_URLS.each do |protocol, remote_url|
23
+ it "with #{protocol} protocol" do
24
+ allow(git_client).to receive(:remote).with(no_args).and_return(remote_url)
25
+
26
+ expected_url = "https://github.com/#{OWNER}/#{REPOSITORY_NAME}"
27
+ expected_output = ""
28
+
29
+ actual_output = StringIO.new
30
+ service_instance = described_class.new(repository, out: actual_output, git_client: git_client)
31
+
32
+ expect(service_instance).to receive(:open_file_with_default_application).with(expected_url) do
33
+ # do nothing; just don't open the browser
34
+ end
35
+
36
+ execution_result = VCR.use_cassette('github_com/open_repo') do
37
+ service_instance.execute
38
+ end
39
+
40
+ expect(actual_output.string).to eql(expected_output)
41
+ expect(execution_result).to eql(expected_url)
42
+ end
43
+ end
44
+ end # context 'should open the PR for the current branch'
45
+ end # describe Services::OpenRepo
46
+ end # module Geet
@@ -608,7 +608,7 @@ http_interactions:
608
608
  uri: https://api.github.com/repos/donaldduck/testrepo_f/issues
609
609
  body:
610
610
  encoding: UTF-8
611
- string: '{"title":"Title","body":"Description","base":"master"}'
611
+ string: '{"title":"Title","body":"Description"}'
612
612
  headers:
613
613
  Accept-Encoding:
614
614
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
@@ -152,7 +152,7 @@ http_interactions:
152
152
  uri: https://api.github.com/repos/momcorp/therepo/issues
153
153
  body:
154
154
  encoding: UTF-8
155
- string: '{"title":"Title","body":"Description","base":"master"}'
155
+ string: '{"title":"Title","body":"Description"}'
156
156
  headers:
157
157
  Accept-Encoding:
158
158
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3