geet 0.3.18 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b37d7ac48684dcd431b13c0e00cb9f999764ae714dec3c8d046102469f7f62f
4
- data.tar.gz: 43a045941aff66c212314ae0de2c5c439434c75e89240ce2c59750f5759dcc5a
3
+ metadata.gz: 72e79c90885595952ceb12c04e7348639bf1582b24764955810fb8b0b50b574f
4
+ data.tar.gz: f16daadc22258458d650bab0a665b6f903cc7461903807a6b17968a7706f8089
5
5
  SHA512:
6
- metadata.gz: fe4aa67774fef6b5943ae4f6eb2950ec4d4c2b7f004aa963438e00904d80d01c3a73db8671567c718b6fc9b235a2e9d2002744ec891bce3ff4af1144ffa01d28
7
- data.tar.gz: 14c3efa61fa206f3f3f70432c3683d394f9e4e4e09f6cefad757d96d11b88110559f393d22d296acef963d72d7117c668125724da79d8f1f6cbda9e35dfc367a
6
+ metadata.gz: b3e9160181a4b619c33e0eb5ea137ae233f70b3d7281a16097ef6469c363dd35bc0eb0d3e17e8804019c7ea43f7abee9146f76e137c2312267eec926a5af0b3b
7
+ data.tar.gz: 1305850037b80671c375c99336b826e9c77fcbf301e5bcdb545e643f6be00a1ce96767d4a78f1439f28a4ef52ac3325557a93a031eef67b1196396706e56b86d
data/bin/geet CHANGED
@@ -88,12 +88,10 @@ class GeetLauncher
88
88
  private
89
89
 
90
90
  def edit_pr_summary(base: nil)
91
- base ||= 'master'
92
-
93
91
  # Tricky. It would be best to have Git logic exlusively inside the services,
94
92
  # but at the same time, the summary editing should be out.
95
93
  git = Utils::GitClient.new
96
- pr_commits = git.cherry(base)
94
+ pr_commits = git.cherry(base: base)
97
95
 
98
96
  if pr_commits.size == 1
99
97
  prepopulated_summary = git.show_description('HEAD')
data/geet.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.required_ruby_version = '>= 2.3.0'
12
12
  s.authors = ['Saverio Miroddi']
13
- s.date = '2021-05-28'
13
+ s.date = '2021-09-04'
14
14
  s.email = ['saverio.pub2@gmail.com']
15
15
  s.homepage = 'https://github.com/saveriomiroddi/geet'
16
16
  s.summary = 'Commandline interface for performing SCM host operations, eg. create a PR on GitHub'
@@ -67,7 +67,8 @@ module Geet
67
67
  PR_CREATE_OPTIONS = [
68
68
  ['-A', '--automated-mode', "Automate the branch operations (see long help)"],
69
69
  ['-n', '--no-open-pr', "Don't open the PR link in the browser after creation"],
70
- ['-b', '--base develop', "Specify the base branch; defaults to `master`"],
70
+ ['-b', '--base develop', "Specify the base branch; defaults to the main branch"],
71
+ ['-d', '--draft', "Create as draft"],
71
72
  ['-l', '--labels "legacy,code review"', 'Labels'],
72
73
  ['-m', '--milestone 1.5.0', 'Milestone title pattern'],
73
74
  ['-r', '--reviewers john,tom,adrian,kevin', 'Reviewer logins'],
@@ -95,6 +96,7 @@ module Geet
95
96
  ]
96
97
 
97
98
  PR_OPEN_OPTIONS = [
99
+ ['-u', '--upstream', 'List on the upstream repository'],
98
100
  long_help: 'Open in the browser the PR for the current branch'
99
101
  ]
100
102
 
@@ -74,11 +74,11 @@ module Geet
74
74
  attempt_provider_call(:Milestone, :close, number, api_interface)
75
75
  end
76
76
 
