geet 0.27.1 → 0.27.3
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 +4 -4
- data/.rubocop.yml +79 -58
- data/Gemfile +9 -9
- data/Rakefile +2 -2
- data/bin/geet +7 -7
- data/geet.gemspec +19 -19
- data/lib/geet/commandline/commands.rb +16 -15
- data/lib/geet/commandline/configuration.rb +97 -93
- data/lib/geet/commandline/editor.rb +13 -7
- data/lib/geet/git/repository.rb +75 -6
- data/lib/geet/github/abstract_issue.rb +7 -7
- data/lib/geet/github/api_interface.rb +23 -23
- data/lib/geet/github/gist.rb +8 -8
- data/lib/geet/github/issue.rb +6 -6
- data/lib/geet/github/label.rb +5 -5
- data/lib/geet/github/milestone.rb +10 -10
- data/lib/geet/github/pr.rb +25 -25
- data/lib/geet/github/remote_repository.rb +1 -1
- data/lib/geet/github/user.rb +5 -5
- data/lib/geet/gitlab/api_interface.rb +13 -13
- data/lib/geet/gitlab/issue.rb +3 -3
- data/lib/geet/gitlab/label.rb +4 -4
- data/lib/geet/gitlab/milestone.rb +4 -4
- data/lib/geet/gitlab/pr.rb +4 -4
- data/lib/geet/gitlab/user.rb +2 -2
- data/lib/geet/helpers/json_helper.rb +1 -1
- data/lib/geet/helpers/os_helper.rb +5 -5
- data/lib/geet/helpers/services_workflow_helper.rb +4 -4
- data/lib/geet/services/abstract_create_issue.rb +3 -3
- data/lib/geet/services/add_upstream_repo.rb +1 -1
- data/lib/geet/services/close_milestones.rb +9 -2
- data/lib/geet/services/comment_pr.rb +11 -0
- data/lib/geet/services/create_gist.rb +18 -4
- data/lib/geet/services/create_issue.rb +14 -8
- data/lib/geet/services/create_label.rb +22 -3
- data/lib/geet/services/create_milestone.rb +7 -1
- data/lib/geet/services/create_pr.rb +98 -23
- data/lib/geet/services/list_issues.rb +4 -3
- data/lib/geet/services/list_labels.rb +7 -0
- data/lib/geet/services/list_milestones.rb +35 -6
- data/lib/geet/services/list_prs.rb +7 -0
- data/lib/geet/services/merge_pr.rb +20 -2
- data/lib/geet/services/open_pr.rb +2 -2
- data/lib/geet/services/open_repo.rb +7 -1
- data/lib/geet/shared/repo_permissions.rb +4 -4
- data/lib/geet/shared/selection.rb +2 -2
- data/lib/geet/utils/attributes_selection_manager.rb +30 -10
- data/lib/geet/utils/git_client.rb +74 -33
- data/lib/geet/utils/manual_list_selection.rb +23 -11
- data/lib/geet/utils/string_matching_selection.rb +22 -6
- data/lib/geet/version.rb +2 -1
- data/lib/geet.rb +2 -2
- data/spec/integration/comment_pr_spec.rb +10 -10
- data/spec/integration/create_gist_spec.rb +12 -12
- data/spec/integration/create_issue_spec.rb +21 -21
- data/spec/integration/create_label_spec.rb +33 -33
- data/spec/integration/create_milestone_spec.rb +9 -9
- data/spec/integration/create_pr_spec.rb +120 -134
- data/spec/integration/list_issues_spec.rb +25 -25
- data/spec/integration/list_labels_spec.rb +15 -15
- data/spec/integration/list_milestones_spec.rb +15 -15
- data/spec/integration/list_prs_spec.rb +10 -10
- data/spec/integration/merge_pr_spec.rb +18 -18
- data/spec/integration/open_pr_spec.rb +18 -20
- data/spec/integration/open_repo_spec.rb +18 -18
- data/spec/spec_helper.rb +10 -10
- data/spec/unit/github/pr_spec.rb +91 -91
- metadata +2 -3
- data/.rubocop_todo.yml +0 -466
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "spec_helper"
|
|
4
4
|
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
5
|
+
require_relative "../../lib/geet/git/repository"
|
|
6
|
+
require_relative "../../lib/geet/services/create_issue"
|
|
7
7
|
|
|
8
8
|
describe Geet::Services::CreateIssue do
|
|
9
9
|
let(:git_client) { Geet::Utils::GitClient.new }
|
|
10
10
|
let(:repository) { Geet::Git::Repository.new(warnings: false, git_client: git_client) }
|
|
11
11
|
let(:upstream_repository) { Geet::Git::Repository.new(upstream: true, git_client: git_client) }
|
|
12
12
|
|
|
13
|
-
context
|
|
14
|
-
it
|
|
15
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
13
|
+
context "with labels, assignees and milestones" do
|
|
14
|
+
it "should create an issue" do
|
|
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...
|
|
@@ -27,27 +27,27 @@ describe Geet::Services::CreateIssue do
|
|
|
27
27
|
|
|
28
28
|
actual_output = StringIO.new
|
|
29
29
|
|
|
30
|
-
actual_created_issue = VCR.use_cassette(
|
|
30
|
+
actual_created_issue = VCR.use_cassette("create_issue") do
|
|
31
31
|
described_class.new(repository, out: actual_output).execute(
|
|
32
|
-
|
|
33
|
-
labels:
|
|
32
|
+
"Title", "Description",
|
|
33
|
+
labels: "bug,invalid", milestone: "0.0.1", assignees: "donaldduck,donald-fr",
|
|
34
34
|
)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
expect(actual_output.string).to eql(expected_output)
|
|
38
38
|
|
|
39
39
|
expect(actual_created_issue.number).to eql(2)
|
|
40
|
-
expect(actual_created_issue.title).to eql(
|
|
41
|
-
expect(actual_created_issue.link).to eql(
|
|
40
|
+
expect(actual_created_issue.title).to eql("Title")
|
|
41
|
+
expect(actual_created_issue.link).to eql("https://github.com/donaldduck/testrepo_f/issues/2")
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
context
|
|
46
|
-
context
|
|
47
|
-
it
|
|
48
|
-
allow(git_client).to receive(:current_branch).and_return(
|
|
49
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
50
|
-
allow(git_client).to receive(:remote).with(name:
|
|
45
|
+
context "without write permissions" do
|
|
46
|
+
context "without labels, assignees and milestones" do
|
|
47
|
+
it "should create an upstream issue" do
|
|
48
|
+
allow(git_client).to receive(:current_branch).and_return("mybranch")
|
|
49
|
+
allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:donaldduck/testrepo")
|
|
50
|
+
allow(git_client).to receive(:remote).with(name: "upstream").and_return("git@github.com:momcorp/therepo")
|
|
51
51
|
|
|
52
52
|
expected_output = <<~STR
|
|
53
53
|
Creating the issue...
|
|
@@ -56,15 +56,15 @@ describe Geet::Services::CreateIssue do
|
|
|
56
56
|
|
|
57
57
|
actual_output = StringIO.new
|
|
58
58
|
|
|
59
|
-
actual_created_issue = VCR.use_cassette(
|
|
60
|
-
described_class.new(upstream_repository, out: actual_output).execute(
|
|
59
|
+
actual_created_issue = VCR.use_cassette("create_issue_upstream") do
|
|
60
|
+
described_class.new(upstream_repository, out: actual_output).execute("Title", "Description")
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
expect(actual_output.string).to eql(expected_output)
|
|
64
64
|
|
|
65
65
|
expect(actual_created_issue.number).to eql(42)
|
|
66
|
-
expect(actual_created_issue.title).to eql(
|
|
67
|
-
expect(actual_created_issue.link).to eql(
|
|
66
|
+
expect(actual_created_issue.title).to eql("Title")
|
|
67
|
+
expect(actual_created_issue.link).to eql("https://github.com/momcorp/therepo/issues/42")
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
end
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "spec_helper"
|
|
4
4
|
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
5
|
+
require_relative "../../lib/geet/git/repository"
|
|
6
|
+
require_relative "../../lib/geet/services/create_label"
|
|
7
7
|
|
|
8
8
|
describe Geet::Services::CreateLabel do
|
|
9
9
|
let(:git_client) { Geet::Utils::GitClient.new }
|
|
10
10
|
let(:repository) { Geet::Git::Repository.new(git_client: git_client) }
|
|
11
11
|
let(:upstream_repository) { Geet::Git::Repository.new(upstream: true, git_client: git_client) }
|
|
12
12
|
|
|
13
|
-
context
|
|
14
|
-
context
|
|
15
|
-
it
|
|
16
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
13
|
+
context "with github.com" do
|
|
14
|
+
context "with user-specified color" do
|
|
15
|
+
it "should create a label" do
|
|
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...
|
|
@@ -22,20 +22,20 @@ describe Geet::Services::CreateLabel do
|
|
|
22
22
|
|
|
23
23
|
actual_output = StringIO.new
|
|
24
24
|
|
|
25
|
-
actual_created_label = VCR.use_cassette(
|
|
26
|
-
described_class.new(repository, out: actual_output).execute(
|
|
25
|
+
actual_created_label = VCR.use_cassette("github_com/create_label") do
|
|
26
|
+
described_class.new(repository, out: actual_output).execute("my_label", color: "c64c64")
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
expect(actual_output.string).to eql(expected_output)
|
|
30
30
|
|
|
31
|
-
expect(actual_created_label.name).to eql(
|
|
32
|
-
expect(actual_created_label.color).to eql(
|
|
31
|
+
expect(actual_created_label.name).to eql("my_label")
|
|
32
|
+
expect(actual_created_label.color).to eql("c64c64")
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
context
|
|
36
|
-
it
|
|
37
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
38
|
-
allow(git_client).to receive(:remote).with(name:
|
|
35
|
+
context "upstream" do
|
|
36
|
+
it "should create a label" do
|
|
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...
|
|
@@ -44,21 +44,21 @@ describe Geet::Services::CreateLabel do
|
|
|
44
44
|
|
|
45
45
|
actual_output = StringIO.new
|
|
46
46
|
|
|
47
|
-
actual_created_label = VCR.use_cassette(
|
|
48
|
-
described_class.new(upstream_repository, out: actual_output).execute(
|
|
47
|
+
actual_created_label = VCR.use_cassette("github_com/create_label_upstream") do
|
|
48
|
+
described_class.new(upstream_repository, out: actual_output).execute("my_label", color: "c64c64")
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
expect(actual_output.string).to eql(expected_output)
|
|
52
52
|
|
|
53
|
-
expect(actual_created_label.name).to eql(
|
|
54
|
-
expect(actual_created_label.color).to eql(
|
|
53
|
+
expect(actual_created_label.name).to eql("my_label")
|
|
54
|
+
expect(actual_created_label.color).to eql("c64c64")
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
context
|
|
60
|
-
it
|
|
61
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
59
|
+
context "with auto-generated color" do
|
|
60
|
+
it "should create a label" do
|
|
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
|
|
|
@@ -71,23 +71,23 @@ describe Geet::Services::CreateLabel do
|
|
|
71
71
|
Created with color #0097ff
|
|
72
72
|
STR
|
|
73
73
|
|
|
74
|
-
actual_created_label = VCR.use_cassette(
|
|
75
|
-
service_instance.execute(
|
|
74
|
+
actual_created_label = VCR.use_cassette("github_com/create_label_with_random_color") do
|
|
75
|
+
service_instance.execute("my_label")
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
expected_output = format(expected_output_template, color: actual_created_label.color)
|
|
79
79
|
|
|
80
80
|
expect(actual_output.string).to eql(expected_output)
|
|
81
81
|
|
|
82
|
-
expect(actual_created_label.name).to eql(
|
|
83
|
-
expect(actual_created_label.color).to eql(
|
|
82
|
+
expect(actual_created_label.name).to eql("my_label")
|
|
83
|
+
expect(actual_created_label.color).to eql("0097ff")
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
86
|
end # context 'with github.com'
|
|
87
87
|
|
|
88
|
-
context
|
|
89
|
-
it
|
|
90
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
88
|
+
context "with gitlab.com" do
|
|
89
|
+
it "should create a label" do
|
|
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...
|
|
@@ -96,14 +96,14 @@ describe Geet::Services::CreateLabel do
|
|
|
96
96
|
|
|
97
97
|
actual_output = StringIO.new
|
|
98
98
|
|
|
99
|
-
actual_created_label = VCR.use_cassette(
|
|
100
|
-
described_class.new(repository, out: actual_output).execute(
|
|
99
|
+
actual_created_label = VCR.use_cassette("gitlab_com/create_label") do
|
|
100
|
+
described_class.new(repository, out: actual_output).execute("my_label", color: "123456")
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
expect(actual_output.string).to eql(expected_output)
|
|
104
104
|
|
|
105
|
-
expect(actual_created_label.name).to eql(
|
|
106
|
-
expect(actual_created_label.color).to eql(
|
|
105
|
+
expect(actual_created_label.name).to eql("my_label")
|
|
106
|
+
expect(actual_created_label.color).to eql("123456")
|
|
107
107
|
end
|
|
108
108
|
end
|
|
109
109
|
end
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "spec_helper"
|
|
4
4
|
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
5
|
+
require_relative "../../lib/geet/git/repository"
|
|
6
|
+
require_relative "../../lib/geet/services/create_milestone"
|
|
7
7
|
|
|
8
8
|
describe Geet::Services::CreateMilestone do
|
|
9
9
|
let(:git_client) { Geet::Utils::GitClient.new }
|
|
10
10
|
let(:repository) { Geet::Git::Repository.new(git_client: git_client) }
|
|
11
11
|
let(:upstream_repository) { Geet::Git::Repository.new(upstream: true, git_client: git_client) }
|
|
12
12
|
|
|
13
|
-
context
|
|
14
|
-
it
|
|
15
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
13
|
+
context "with github.com" do
|
|
14
|
+
it "should create a milestone" do
|
|
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...
|
|
@@ -20,14 +20,14 @@ describe Geet::Services::CreateMilestone do
|
|
|
20
20
|
|
|
21
21
|
actual_output = StringIO.new
|
|
22
22
|
|
|
23
|
-
actual_created_label = VCR.use_cassette(
|
|
24
|
-
described_class.new(repository, out: actual_output).execute(
|
|
23
|
+
actual_created_label = VCR.use_cassette("github_com/create_milestone") do
|
|
24
|
+
described_class.new(repository, out: actual_output).execute("my_milestone")
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
expect(actual_output.string).to eql(expected_output)
|
|
28
28
|
|
|
29
29
|
expect(actual_created_label.number).to eql(6)
|
|
30
|
-
expect(actual_created_label.title).to eql(
|
|
30
|
+
expect(actual_created_label.title).to eql("my_milestone")
|
|
31
31
|
expect(actual_created_label.due_on).to be(nil)
|
|
32
32
|
end
|
|
33
33
|
end # context 'with github.com'
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "spec_helper"
|
|
4
4
|
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
5
|
+
require_relative "../../lib/geet/git/repository"
|
|
6
|
+
require_relative "../../lib/geet/services/create_pr"
|
|
7
7
|
|
|
8
8
|
describe Geet::Services::CreatePr do
|
|
9
9
|
let(:git_client) { Geet::Utils::GitClient.new }
|
|
10
10
|
let(:repository) { Geet::Git::Repository.new(git_client:, warnings: false) }
|
|
11
11
|
let(:upstream_repository) { Geet::Git::Repository.new(upstream: true, git_client:, warnings: false) }
|
|
12
12
|
|
|
13
|
-
context
|
|
14
|
-
context
|
|
15
|
-
it
|
|
13
|
+
context "with github.com" do
|
|
14
|
+
context "with labels, reviewers and milestones" do
|
|
15
|
+
it "should create a PR" do
|
|
16
16
|
allow(git_client).to receive(:working_tree_clean?).and_return(true)
|
|
17
|
-
allow(git_client).to receive(:current_branch).and_return(
|
|
18
|
-
allow(git_client).to receive(:main_branch).and_return(
|
|
19
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
20
|
-
allow(git_client).to receive(:remote_branch).and_return(
|
|
17
|
+
allow(git_client).to receive(:current_branch).and_return("mybranch")
|
|
18
|
+
allow(git_client).to receive(:main_branch).and_return("master")
|
|
19
|
+
allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:donaldduck/testrepo_f")
|
|
20
|
+
allow(git_client).to receive(:remote_branch).and_return("mybranch")
|
|
21
21
|
expect(git_client).to receive(:fetch)
|
|
22
22
|
allow(git_client).to receive(:remote_branch_diff_commits).and_return([])
|
|
23
23
|
expect(git_client).to receive(:push)
|
|
@@ -34,33 +34,31 @@ describe Geet::Services::CreatePr do
|
|
|
34
34
|
PR address: https://github.com/donaldduck/testrepo_f/pull/1
|
|
35
35
|
STR
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
expect(actual_output.string).to eql(expected_output)
|
|
37
|
+
expect {
|
|
38
|
+
actual_created_pr = VCR.use_cassette("github_com/create_pr", allow_unused_http_interactions: true) do
|
|
39
|
+
service_instance = described_class.new(repository, git_client:)
|
|
40
|
+
service_instance.execute(
|
|
41
|
+
"Title", "Description",
|
|
42
|
+
labels: "bug,invalid", milestone: "0.0.1", reviewers: "donald-fr"
|
|
43
|
+
)
|
|
44
|
+
end
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
expect(actual_created_pr.number).to eql(1)
|
|
47
|
+
expect(actual_created_pr.title).to eql("Title")
|
|
48
|
+
expect(actual_created_pr.link).to eql("https://github.com/donaldduck/testrepo_f/pull/1")
|
|
49
|
+
}.to output(expected_output).to_stdout
|
|
52
50
|
end
|
|
53
51
|
end
|
|
54
52
|
|
|
55
|
-
context
|
|
56
|
-
it
|
|
53
|
+
context "on an upstream repository" do
|
|
54
|
+
it "should create an upstream PR" do
|
|
57
55
|
allow(git_client).to receive(:working_tree_clean?).and_return(true)
|
|
58
|
-
allow(git_client).to receive(:current_branch).and_return(
|
|
59
|
-
allow(git_client).to receive(:main_branch).and_return(
|
|
60
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
61
|
-
allow(git_client).to receive(:remote).with(name:
|
|
62
|
-
allow(git_client).to receive(:remote_defined?).with(
|
|
63
|
-
allow(git_client).to receive(:remote_branch).and_return(
|
|
56
|
+
allow(git_client).to receive(:current_branch).and_return("mybranch")
|
|
57
|
+
allow(git_client).to receive(:main_branch).and_return("master")
|
|
58
|
+
allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:donaldduck/testrepo_f")
|
|
59
|
+
allow(git_client).to receive(:remote).with(name: "upstream").and_return("git@github.com:donald-fr/testrepo_u")
|
|
60
|
+
allow(git_client).to receive(:remote_defined?).with("upstream").and_return(true)
|
|
61
|
+
allow(git_client).to receive(:remote_branch).and_return("mybranch")
|
|
64
62
|
expect(git_client).to receive(:fetch)
|
|
65
63
|
allow(git_client).to receive(:remote_branch_diff_commits).and_return([])
|
|
66
64
|
expect(git_client).to receive(:push)
|
|
@@ -71,33 +69,31 @@ describe Geet::Services::CreatePr do
|
|
|
71
69
|
PR address: https://github.com/donald-fr/testrepo_u/pull/8
|
|
72
70
|
STR
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
expect(actual_output.string).to eql(expected_output)
|
|
72
|
+
expect {
|
|
73
|
+
actual_created_pr = VCR.use_cassette("github_com/create_pr_upstream", allow_unused_http_interactions: true) do
|
|
74
|
+
service_instance = described_class.new(upstream_repository, git_client:)
|
|
75
|
+
service_instance.execute("Title", "Description")
|
|
76
|
+
end
|
|
82
77
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
expect(actual_created_pr.number).to eql(8)
|
|
79
|
+
expect(actual_created_pr.title).to eql("Title")
|
|
80
|
+
expect(actual_created_pr.link).to eql("https://github.com/donald-fr/testrepo_u/pull/8")
|
|
81
|
+
}.to output(expected_output).to_stdout
|
|
86
82
|
end
|
|
87
83
|
|
|
88
84
|
# It would be more consistent to have this UT outside of an upstream context, however this use
|
|
89
85
|
# case is actually a typical real-world one
|
|
90
86
|
#
|
|
91
|
-
context
|
|
92
|
-
context
|
|
93
|
-
it
|
|
87
|
+
context "without write permissions" do
|
|
88
|
+
context "without labels, reviewers and milestones" do
|
|
89
|
+
it "should create a PR" do
|
|
94
90
|
allow(git_client).to receive(:working_tree_clean?).and_return(true)
|
|
95
|
-
allow(git_client).to receive(:current_branch).and_return(
|
|
96
|
-
allow(git_client).to receive(:main_branch).and_return(
|
|
97
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
98
|
-
allow(git_client).to receive(:remote).with(name:
|
|
99
|
-
allow(git_client).to receive(:remote_defined?).with(
|
|
100
|
-
allow(git_client).to receive(:remote_branch).and_return(
|
|
91
|
+
allow(git_client).to receive(:current_branch).and_return("mybranch")
|
|
92
|
+
allow(git_client).to receive(:main_branch).and_return("master")
|
|
93
|
+
allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:donaldduck/testrepo_f")
|
|
94
|
+
allow(git_client).to receive(:remote).with(name: "upstream").and_return("git@github.com:donald-fr/testrepo_u")
|
|
95
|
+
allow(git_client).to receive(:remote_defined?).with("upstream").and_return(true)
|
|
96
|
+
allow(git_client).to receive(:remote_branch).and_return("mybranch")
|
|
101
97
|
expect(git_client).to receive(:fetch)
|
|
102
98
|
allow(git_client).to receive(:remote_branch_diff_commits).and_return([])
|
|
103
99
|
expect(git_client).to receive(:push)
|
|
@@ -108,51 +104,47 @@ describe Geet::Services::CreatePr do
|
|
|
108
104
|
PR address: https://github.com/donald-fr/testrepo_u/pull/9
|
|
109
105
|
STR
|
|
110
106
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
expect(actual_created_pr.title).to eql('Title')
|
|
125
|
-
expect(actual_created_pr.link).to eql('https://github.com/donald-fr/testrepo_u/pull/9')
|
|
107
|
+
expect {
|
|
108
|
+
actual_created_pr = VCR.use_cassette("github_com/create_pr_upstream_without_write_permissions") do
|
|
109
|
+
service_instance = described_class.new(upstream_repository, git_client:)
|
|
110
|
+
service_instance.execute(
|
|
111
|
+
"Title", "Description",
|
|
112
|
+
labels: "<ignored>"
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
expect(actual_created_pr.number).to eql(9)
|
|
117
|
+
expect(actual_created_pr.title).to eql("Title")
|
|
118
|
+
expect(actual_created_pr.link).to eql("https://github.com/donald-fr/testrepo_u/pull/9")
|
|
119
|
+
}.to output(expected_output).to_stdout
|
|
126
120
|
end
|
|
127
121
|
end
|
|
128
122
|
end
|
|
129
123
|
end
|
|
130
124
|
|
|
131
|
-
context
|
|
132
|
-
it
|
|
125
|
+
context "in automated mode" do
|
|
126
|
+
it "should raise an error when the working tree is dirty" do
|
|
133
127
|
allow(git_client).to receive(:working_tree_clean?).and_return(false)
|
|
134
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
expect(actual_output.string).to be_empty
|
|
128
|
+
allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:donaldduck/testrepo_f")
|
|
129
|
+
|
|
130
|
+
expect {
|
|
131
|
+
expect do
|
|
132
|
+
service_instance = described_class.new(repository, git_client:)
|
|
133
|
+
service_instance.execute("Title", "Description")
|
|
134
|
+
end.to raise_error(RuntimeError, "The working tree is not clean!")
|
|
135
|
+
}.to output("").to_stdout
|
|
144
136
|
end
|
|
145
137
|
|
|
146
|
-
it
|
|
138
|
+
it "should push to the remote branch" do
|
|
147
139
|
allow(git_client).to receive(:working_tree_clean?).and_return(true)
|
|
148
|
-
allow(git_client).to receive(:current_branch).and_return(
|
|
149
|
-
allow(git_client).to receive(:main_branch).and_return(
|
|
150
|
-
expect(git_client).to receive(:remote_branch).and_return(
|
|
140
|
+
allow(git_client).to receive(:current_branch).and_return("mybranch")
|
|
141
|
+
allow(git_client).to receive(:main_branch).and_return("master")
|
|
142
|
+
expect(git_client).to receive(:remote_branch).and_return("mybranch")
|
|
151
143
|
expect(git_client).to receive(:fetch)
|
|
152
144
|
allow(git_client).to receive(:remote_branch_diff_commits).and_return([])
|
|
153
145
|
expect(git_client).to receive(:push)
|
|
154
146
|
|
|
155
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
147
|
+
allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:donaldduck/testrepo_f")
|
|
156
148
|
|
|
157
149
|
expected_output = <<~STR
|
|
158
150
|
Pushing to remote branch...
|
|
@@ -160,24 +152,22 @@ describe Geet::Services::CreatePr do
|
|
|
160
152
|
PR address: https://github.com/donaldduck/testrepo_f/pull/2
|
|
161
153
|
STR
|
|
162
154
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
expect(actual_output.string).to eql(expected_output)
|
|
155
|
+
expect {
|
|
156
|
+
VCR.use_cassette("github_com/create_pr_in_auto_mode_with_push", allow_unused_http_interactions: true) do
|
|
157
|
+
service_instance = described_class.new(repository, git_client:)
|
|
158
|
+
service_instance.execute("Title", "Description")
|
|
159
|
+
end
|
|
160
|
+
}.to output(expected_output).to_stdout
|
|
171
161
|
end
|
|
172
162
|
|
|
173
163
|
it "should create a remote branch, when there isn't one (is not tracked)" do
|
|
174
164
|
allow(git_client).to receive(:working_tree_clean?).and_return(true)
|
|
175
|
-
allow(git_client).to receive(:current_branch).and_return(
|
|
176
|
-
allow(git_client).to receive(:main_branch).and_return(
|
|
165
|
+
allow(git_client).to receive(:current_branch).and_return("mybranch")
|
|
166
|
+
allow(git_client).to receive(:main_branch).and_return("master")
|
|
177
167
|
expect(git_client).to receive(:remote_branch).and_return(nil)
|
|
178
|
-
expect(git_client).to receive(:push).with(remote_branch:
|
|
168
|
+
expect(git_client).to receive(:push).with(remote_branch: "mybranch")
|
|
179
169
|
|
|
180
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
170
|
+
allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:donaldduck/testrepo_f")
|
|
181
171
|
|
|
182
172
|
expected_output = <<~STR
|
|
183
173
|
Creating remote branch "mybranch"...
|
|
@@ -185,27 +175,23 @@ describe Geet::Services::CreatePr do
|
|
|
185
175
|
PR address: https://github.com/donaldduck/testrepo_f/pull/4
|
|
186
176
|
STR
|
|
187
177
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
expect(actual_output.string).to eql(expected_output)
|
|
178
|
+
expect {
|
|
179
|
+
VCR.use_cassette("github_com/create_pr_in_auto_mode_create_upstream", allow_unused_http_interactions: true) do
|
|
180
|
+
service_instance = described_class.new(repository, git_client:)
|
|
181
|
+
service_instance.execute("Title", "Description")
|
|
182
|
+
end
|
|
183
|
+
}.to output(expected_output).to_stdout
|
|
196
184
|
end
|
|
197
185
|
|
|
198
|
-
it
|
|
186
|
+
it "should enable automerge after creating a PR" do
|
|
199
187
|
allow(git_client).to receive(:working_tree_clean?).and_return(true)
|
|
200
|
-
allow(git_client).to receive(:current_branch).and_return(
|
|
201
|
-
allow(git_client).to receive(:main_branch).and_return(
|
|
202
|
-
allow(git_client).to receive(:remote_branch).and_return(
|
|
188
|
+
allow(git_client).to receive(:current_branch).and_return("mybranch")
|
|
189
|
+
allow(git_client).to receive(:main_branch).and_return("master")
|
|
190
|
+
allow(git_client).to receive(:remote_branch).and_return("mybranch")
|
|
203
191
|
allow(git_client).to receive(:remote_branch_diff_commits).and_return([])
|
|
204
192
|
allow(git_client).to receive(:fetch)
|
|
205
193
|
allow(git_client).to receive(:push)
|
|
206
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
207
|
-
|
|
208
|
-
actual_output = StringIO.new
|
|
194
|
+
allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:donaldduck/testrepo_f")
|
|
209
195
|
|
|
210
196
|
# Mock the repository and PR
|
|
211
197
|
allow(repository).to receive(:authenticated_user).and_return(
|
|
@@ -213,34 +199,33 @@ describe Geet::Services::CreatePr do
|
|
|
213
199
|
)
|
|
214
200
|
|
|
215
201
|
mock_pr = double(
|
|
216
|
-
|
|
202
|
+
"PR",
|
|
217
203
|
number: 1,
|
|
218
|
-
title:
|
|
219
|
-
link:
|
|
220
|
-
node_id:
|
|
204
|
+
title: "Title",
|
|
205
|
+
link: "https://github.com/donaldduck/testrepo_f/pull/1",
|
|
206
|
+
node_id: "PR_test123"
|
|
221
207
|
)
|
|
222
208
|
allow(mock_pr).to receive(:enable_automerge)
|
|
223
209
|
|
|
224
210
|
allow(repository).to receive(:create_pr).and_return(mock_pr)
|
|
225
211
|
|
|
226
|
-
|
|
227
|
-
|
|
212
|
+
expect {
|
|
213
|
+
service_instance = described_class.new(repository, git_client:)
|
|
214
|
+
service_instance.execute("Title", "Description", automerge: true)
|
|
228
215
|
|
|
229
|
-
|
|
230
|
-
|
|
216
|
+
expect(mock_pr).to have_received(:enable_automerge)
|
|
217
|
+
}.to output(/Enabling automerge\.\.\./).to_stdout
|
|
231
218
|
end
|
|
232
219
|
|
|
233
|
-
it
|
|
220
|
+
it "should raise an error when automerge is requested but not supported" do
|
|
234
221
|
allow(git_client).to receive(:working_tree_clean?).and_return(true)
|
|
235
|
-
allow(git_client).to receive(:current_branch).and_return(
|
|
236
|
-
allow(git_client).to receive(:main_branch).and_return(
|
|
237
|
-
allow(git_client).to receive(:remote_branch).and_return(
|
|
222
|
+
allow(git_client).to receive(:current_branch).and_return("mybranch")
|
|
223
|
+
allow(git_client).to receive(:main_branch).and_return("master")
|
|
224
|
+
allow(git_client).to receive(:remote_branch).and_return("mybranch")
|
|
238
225
|
allow(git_client).to receive(:remote_branch_diff_commits).and_return([])
|
|
239
226
|
allow(git_client).to receive(:fetch)
|
|
240
227
|
allow(git_client).to receive(:push)
|
|
241
|
-
allow(git_client).to receive(:remote).with(no_args).and_return(
|
|
242
|
-
|
|
243
|
-
actual_output = StringIO.new
|
|
228
|
+
allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:donaldduck/testrepo_f")
|
|
244
229
|
|
|
245
230
|
# Mock the repository and PR without enable_automerge method (simulating GitLab)
|
|
246
231
|
allow(repository).to receive(:authenticated_user).and_return(
|
|
@@ -248,19 +233,20 @@ describe Geet::Services::CreatePr do
|
|
|
248
233
|
)
|
|
249
234
|
|
|
250
235
|
mock_pr = double(
|
|
251
|
-
|
|
236
|
+
"PR",
|
|
252
237
|
number: 1,
|
|
253
|
-
title:
|
|
254
|
-
link:
|
|
238
|
+
title: "Title",
|
|
239
|
+
link: "https://github.com/donaldduck/testrepo_f/pull/1"
|
|
255
240
|
)
|
|
256
241
|
|
|
257
242
|
allow(repository).to receive(:create_pr).and_return(mock_pr)
|
|
258
243
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
244
|
+
expect {
|
|
245
|
+
expect do
|
|
246
|
+
service_instance = described_class.new(repository, git_client:)
|
|
247
|
+
service_instance.execute("Title", "Description", automerge: true)
|
|
248
|
+
end.to raise_error(RuntimeError, "Automerge is not supported for this repository provider")
|
|
249
|
+
}.to output(//).to_stdout
|
|
264
250
|
end
|
|
265
251
|
end
|
|
266
252
|
end # context 'with github.com'
|