geet 0.3.13 → 0.3.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +8 -0
- data/README.md +5 -8
- data/bin/geet +26 -7
- data/extra/anonymize_vcr_data +58 -0
- data/geet.gemspec +1 -1
- data/lib/geet/commandline/commands.rb +5 -0
- data/lib/geet/commandline/configuration.rb +31 -0
- data/lib/geet/git/repository.rb +19 -1
- data/lib/geet/github/abstract_issue.rb +9 -0
- data/lib/geet/github/api_interface.rb +2 -0
- data/lib/geet/github/branch.rb +1 -1
- data/lib/geet/github/issue.rb +1 -1
- data/lib/geet/github/label.rb +2 -2
- data/lib/geet/github/milestone.rb +29 -2
- data/lib/geet/github/remote_repository.rb +37 -0
- data/lib/geet/github/user.rb +2 -2
- data/lib/geet/gitlab/api_interface.rb +2 -0
- data/lib/geet/gitlab/label.rb +2 -2
- data/lib/geet/gitlab/milestone.rb +1 -1
- data/lib/geet/gitlab/user.rb +1 -1
- data/lib/geet/services/add_upstream_repo.rb +37 -0
- data/lib/geet/services/close_milestones.rb +46 -0
- data/lib/geet/services/comment_pr.rb +31 -0
- data/lib/geet/services/create_issue.rb +5 -3
- data/lib/geet/services/create_milestone.rb +24 -0
- data/lib/geet/services/create_pr.rb +5 -3
- data/lib/geet/services/list_issues.rb +4 -1
- data/lib/geet/services/merge_pr.rb +55 -4
- data/lib/geet/services/open_repo.rb +50 -0
- data/lib/geet/shared/branches.rb +9 -0
- data/lib/geet/shared/selection.rb +3 -0
- data/lib/geet/utils/attributes_selection_manager.rb +12 -3
- data/lib/geet/utils/git_client.rb +101 -28
- data/lib/geet/version.rb +1 -1
- data/spec/integration/comment_pr_spec.rb +44 -0
- data/spec/integration/create_issue_spec.rb +4 -4
- data/spec/integration/create_label_spec.rb +5 -5
- data/spec/integration/create_milestone_spec.rb +34 -0
- data/spec/integration/create_pr_spec.rb +8 -8
- data/spec/integration/list_issues_spec.rb +6 -6
- data/spec/integration/list_labels_spec.rb +4 -4
- data/spec/integration/list_milestones_spec.rb +4 -4
- data/spec/integration/list_prs_spec.rb +3 -3
- data/spec/integration/merge_pr_spec.rb +29 -4
- data/spec/integration/open_pr_spec.rb +1 -1
- data/spec/integration/open_repo_spec.rb +46 -0
- data/spec/vcr_cassettes/create_gist_private.yml +1 -1
- data/spec/vcr_cassettes/create_gist_public.yml +1 -1
- data/spec/vcr_cassettes/create_issue.yml +13 -13
- data/spec/vcr_cassettes/create_issue_upstream.yml +2 -2
- data/spec/vcr_cassettes/github_com/comment_pr.yml +161 -0
- data/spec/vcr_cassettes/github_com/create_label.yml +1 -1
- data/spec/vcr_cassettes/github_com/create_label_upstream.yml +1 -1
- data/spec/vcr_cassettes/github_com/create_label_with_random_color.yml +1 -1
- data/spec/vcr_cassettes/github_com/create_milestone.yml +82 -0
- data/spec/vcr_cassettes/github_com/create_pr.yml +16 -16
- data/spec/vcr_cassettes/github_com/create_pr_in_auto_mode_create_upstream.yml +7 -7
- data/spec/vcr_cassettes/github_com/create_pr_in_auto_mode_with_push.yml +7 -7
- data/spec/vcr_cassettes/github_com/create_pr_upstream.yml +8 -8
- data/spec/vcr_cassettes/github_com/create_pr_upstream_without_write_permissions.yml +3 -3
- data/spec/vcr_cassettes/github_com/list_issues.yml +5 -5
- data/spec/vcr_cassettes/github_com/list_issues_upstream.yml +6 -6
- data/spec/vcr_cassettes/github_com/list_issues_with_assignee.yml +4 -4
- data/spec/vcr_cassettes/github_com/list_labels.yml +1 -1
- data/spec/vcr_cassettes/github_com/list_labels_upstream.yml +1 -1
- data/spec/vcr_cassettes/github_com/list_milestones.yml +50 -50
- data/spec/vcr_cassettes/github_com/merge_pr.yml +2 -2
- data/spec/vcr_cassettes/github_com/merge_pr_with_branch_deletion.yml +2 -2
- data/spec/vcr_cassettes/github_com/open_pr.yml +2 -2
- data/spec/vcr_cassettes/gitlab_com/create_label.yml +1 -1
- data/spec/vcr_cassettes/gitlab_com/list_issues.yml +4 -4
- data/spec/vcr_cassettes/gitlab_com/list_issues_with_assignee.yml +8 -8
- data/spec/vcr_cassettes/gitlab_com/list_labels.yml +1 -1
- data/spec/vcr_cassettes/gitlab_com/list_milestones.yml +9 -9
- data/spec/vcr_cassettes/gitlab_com/merge_pr.yml +5 -5
- data/spec/vcr_cassettes/list_milestones_upstream.yml +21 -21
- data/spec/vcr_cassettes/list_prs.yml +10 -10
- data/spec/vcr_cassettes/list_prs_upstream.yml +10 -10
- metadata +16 -4
@@ -30,8 +30,10 @@ module Geet
|
|
30
30
|
@selections_data = []
|
31
31
|
end
|
32
32
|
|
33
|
+
# selection_type: SELECTION_SINGLE or SELECTION_MULTIPLE
|
34
|
+
#
|
33
35
|
def add_attribute(repository_call, description, pattern, selection_type, name_method: nil, &pre_selection_hook)
|
34
|
-
raise "Unrecognized selection type #{selection_type.inspect}" if ![
|
36
|
+
raise "Unrecognized selection type #{selection_type.inspect}" if ![SELECTION_SINGLE, SELECTION_MULTIPLE].include?(selection_type)
|
35
37
|
|
36
38
|
finder_thread = find_attribute_entries(repository_call)
|
37
39
|
|
@@ -47,9 +49,9 @@ module Geet
|
|
47
49
|
entries = pre_selection_hook.(entries) if pre_selection_hook
|
48
50
|
|
49
51
|
case selection_type
|
50
|
-
when
|
52
|
+
when SELECTION_SINGLE
|
51
53
|
select_entry(description, entries, pattern, name_method)
|
52
|
-
when
|
54
|
+
when SELECTION_MULTIPLE
|
53
55
|
select_entries(description, entries, pattern, name_method)
|
54
56
|
end
|
55
57
|
end
|
@@ -86,6 +88,13 @@ module Geet
|
|
86
88
|
# select_entries('reviewer', all_collaborators, 'donaldduck', nil)
|
87
89
|
#
|
88
90
|
def select_entries(entry_type, entries, pattern, name_method)
|
91
|
+
# Support both formats Array and String.
|
92
|
+
# It seems that at some point, SimpleScripting started splitting arrays automatically, so until
|
93
|
+
# the code is adjusted accordingly, this accommodates both the CLI and the test suite.
|
94
|
+
# Tracked here: https://github.com/saveriomiroddi/geet/issues/171.
|
95
|
+
#
|
96
|
+
pattern = pattern.join(',') if pattern.is_a?(Array)
|
97
|
+
|
89
98
|
if pattern == MANUAL_LIST_SELECTION_FLAG
|
90
99
|
Geet::Utils::ManualListSelection.new.select_entries(entry_type, entries, name_method: name_method)
|
91
100
|
else
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'English'
|
3
4
|
require 'shellwords'
|
4
5
|
require_relative '../helpers/os_helper'
|
5
6
|
|
@@ -10,15 +11,25 @@ module Geet
|
|
10
11
|
class GitClient
|
11
12
|
include Geet::Helpers::OsHelper
|
12
13
|
|
13
|
-
ORIGIN_NAME = 'origin'
|
14
14
|
UPSTREAM_NAME = 'upstream'
|
15
15
|
|
16
|
-
#
|
17
|
-
|
16
|
+
# Simplified, but good enough, pattern.
|
17
|
+
#
|
18
|
+
# Relevant matches:
|
19
|
+
#
|
20
|
+
# 1: protocol + suffix
|
21
|
+
# 2: domain
|
22
|
+
# 3: domain<>path separator
|
23
|
+
# 4: path (repo, project)
|
24
|
+
# 5: suffix
|
25
|
+
#
|
26
|
+
REMOTE_URL_REGEX = %r{
|
18
27
|
\A
|
19
|
-
(
|
20
|
-
(
|
21
|
-
(
|
28
|
+
(https://|git@)
|
29
|
+
(.+?)
|
30
|
+
([/:])
|
31
|
+
(.+/.+?)
|
32
|
+
(\.git)?
|
22
33
|
\Z
|
23
34
|
}x
|
24
35
|
|
@@ -38,13 +49,13 @@ module Geet
|
|
38
49
|
# (which start with `-`)
|
39
50
|
#
|
40
51
|
def cherry(limit)
|
41
|
-
raw_commits =
|
52
|
+
raw_commits = execute_git_command("cherry #{limit.shellescape}")
|
42
53
|
|
43
54
|
raw_commits.split("\n").grep(/^\+/).map { |line| line[3..-1] }
|
44
55
|
end
|
45
56
|
|
46
57
|
def current_branch
|
47
|
-
branch =
|
58
|
+
branch = execute_git_command("rev-parse --abbrev-ref HEAD")
|
48
59
|
|
49
60
|
raise "Couldn't find current branch" if branch == 'HEAD'
|
50
61
|
|
@@ -53,12 +64,14 @@ module Geet
|
|
53
64
|
|
54
65
|
# Not to be confused with `upstream` repository!
|
55
66
|
#
|
67
|
+
# This API doesn't reveal if the remote branch is gone.
|
68
|
+
#
|
56
69
|
# return: nil, if the upstream branch is not configured.
|
57
70
|
#
|
58
71
|
def upstream_branch
|
59
|
-
head_symbolic_ref =
|
72
|
+
head_symbolic_ref = execute_git_command("symbolic-ref -q HEAD")
|
60
73
|
|
61
|
-
raw_upstream_branch =
|
74
|
+
raw_upstream_branch = execute_git_command("for-each-ref --format='%(upstream:short)' #{head_symbolic_ref.shellescape}").strip
|
62
75
|
|
63
76
|
if raw_upstream_branch != ''
|
64
77
|
raw_upstream_branch[UPSTREAM_BRANCH_REGEX, 1] || raise("Unexpected upstream format: #{raw_upstream_branch}")
|
@@ -67,8 +80,30 @@ module Geet
|
|
67
80
|
end
|
68
81
|
end
|
69
82
|
|
83
|
+
# TODO: May be merged with :upstream_branch, although it would require designing how a gone
|
84
|
+
# remote branch is expressed.
|
85
|
+
#
|
86
|
+
# Sample command output:
|
87
|
+
#
|
88
|
+
# ## add_milestone_closing...origin/add_milestone_closing [gone]
|
89
|
+
# M spec/integration/merge_pr_spec.rb
|
90
|
+
#
|
91
|
+
def upstream_branch_gone?
|
92
|
+
git_command = "status -b --porcelain"
|
93
|
+
status_output = execute_git_command(git_command)
|
94
|
+
|
95
|
+
# Simplified branch naming pattern. The exact one (see https://stackoverflow.com/a/3651867)
|
96
|
+
# is not worth implementing.
|
97
|
+
#
|
98
|
+
if status_output =~ %r(^## .+\.\.\..+?( \[gone\])?$)
|
99
|
+
!!$LAST_MATCH_INFO[1]
|
100
|
+
else
|
101
|
+
raise "Unexpected git command #{git_command.inspect} output: #{status_output}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
70
105
|
def working_tree_clean?
|
71
|
-
git_message =
|
106
|
+
git_message = execute_git_command("status")
|
72
107
|
|
73
108
|
!!(git_message =~ CLEAN_TREE_MESSAGE_REGEX)
|
74
109
|
end
|
@@ -80,19 +115,26 @@ module Geet
|
|
80
115
|
# Show the description ("<subject>\n\n<body>") for the given git object.
|
81
116
|
#
|
82
117
|
def show_description(object)
|
83
|
-
|
118
|
+
execute_git_command("show --quiet --format='%s\n\n%b' #{object.shellescape}")
|
84
119
|
end
|
85
120
|
|
86
121
|
##########################################################################
|
87
|
-
# REPOSITORY/REMOTE APIS
|
122
|
+
# REPOSITORY/REMOTE QUERYING APIS
|
88
123
|
##########################################################################
|
89
124
|
|
125
|
+
# Return the components of the remote, according to REMOTE_URL_REGEX; doesn't include the full
|
126
|
+
# match.
|
127
|
+
#
|
128
|
+
def remote_components(name: nil)
|
129
|
+
remote.match(REMOTE_URL_REGEX)[1..]
|
130
|
+
end
|
131
|
+
|
90
132
|
# Example: `donaldduck/geet`
|
91
133
|
#
|
92
134
|
def path(upstream: false)
|
93
|
-
|
135
|
+
remote_name_option = upstream ? {name: UPSTREAM_NAME} : {}
|
94
136
|
|
95
|
-
remote(
|
137
|
+
remote(**remote_name_option)[REMOTE_URL_REGEX, 4]
|
96
138
|
end
|
97
139
|
|
98
140
|
def owner
|
@@ -101,12 +143,10 @@ module Geet
|
|
101
143
|
|
102
144
|
def provider_domain
|
103
145
|
# We assume that it's not possible to have origin and upstream on different providers.
|
104
|
-
#
|
105
|
-
remote_url = remote(ORIGIN_NAME)
|
106
146
|
|
107
|
-
domain =
|
147
|
+
domain = remote()[REMOTE_URL_REGEX, 2]
|
108
148
|
|
109
|
-
raise "Can't identify domain in the provider domain string: #{domain}" if domain !~
|
149
|
+
raise "Can't identify domain in the provider domain string: #{domain}" if domain !~ /\w+\.\w+/
|
110
150
|
|
111
151
|
domain
|
112
152
|
end
|
@@ -116,12 +156,15 @@ module Geet
|
|
116
156
|
#
|
117
157
|
# The result is in the format `git@github.com:donaldduck/geet.git`
|
118
158
|
#
|
119
|
-
|
120
|
-
|
159
|
+
# options
|
160
|
+
# :name: remote name; if unspecified, the default remote is used.
|
161
|
+
#
|
162
|
+
def remote(name: nil)
|
163
|
+
remote_url = execute_git_command("ls-remote --get-url #{name}")
|
121
164
|
|
122
|
-
if
|
165
|
+
if !remote_defined?(name)
|
123
166
|
raise "Remote #{name.inspect} not found!"
|
124
|
-
elsif remote_url !~
|
167
|
+
elsif remote_url !~ REMOTE_URL_REGEX
|
125
168
|
raise "Unexpected remote reference format: #{remote_url.inspect}"
|
126
169
|
end
|
127
170
|
|
@@ -132,9 +175,10 @@ module Geet
|
|
132
175
|
# purposes, any any action that needs to work with the remote, uses #remote.
|
133
176
|
#
|
134
177
|
def remote_defined?(name)
|
135
|
-
remote_url =
|
178
|
+
remote_url = execute_git_command("ls-remote --get-url #{name}")
|
136
179
|
|
137
|
-
# If the remote is not
|
180
|
+
# If the remote is not defined, `git ls-remote` will return the passed value.
|
181
|
+
#
|
138
182
|
remote_url != name
|
139
183
|
end
|
140
184
|
|
@@ -142,12 +186,36 @@ module Geet
|
|
142
186
|
# OPERATION APIS
|
143
187
|
##########################################################################
|
144
188
|
|
189
|
+
def checkout(branch)
|
190
|
+
execute_git_command("checkout #{branch.shellescape}")
|
191
|
+
end
|
192
|
+
|
193
|
+
# Unforced deletion.
|
194
|
+
#
|
195
|
+
def delete_branch(branch)
|
196
|
+
execute_git_command("branch --delete #{branch.shellescape}")
|
197
|
+
end
|
198
|
+
|
199
|
+
def rebase
|
200
|
+
execute_git_command("rebase")
|
201
|
+
end
|
202
|
+
|
145
203
|
# upstream_branch: create an upstream branch.
|
146
204
|
#
|
147
205
|
def push(upstream_branch: nil)
|
148
206
|
upstream_branch_option = "-u origin #{upstream_branch.shellescape}" if upstream_branch
|
149
207
|
|
150
|
-
|
208
|
+
execute_git_command("push #{upstream_branch_option}")
|
209
|
+
end
|
210
|
+
|
211
|
+
# Performs pruning.
|
212
|
+
#
|
213
|
+
def fetch
|
214
|
+
execute_git_command("fetch --prune")
|
215
|
+
end
|
216
|
+
|
217
|
+
def add_remote(name, url)
|
218
|
+
execute_git_command("remote add #{name.shellescape} #{url}")
|
151
219
|
end
|
152
220
|
|
153
221
|
##########################################################################
|
@@ -156,8 +224,13 @@ module Geet
|
|
156
224
|
|
157
225
|
private
|
158
226
|
|
159
|
-
|
160
|
-
|
227
|
+
# If executing a git command without calling this API, don't forget to split `gitdir_option`
|
228
|
+
# and use it!
|
229
|
+
#
|
230
|
+
def execute_git_command(command)
|
231
|
+
gitdir_option = "-C #{@location.shellescape}" if @location
|
232
|
+
|
233
|
+
execute_command("git #{gitdir_option} #{command}")
|
161
234
|
end
|
162
235
|
end
|
163
236
|
end
|
data/lib/geet/version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
require_relative '../../lib/geet/git/repository'
|
6
|
+
require_relative '../../lib/geet/services/comment_pr'
|
7
|
+
|
8
|
+
describe Geet::Services::CommentPr do
|
9
|
+
let(:git_client) { Geet::Utils::GitClient.new }
|
10
|
+
let(:repository) { Geet::Git::Repository.new(git_client: git_client) }
|
11
|
+
let(:owner) { 'donaldduck' }
|
12
|
+
let(:branch) { 'mybranch' }
|
13
|
+
let(:comment) { 'this is a programmatically added comment' }
|
14
|
+
|
15
|
+
context 'with github.com' do
|
16
|
+
let(:repository_name) { 'testrepo_upstream' }
|
17
|
+
|
18
|
+
it 'should add a comment to the PR for the current branch' do
|
19
|
+
allow(git_client).to receive(:current_branch).and_return(branch)
|
20
|
+
allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:#{owner}/#{repository_name}")
|
21
|
+
|
22
|
+
expected_pr_number = 3
|
23
|
+
expected_output = <<~STR
|
24
|
+
Finding PR with head (#{owner}:#{branch})...
|
25
|
+
STR
|
26
|
+
|
27
|
+
actual_output = StringIO.new
|
28
|
+
service_instance = described_class.new(repository, out: actual_output, git_client: git_client)
|
29
|
+
|
30
|
+
expect(service_instance).to receive(:open_file_with_default_application).with("https://github.com/#{owner}/#{repository_name}/pull/#{expected_pr_number}") do
|
31
|
+
# do nothing; just don't open the browser
|
32
|
+
end
|
33
|
+
|
34
|
+
service_result = VCR.use_cassette('github_com/comment_pr') do
|
35
|
+
service_instance.execute(comment)
|
36
|
+
end
|
37
|
+
|
38
|
+
actual_pr_number = service_result.number
|
39
|
+
|
40
|
+
expect(actual_output.string).to eql(expected_output)
|
41
|
+
expect(actual_pr_number).to eql(expected_pr_number)
|
42
|
+
end
|
43
|
+
end # context 'with github.com'
|
44
|
+
end
|
@@ -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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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...
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
require_relative '../../lib/geet/git/repository'
|
6
|
+
require_relative '../../lib/geet/services/create_milestone'
|
7
|
+
|
8
|
+
describe Geet::Services::CreateMilestone do
|
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) }
|
12
|
+
|
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
|
+
|
17
|
+
expected_output = <<~STR
|
18
|
+
Creating milestone...
|
19
|
+
STR
|
20
|
+
|
21
|
+
actual_output = StringIO.new
|
22
|
+
|
23
|
+
actual_created_label = VCR.use_cassette('github_com/create_milestone') do
|
24
|
+
described_class.new(repository, out: actual_output).execute('my_milestone')
|
25
|
+
end
|
26
|
+
|
27
|
+
expect(actual_output.string).to eql(expected_output)
|
28
|
+
|
29
|
+
expect(actual_created_label.number).to eql(6)
|
30
|
+
expect(actual_created_label.title).to eql('my_milestone')
|
31
|
+
expect(actual_created_label.due_on).to be(nil)
|
32
|
+
end
|
33
|
+
end # context 'with github.com'
|
34
|
+
end # describe Geet::Services::CreateLabel
|
@@ -14,7 +14,7 @@ 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(
|
17
|
+
allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
|
18
18
|
|
19
19
|
expected_output = <<~STR
|
20
20
|
Finding labels...
|
@@ -50,8 +50,8 @@ describe Geet::Services::CreatePr do
|
|
50
50
|
context 'on an upstream repository' do
|
51
51
|
it 'should create an upstream PR' do
|
52
52
|
allow(git_client).to receive(:current_branch).and_return('mybranch')
|
53
|
-
allow(git_client).to receive(:remote).with(
|
54
|
-
allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:donald-fr/testrepo_u')
|
53
|
+
allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
|
54
|
+
allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:donald-fr/testrepo_u')
|
55
55
|
|
56
56
|
expected_output = <<~STR
|
57
57
|
Creating PR...
|
@@ -80,8 +80,8 @@ describe Geet::Services::CreatePr do
|
|
80
80
|
context 'without labels, reviewers and milestones' do
|
81
81
|
it 'should create a PR' do
|
82
82
|
allow(git_client).to receive(:current_branch).and_return('mybranch')
|
83
|
-
allow(git_client).to receive(:remote).with(
|
84
|
-
allow(git_client).to receive(:remote).with('upstream').and_return('git@github.com:donald-fr/testrepo_u')
|
83
|
+
allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
|
84
|
+
allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:donald-fr/testrepo_u')
|
85
85
|
|
86
86
|
expected_output = <<~STR
|
87
87
|
Creating PR...
|
@@ -112,7 +112,7 @@ describe Geet::Services::CreatePr do
|
|
112
112
|
context 'in automated mode' do
|
113
113
|
it 'should raise an error when the working tree is dirty' do
|
114
114
|
allow(git_client).to receive(:working_tree_clean?).and_return(false)
|
115
|
-
allow(git_client).to receive(:remote).with(
|
115
|
+
allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
|
116
116
|
|
117
117
|
expected_output = <<~STR
|
118
118
|
Error! Saved summary to /tmp/last_geet_edited_summary.md
|
@@ -136,7 +136,7 @@ describe Geet::Services::CreatePr do
|
|
136
136
|
expect(git_client).to receive(:upstream_branch).and_return('mybranch')
|
137
137
|
expect(git_client).to receive(:push)
|
138
138
|
|
139
|
-
allow(git_client).to receive(:remote).with(
|
139
|
+
allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
|
140
140
|
|
141
141
|
expected_output = <<~STR
|
142
142
|
Pushing to upstream branch...
|
@@ -161,7 +161,7 @@ describe Geet::Services::CreatePr do
|
|
161
161
|
expect(git_client).to receive(:upstream_branch).and_return(nil)
|
162
162
|
expect(git_client).to receive(:push).with(upstream_branch: 'mybranch')
|
163
163
|
|
164
|
-
allow(git_client).to receive(:remote).with(
|
164
|
+
allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
|
165
165
|
|
166
166
|
expected_output = <<~STR
|
167
167
|
Creating upstream branch "mybranch"...
|