77
- def create_pr(title, description, head, base: nil)
77
+ def create_pr(title, description, head, base, draft)
78
78
  confirm(LOCAL_ACTION_ON_UPSTREAM_REPOSITORY_MESSAGE) if local_action_on_upstream_repository? && @warnings
79
79
  confirm(ACTION_ON_PROTECTED_REPOSITORY_MESSAGE) if action_on_protected_repository? && @warnings
80
80
 
81
- attempt_provider_call(:PR, :create, title, description, head, api_interface, base: base)
81
+ attempt_provider_call(:PR, :create, title, description, head, api_interface, base, draft: draft)
82
82
  end
83
83
 
84
84
  def prs(owner: nil, head: nil, milestone: nil)
@@ -22,6 +22,9 @@ module Geet
22
22
 
23
23
  # See https://developer.github.com/v3/issues/#list-issues-for-a-repository
24
24
  #
25
+ # This works both for Issues and PRs, however, when the `/pulls` API (path) is used, additional
26
+ # information is provided (e.g. `head`).
27
+ #
25
28
  def self.list(api_interface, milestone: nil, assignee: nil, &type_filter)
26
29
  api_path = 'issues'
27
30
 
@@ -8,7 +8,7 @@ module Geet
8
8
  class Issue < Geet::Github::AbstractIssue
9
9
  def self.create(title, description, api_interface, **)
10
10
  api_path = 'issues'
11
- request_data = { title: title, body: description, base: 'master' }
11
+ request_data = { title: title, body: description }
12
12
 
13
13
  response = api_interface.send_request(api_path, data: request_data)
14
14
 
@@ -8,16 +8,15 @@ module Geet
8
8
  class PR < AbstractIssue
9
9
  # See https://developer.github.com/v3/pulls/#create-a-pull-request
10
10
  #
11
- def self.create(title, description, head, api_interface, base: nil)
11
+ def self.create(title, description, head, api_interface, base, draft: false)
12
12
  api_path = 'pulls'
13
- base ||= 'master'
14
13
 
15
14
  if api_interface.upstream?
16
15
  authenticated_user = Geet::Github::User.authenticated(api_interface).username
17
16
  head = "#{authenticated_user}:#{head}"
18
17
  end
19
18
 
20
- request_data = { title: title, body: description, head: head, base: base }
19
+ request_data = { title: title, body: description, head: head, base: base, draft: draft }
21
20
 
22
21
  response = api_interface.send_request(api_path, data: request_data)
23
22
 
@@ -33,14 +32,34 @@ module Geet
33
32
 
34
33
  if head
35
34
  api_path = 'pulls'
36
- request_params = { head: "#{owner}:#{head}" }
37
35
 
38
- response = api_interface.send_request(api_path, params: request_params, multipage: true)
36
+ # Technically, the upstream approach could be used for both, but it's actually good to have
37
+ # both of them as reference.
38
+ #
39
+ # For upstream pulls, the owner is the authenticated user, otherwise, the repository owner.
40
+ #
41
+ response = if api_interface.upstream?
42
+ unfiltered_response = api_interface.send_request(api_path, multipage: true)
43
+
44
+ # VERY weird. From the docs, it's not clear if the user/org is required in the `head` parameter,
45
+ # but:
46
+ #
47
+ # - if it isn't included (eg. `anything`), the parameter is ignored
48
+ # - if it's included (eg. `saveriomiroddi:local_branch_name`), an empty resultset is returned.
49
+ #
50
+ # For this reason, we can't use that param, and have to filter manually.
51
+ #
52
+ unfiltered_response.select { |pr_data| pr_data.fetch('head').fetch('label') == "#{owner}:#{head}" }
53
+ else
54
+ request_params = { head: "#{owner}:#{head}" }
55
+
56
+ api_interface.send_request(api_path, params: request_params, multipage: true)
57
+ end
39
58
 
