geet 0.3.18 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b37d7ac48684dcd431b13c0e00cb9f999764ae714dec3c8d046102469f7f62f
4
- data.tar.gz: 43a045941aff66c212314ae0de2c5c439434c75e89240ce2c59750f5759dcc5a
3
+ metadata.gz: b2329057378f97cc59535b5821aeeca1f527bca27bd4ced6bb3250e46a55042c
4
+ data.tar.gz: 680b9175785b58deac3d5df918b2b843168ac709aea396168bd35091b6b7810b
5
5
  SHA512:
6
- metadata.gz: fe4aa67774fef6b5943ae4f6eb2950ec4d4c2b7f004aa963438e00904d80d01c3a73db8671567c718b6fc9b235a2e9d2002744ec891bce3ff4af1144ffa01d28
7
- data.tar.gz: 14c3efa61fa206f3f3f70432c3683d394f9e4e4e09f6cefad757d96d11b88110559f393d22d296acef963d72d7117c668125724da79d8f1f6cbda9e35dfc367a
6
+ metadata.gz: 9dbb35ae368c401562677fa3a84138b53e1f15d4741802b478dca6cc166e65c451bf892316dcc9c32add3ca503d031a53d7964ffcc8910713fd2255f4b7c0220
7
+ data.tar.gz: ecba5a04fd823553108c83bc1e7a182d81d3a3e08d8e875584213e05f966153419fd30a4237f63126a419bcb8ce1007a1ad55e093ff24ea7d1f038ca3ad9c0cf
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-06-08'
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,7 @@ 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
71
  ['-l', '--labels "legacy,code review"', 'Labels'],
72
72
  ['-m', '--milestone 1.5.0', 'Milestone title pattern'],
73
73
  ['-r', '--reviewers john,tom,adrian,kevin', 'Reviewer logins'],
@@ -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)
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)
82
82
  end
83
83
 
84
84
  def prs(owner: nil, head: nil, milestone: nil)
@@ -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,9 +8,8 @@ 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)
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
@@ -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
@@ -39,7 +39,7 @@ module Geet
39
39
 
40
40
  sync_with_upstream_branch if automated_mode
41
41
 
42
- pr = create_pr(title, description, base)
42
+ pr = create_pr(title, description, base: base)
43
43
 
44
44
  if user_has_write_permissions
45
45
  edit_pr(pr, selected_labels, selected_milestone, selected_reviewers)
@@ -95,10 +95,12 @@ module Geet
95
95
  end
96
96
  end
97
97
 
98
- def create_pr(title, description, base)
98
+ def create_pr(title, description, base: nil)
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)
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
 
@@ -39,11 +38,12 @@ module Geet
39
38
 
40
39
  if upstream_branch_gone?
41
40
  pr_branch = @git_client.current_branch
41
+ main_branch = @git_client.main_branch
42
42
 
43
43
  # The rebase could also be placed after the branch deletion. There are pros/cons;
44
44
  # currently, it's not important.
45
45
  #
46
- checkout_branch(MAIN_BRANCH)
46
+ checkout_branch(main_branch)
47
47
  rebase
48
48
 
49
49
  delete_local_branch(pr_branch)
@@ -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.
@@ -35,6 +36,8 @@ module Geet
35
36
 
36
37
  UPSTREAM_BRANCH_REGEX = %r{\A[^/]+/([^/]+)\Z}
37
38
 
39
+ MAIN_BRANCH_CONFIG_ENTRY = 'custom.development-branch'
40
+
38
41
  CLEAN_TREE_MESSAGE_REGEX = /^nothing to commit, working tree clean$/
39
42
 
40
43
  def initialize(location: nil)
@@ -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
 
@@ -203,7 +219,7 @@ module Geet
203
219
  # upstream_branch: create an upstream branch.
204
220
  #
205
221
  def push(upstream_branch: nil)
206
- upstream_branch_option = "-u origin #{upstream_branch.shellescape}" if upstream_branch
222
+ upstream_branch_option = "-u #{ORIGIN_NAME} #{upstream_branch.shellescape}" if upstream_branch
207
223
 
208
224
  execute_git_command("push #{upstream_branch_option}")
209
225
  end
@@ -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.0'
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
 
@@ -133,6 +136,7 @@ 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
 
@@ -158,6 +162,7 @@ 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
 
@@ -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
22
  expect(git_client).to receive(:upstream_branch_gone?).and_return(true)
22
- expect(git_client).to receive(:checkout).with('master')
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
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.0
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-06-08 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.2.19
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