40
- response.map do |issue_data|
41
- number = issue_data.fetch('number')
42
- title = issue_data.fetch('title')
43
- link = issue_data.fetch('html_url')
59
+ response.map do |pr_data|
60
+ number = pr_data.fetch('number')
61
+ title = pr_data.fetch('title')
62
+ link = pr_data.fetch('html_url')
44
63
 
45
64
  new(number, api_interface, title, link)
46
65
  end
@@ -26,14 +26,15 @@ module Geet
26
26
  # interactive: set when required; in this case, a different API will be used (`system()`
27
27
  # instead of `popen3`).
28
28
  # silent_stderr: don't print the stderr output
29
+ # allow_error: don't raise error on failure
29
30
  #
30
- def execute_command(command, description: nil, interactive: false, silent_stderr: false)
31
+ def execute_command(command, description: nil, interactive: false, silent_stderr: false, allow_error: false)
31
32
  description_message = " on #{description}" if description
32
33
 
33
34
  if interactive
34
35
  system(command)
35
36
 
36
- if !$CHILD_STATUS.success?
37
+ if !$CHILD_STATUS.success? && !allow_error
37
38
  raise "Error#{description_message} (exit status: #{$CHILD_STATUS.exitstatus})"
38
39
  end
39
40
  else
@@ -43,7 +44,7 @@ module Geet
43
44
 
44
45
  puts stderr_content if stderr_content != '' && !silent_stderr
45
46
 
46
- if !wait_thread.value.success?
47
+ if !wait_thread.value.success? && !allow_error
47
48
  error_message = stderr_content.lines.first&.strip || "Error running command #{command.inspect}"
48
49
  raise "Error#{description_message}: #{error_message}"
49
50
  end
@@ -9,17 +9,19 @@ module Geet
9
9
  # Helper for services common workflow, for example, find the merge head.
10
10
  #
11
11
  module ServicesWorkflowHelper
12
- # Requires: @git_client
13
- #
14
- def find_merge_head
15
- [@git_client.owner, @git_client.current_branch]
16
- end
17
-
18
12
  # Expect to find only one.
19
13
  #
20
14
  # Requires: @out, @repository.
21
15
  #
22
- def checked_find_branch_pr(owner, head)
16
+ def checked_find_branch_pr
17
+ owner = if @repository.upstream?
18
+ @repository.authenticated_user.username
19
+ else
20
+ @git_client.owner
21
+ end
22
+
23
+ head = @git_client.current_branch
24
+
23
25
  @out.puts "Finding PR with head (#{owner}:#{head})..."
24
26
 
25
27
  prs = @repository.prs(owner: owner, head: head)
@@ -20,8 +20,7 @@ module Geet
20
20
  end
21
21
 
22
22
  def execute(comment, no_open_pr: nil)
23
- merge_owner, merge_head = find_merge_head
24
- pr = checked_find_branch_pr(merge_owner, merge_head)
23
+ pr = checked_find_branch_pr
25
24
  pr.comment(comment)
26
25
  open_file_with_default_application(pr.link) unless no_open_pr
27
26
  pr
@@ -25,7 +25,7 @@ module Geet
25
25
  #
26
26
  def execute(
27
27
  title, description, labels: nil, milestone: nil, reviewers: nil,
28
- base: nil, no_open_pr: nil, automated_mode: false, **
28
+ base: nil, draft: false, no_open_pr: nil, automated_mode: false, **
29
29
  )
30
30
  ensure_clean_tree if automated_mode
31
31
 
@@ -37,9 +37,9 @@ module Geet
37
37
  selected_labels, selected_milestone, selected_reviewers = find_and_select_attributes(labels, milestone, reviewers)
38
38
  end
39
39
 
40
- sync_with_upstream_branch if automated_mode
40
+ sync_with_remote_branch if automated_mode
41
41
 
42
- pr = create_pr(title, description, base)
42
+ pr = create_pr(title, description, base: base, draft: draft)
43
43
 
44
44
  if user_has_write_permissions
45
45
  edit_pr(pr, selected_labels, selected_milestone, selected_reviewers)
@@ -81,24 +81,26 @@ module Geet
81
81
  selection_manager.select_attributes
82
82
  end
83
83
 
84
- def sync_with_upstream_branch
85
- if @git_client.upstream_branch
86
- @out.puts "Pushing to upstream branch..."
84
+ def sync_with_remote_branch
85
+ if @git_client.remote_branch
86
+ @out.puts "Pushing to remote branch..."
87
87
 
88
88
  @git_client.push
89
89
  else
90
- upstream_branch = @git_client.current_branch
90
+ remote_branch = @git_client.current_branch
91
91
 
92
- @out.puts "Creating upstream branch #{upstream_branch.inspect}..."
92
+ @out.puts "Creating remote branch #{remote_branch.inspect}..."
93
93
 
94
- @git_client.push(upstream_branch: upstream_branch)
94
+ @git_client.push(remote_branch: remote_branch)
95
95
  end
96
96
  end
97
97
 
98
- def create_pr(title, description, base)
98
+ def create_pr(title, description, base:, draft:)
99
99
  @out.puts 'Creating PR...'
100
100
 
101
- @repository.create_pr(title, description, @git_client.current_branch, base: base)
101
+ base ||= @git_client.main_branch
102
+
103
+ @repository.create_pr(title, description, @git_client.current_branch, base, draft)
102
104
  end
103
105
 
104
106
  def edit_pr(pr, labels, milestone, reviewers)
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../helpers/services_workflow_helper'
4
- require_relative '../shared/branches'
5
4
 
6
5
  module Geet
7
6
  module Services
@@ -13,7 +12,7 @@ module Geet
13
12
  #
14
13
  class MergePr
15
14
  include Geet::Helpers::ServicesWorkflowHelper
16
- include Geet::Shared::Branches
15
+ include Geet::Shared
17
16
 
18
17
  DEFAULT_GIT_CLIENT = Geet::Utils::GitClient.new
19
18
 
@@ -24,8 +23,7 @@ module Geet
24
23
  end
25
24
 
26
25
  def execute(delete_branch: false)
27
- merge_owner, merge_head = find_merge_head
28
- pr = checked_find_branch_pr(merge_owner, merge_head)
26
+ pr = checked_find_branch_pr
29
27
 
30
28
  merge_pr(pr)
31
29
 
@@ -37,13 +35,14 @@ module Geet
37
35
 
38
36
  fetch_repository
39
37
 
40
- if upstream_branch_gone?
38
+ if remote_branch_gone?
41
39
  pr_branch = @git_client.current_branch
40
+ main_branch = @git_client.main_branch
42
41
 
43
42
  # The rebase could also be placed after the branch deletion. There are pros/cons;
44
43
  # currently, it's not important.
45
44
  #
46
- checkout_branch(MAIN_BRANCH)
45
+ checkout_branch(main_branch)
47
46
  rebase
48
47
 
49
48
  delete_local_branch(pr_branch)
@@ -72,8 +71,8 @@ module Geet
72
71
  @git_client.fetch
73
72
  end
74
73
 
75
- def upstream_branch_gone?
76
- @git_client.upstream_branch_gone?
74
+ def remote_branch_gone?
75
+ @git_client.remote_branch_gone?
77
76
  end
78
77
 
79
78
  def checkout_branch(branch)
@@ -19,9 +19,8 @@ module Geet
19
19
  @git_client = git_client
20
20
  end
21
21
 
22
- def execute(delete_branch: false)
23
- merge_owner, merge_head = find_merge_head
24
- pr = checked_find_branch_pr(merge_owner, merge_head)
22
+ def execute(delete_branch: false, **)
23
+ pr = checked_find_branch_pr
25
24
  open_file_with_default_application(pr.link)
26
25
  pr
27
26
  end
@@ -11,6 +11,7 @@ module Geet
11
11
  class GitClient
12
12
  include Geet::Helpers::OsHelper
13
13
 
14
+ ORIGIN_NAME = 'origin'
14
15
  UPSTREAM_NAME = 'upstream'
15
16
 
16
17
  # Simplified, but good enough, pattern.
@@ -33,7 +34,9 @@ module Geet
33
34
  \Z
34
35
  }x
35
36
 
36
- UPSTREAM_BRANCH_REGEX = %r{\A[^/]+/([^/]+)\Z}
37
+ REMOTE_BRANCH_REGEX = %r{\A[^/]+/(.+)\Z}
38
+
39
+ MAIN_BRANCH_CONFIG_ENTRY = 'custom.development-branch'
37
40
 
38
41
  CLEAN_TREE_MESSAGE_REGEX = /^nothing to commit, working tree clean$/
39
42
 
@@ -45,11 +48,13 @@ module Geet
45
48
  # BRANCH/TREE APIS
46
49
  ##########################################################################
47
50
 
48
- # Return the commit shas between HEAD and `limit`, excluding the already applied commits
51
+ # Return the commit SHAs between HEAD and `base`, excluding the already applied commits
49
52
  # (which start with `-`)
50
53
  #
51
- def cherry(limit)
52
- raw_commits = execute_git_command("cherry #{limit.shellescape}")
54
+ def cherry(base: nil)
55
+ base ||= main_branch
56
+
57
+ raw_commits = execute_git_command("cherry #{base.shellescape}")
53
58
 
54
59
  raw_commits.split("\n").grep(/^\+/).map { |line| line[3..-1] }
55
60
  end
@@ -62,25 +67,23 @@ module Geet
62
67
  branch
63
68
  end
64
69
 
65
- # Not to be confused with `upstream` repository!
66
- #
67
70
  # This API doesn't reveal if the remote branch is gone.
68
71
  #
69
- # return: nil, if the upstream branch is not configured.
72
+ # return: nil, if the remote branch is not configured.
70
73
  #
71
- def upstream_branch
74
+ def remote_branch
72
75
  head_symbolic_ref = execute_git_command("symbolic-ref -q HEAD")
73
76
 
74
- raw_upstream_branch = execute_git_command("for-each-ref --format='%(upstream:short)' #{head_symbolic_ref.shellescape}").strip
77
+ raw_remote_branch = execute_git_command("for-each-ref --format='%(upstream:short)' #{head_symbolic_ref.shellescape}").strip
75
78
 
76
- if raw_upstream_branch != ''
77
- raw_upstream_branch[UPSTREAM_BRANCH_REGEX, 1] || raise("Unexpected upstream format: #{raw_upstream_branch}")
79
+ if raw_remote_branch != ''
80
+ raw_remote_branch[REMOTE_BRANCH_REGEX, 1] || raise("Unexpected remote branch format: #{raw_remote_branch}")
78
81
  else
79
82
  nil
80
83
  end
81
84
  end
82
85
 
83
- # TODO: May be merged with :upstream_branch, although it would require designing how a gone
86
+ # TODO: May be merged with :remote_branch, although it would require designing how a gone
84
87
  # remote branch is expressed.
85
88
  #
86
89
  # Sample command output:
@@ -88,7 +91,7 @@ module Geet
88
91
  # ## add_milestone_closing...origin/add_milestone_closing [gone]
89
92
  # M spec/integration/merge_pr_spec.rb
90
93
  #
91
- def upstream_branch_gone?
94
+ def remote_branch_gone?
92
95
  git_command = "status -b --porcelain"
93
96
  status_output = execute_git_command(git_command)
94
97
 
@@ -102,6 +105,19 @@ module Geet
102
105
  end
103
106
  end
104
107
 
108
+ # See https://saveriomiroddi.github.io/Conveniently-Handling-non-master-development-default-branches-in-git-hub
109
+ #
110
+ def main_branch
111
+ branch_name = execute_git_command("config --get #{MAIN_BRANCH_CONFIG_ENTRY}", allow_error: true)
112
+
113
+ if branch_name.empty?
114
+ full_branch_name = execute_git_command("rev-parse --abbrev-ref #{ORIGIN_NAME}/HEAD")
115
+ full_branch_name.split('/').last
116
+ else
117
+ branch_name
118
+ end
119
+ end
120
+
105
121
  def working_tree_clean?
106
122
  git_message = execute_git_command("status")
107
123
 
@@ -200,12 +216,12 @@ module Geet
200
216
  execute_git_command("rebase")
201
217
  end
202
218
 
203
- # upstream_branch: create an upstream branch.
219
+ # remote_branch: create an upstream branch.
204
220
  #
205
- def push(upstream_branch: nil)
206
- upstream_branch_option = "-u origin #{upstream_branch.shellescape}" if upstream_branch
221
+ def push(remote_branch: nil)
222
+ remote_branch_option = "-u #{ORIGIN_NAME} #{remote_branch.shellescape}" if remote_branch
207
223
 
208
- execute_git_command("push #{upstream_branch_option}")
224
+ execute_git_command("push #{remote_branch_option}")
209
225
  end
210
226
 
211
227
  # Performs pruning.
@@ -227,10 +243,14 @@ module Geet
227
243
  # If executing a git command without calling this API, don't forget to split `gitdir_option`
228
244
  # and use it!
229
245
  #
230
- def execute_git_command(command)
246
+ # options (passed to :execute_command):
247
+ # - allow_error
248
+ # - (others)
249
+ #
250
+ def execute_git_command(command, **options)
231
251
  gitdir_option = "-C #{@location.shellescape}" if @location
232
252
 
233
- execute_command("git #{gitdir_option} #{command}")
253
+ execute_command("git #{gitdir_option} #{command}", **options)
234
254
  end
235
255
  end
236
256
  end
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.18'
4
+ VERSION = '0.4.3'
5
5
  end
@@ -14,6 +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(:main_branch).and_return('master')
17
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
@@ -50,6 +51,7 @@ 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')
54
+ allow(git_client).to receive(:main_branch).and_return('master')
53
55
  allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
54
56
  allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:donald-fr/testrepo_u')
55
57
 
@@ -80,6 +82,7 @@ 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')
85
+ allow(git_client).to receive(:main_branch).and_return('master')
83
86
  allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
84
87
  allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:donald-fr/testrepo_u')
85
88
 
@@ -130,16 +133,17 @@ describe Geet::Services::CreatePr do
130
133
  expect(actual_output.string).to eql(expected_output)
131
134
  end
132
135
 
133
- it 'should push to the upstream branch' do
136
+ it 'should push to the remote 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')
136
- expect(git_client).to receive(:upstream_branch).and_return('mybranch')
139
+ allow(git_client).to receive(:main_branch).and_return('master')
140
+ expect(git_client).to receive(:remote_branch).and_return('mybranch')
137
141
  expect(git_client).to receive(:push)
138
142
 
139
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
- Pushing to upstream branch...
146
+ Pushing to remote branch...
143
147
  Creating PR...
144
148
  Assigning authenticated user...
145
149
  PR address: https://github.com/donaldduck/testrepo_f/pull/2
@@ -155,16 +159,17 @@ describe Geet::Services::CreatePr do
155
159
  expect(actual_output.string).to eql(expected_output)
156
160
  end
157
161
 
158
- it "should create an upstream branch, when there isn't one (is not tracked)" do
162
+ it "should create a remote 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')
161
- expect(git_client).to receive(:upstream_branch).and_return(nil)
162
- expect(git_client).to receive(:push).with(upstream_branch: 'mybranch')
165
+ allow(git_client).to receive(:main_branch).and_return('master')
166
+ expect(git_client).to receive(:remote_branch).and_return(nil)
167
+ expect(git_client).to receive(:push).with(remote_branch: 'mybranch')
163
168
 
164
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
- Creating upstream branch "mybranch"...
172
+ Creating remote branch "mybranch"...
168
173
  Creating PR...
169
174
  Assigning authenticated user...
170
175
  PR address: https://github.com/donaldduck/testrepo_f/pull/4
@@ -7,7 +7,7 @@ require_relative '../../lib/geet/services/merge_pr'
7
7
 
8
8
  # Currently disabled: it requires updates following the addition of the automatic removal of the local
9
9
  # branch.
10
- # Specifically, `GitClient#upstream_branch_gone?` needs to be handled, since it returns the current
10
+ # Specifically, `GitClient#remote_branch_gone?` needs to be handled, since it returns the current
11
11
  # branch, while it's supposed to return
12
12
  #
13
13
  describe Geet::Services::MergePr do
@@ -15,11 +15,12 @@ describe Geet::Services::MergePr do
15
15
  let(:repository) { Geet::Git::Repository.new(git_client: git_client) }
16
16
  let(:owner) { 'donaldduck' }
17
17
  let(:branch) { 'mybranch' }
18
+ let(:main_branch) { 'main' }
18
19
 
19
20
  before :each do
20
21
  expect(git_client).to receive(:fetch)
21
- expect(git_client).to receive(:upstream_branch_gone?).and_return(true)
22
- expect(git_client).to receive(:checkout).with('master')
22
+ expect(git_client).to receive(:remote_branch_gone?).and_return(true)
23
+ expect(git_client).to receive(:checkout).with(main_branch)
23
24
  expect(git_client).to receive(:rebase)
24
25
  expect(git_client).to receive(:delete_branch).with('mybranch')
25
26
  end
@@ -29,6 +30,7 @@ describe Geet::Services::MergePr do
29
30
 
30
31
  it 'should merge the PR for the current branch' do
31
32
  allow(git_client).to receive(:current_branch).and_return(branch)
33
+ allow(git_client).to receive(:main_branch).and_return(main_branch)
32
34
  allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:#{owner}/#{repository_name}")
33
35
 
34
36
  expected_pr_number = 1
@@ -36,7 +38,7 @@ describe Geet::Services::MergePr do
36
38
  Finding PR with head (#{owner}:#{branch})...
37
39
  Merging PR ##{expected_pr_number}...
38
40
  Fetching repository...
39
- Checking out master...
41
+ Checking out #{main_branch}...
40
42
  Rebasing...
41
43
  Deleting local branch mybranch...
42
44
  STR
@@ -55,6 +57,7 @@ describe Geet::Services::MergePr do
55
57
 
56
58
  it 'should merge the PR for the current branch, with branch deletion' do
57
59
  allow(git_client).to receive(:current_branch).and_return(branch)
60
+ allow(git_client).to receive(:main_branch).and_return(main_branch)
58
61
  allow(git_client).to receive(:remote).with(no_args).and_return("git@github.com:#{owner}/#{repository_name}")
59
62
 
60
63
  expected_pr_number = 2
@@ -63,7 +66,7 @@ describe Geet::Services::MergePr do
63
66
  Merging PR ##{expected_pr_number}...
64
67
  Deleting remote branch #{branch}...
65
68
  Fetching repository...
66
- Checking out master...
69
+ Checking out #{main_branch}...
67
70
  Rebasing...
68
71
  Deleting local branch mybranch...
69
72
  STR
@@ -86,6 +89,7 @@ describe Geet::Services::MergePr do
86
89
 
87
90
  it 'should merge the PR for the current branch' do
88
91
  allow(git_client).to receive(:current_branch).and_return(branch)
92
+ allow(git_client).to receive(:main_branch).and_return(main_branch)
89
93
  allow(git_client).to receive(:remote).with(no_args).and_return("git@gitlab.com:#{owner}/#{repository_name}")
90
94
 
91
95
  expected_pr_number = 4
@@ -93,7 +97,7 @@ describe Geet::Services::MergePr do
93
97
  Finding PR with head (#{owner}:#{branch})...
94
98
  Merging PR ##{expected_pr_number}...
95
99
  Fetching repository...
96
- Checking out master...
100
+ Checking out #{main_branch}...
97
101
  Rebasing...
98
102
  Deleting local branch mybranch...
99
103
  STR
@@ -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
@@ -686,7 +686,7 @@ http_interactions:
686
686
  uri: https://api.github.com/repos/donaldduck/testrepo_f/pulls
687
687
  body:
688
688
  encoding: UTF-8
689
- string: '{"title":"Title","body":"Description","head":"mybranch","base":"master"}'
689
+ string: '{"title":"Title","body":"Description","head":"mybranch","base":"master","draft":false}'
690
690
  headers:
691
691
  Accept-Encoding:
692
692
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
@@ -381,7 +381,7 @@ http_interactions:
381
381
  uri: https://api.github.com/repos/donaldduck/testrepo_f/pulls
382
382
  body:
383
383
  encoding: UTF-8
384
- string: '{"title":"Title","body":"Description","head":"mybranch","base":"master"}'
384
+ string: '{"title":"Title","body":"Description","head":"mybranch","base":"master","draft":false}'
385
385
  headers:
386
386
  Accept-Encoding:
387
387
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
@@ -381,7 +381,7 @@ http_interactions:
381
381
  uri: https://api.github.com/repos/donaldduck/testrepo_f/pulls
382
382
  body:
383
383
  encoding: UTF-8
384
- string: '{"title":"Title","body":"Description","head":"mybranch","base":"master"}'
384
+ string: '{"title":"Title","body":"Description","head":"mybranch","base":"master","draft":false}'
385
385
  headers:
386
386
  Accept-Encoding:
387
387
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
@@ -459,7 +459,7 @@ http_interactions:
459
459
  uri: https://api.github.com/repos/donald-fr/testrepo_u/pulls
460
460
  body:
461
461
  encoding: UTF-8
462
- string: '{"title":"Title","body":"Description","head":"donaldduck:mybranch","base":"master"}'
462
+ string: '{"title":"Title","body":"Description","head":"donaldduck:mybranch","base":"master","draft":false}'
463
463
  headers:
464
464
  Accept-Encoding:
465
465
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
@@ -230,7 +230,7 @@ http_interactions:
230
230
  uri: https://api.github.com/repos/donald-fr/testrepo_u/pulls
231
231
  body:
232
232
  encoding: UTF-8
233
- string: '{"title":"Title","body":"Description","head":"donaldduck:mybranch","base":"master"}'
233
+ string: '{"title":"Title","body":"Description","head":"donaldduck:mybranch","base":"master","draft":false}'
234
234
  headers:
235
235
  Accept-Encoding:
236
236
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.18
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saverio Miroddi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-28 00:00:00.000000000 Z
11
+ date: 2021-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_scripting
@@ -117,7 +117,6 @@ files:
117
117
  - lib/geet/services/merge_pr.rb
118
118
  - lib/geet/services/open_pr.rb
119
119
  - lib/geet/services/open_repo.rb
120
- - lib/geet/shared/branches.rb
121
120
  - lib/geet/shared/http_error.rb
122
121
  - lib/geet/shared/repo_permissions.rb
123
122
  - lib/geet/shared/selection.rb
@@ -191,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
190
  - !ruby/object:Gem::Version
192
191
  version: '0'
193
192
  requirements: []
194
- rubygems_version: 3.2.3
193
+ rubygems_version: 3.1.6
195
194
  signing_key:
196
195
  specification_version: 4
197
196
  summary: Commandline interface for performing SCM host operations, eg. create a PR
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Geet
4
- module Shared
5
- module Branches
6
- MAIN_BRANCH = 'master'
7
- end
8
- end
9
- end