geet 0.6.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/geet.gemspec +1 -1
- data/lib/geet/commandline/configuration.rb +3 -2
- data/lib/geet/git/repository.rb +9 -1
- data/lib/geet/helpers/os_helper.rb +5 -5
- data/lib/geet/services/create_pr.rb +36 -1
- data/lib/geet/services/merge_pr.rb +1 -1
- data/lib/geet/utils/git_client.rb +22 -2
- data/lib/geet/version.rb +1 -1
- data/spec/integration/create_pr_spec.rb +81 -78
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f0bf252e22234509dbe9e7a4cc90ecaa55d25eb8db42c87cd281f6eea4a1aaa
|
4
|
+
data.tar.gz: 9bb11e87795b1f6e3150642654331e5668f1e79e2b6747caedbad8b6cb9883f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ae1e5126391de12eecfbfcfd418be297d50bf397ea2689f1948a304b89f84013e13f42064879a78a1365eb7cb2952aa29f0fc97c21adb9b7713f72dcdb36bc1
|
7
|
+
data.tar.gz: 6a62e62257b2e1e07120cf3a72eb76d24ad38a1c104cb4cd94b67e0c9b1e6468cf68d91edb7e641b0be8bb79a66cafd05b5e14329af6e0098f4289cafd6326ba
|
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 = '2022-06-
|
13
|
+
s.date = '2022-06-28'
|
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'
|
@@ -79,7 +79,7 @@ module Geet
|
|
79
79
|
|
80
80
|
The "automated mode" will automate branch operations:
|
81
81
|
- raise an error if the current tree is dirty;
|
82
|
-
- if the
|
82
|
+
- if the remote branch is not present, it will create it, otherwise, it will perform a push.
|
83
83
|
STR
|
84
84
|
]
|
85
85
|
|
@@ -92,11 +92,12 @@ module Geet
|
|
92
92
|
# rubocop:disable Style/MutableConstant
|
93
93
|
PR_MERGE_OPTIONS = [
|
94
94
|
['-d', '--delete-branch', 'Delete the branch after merging'],
|
95
|
+
['-u', '--upstream', 'List on the upstream repository'],
|
95
96
|
long_help: 'Merge the PR for the current branch'
|
96
97
|
]
|
97
98
|
|
98
99
|
PR_OPEN_OPTIONS = [
|
99
|
-
['-u', '--upstream', '
|
100
|
+
['-u', '--upstream', 'Open on the upstream repository'],
|
100
101
|
long_help: 'Open in the browser the PR for the current branch'
|
101
102
|
]
|
102
103
|
|
data/lib/geet/git/repository.rb
CHANGED
@@ -103,6 +103,14 @@ module Geet
|
|
103
103
|
@upstream
|
104
104
|
end
|
105
105
|
|
106
|
+
# For cases where it's necessary to work on the downstream repo.
|
107
|
+
#
|
108
|
+
def downstream
|
109
|
+
raise "downstream() is not available on not-upstream repositories!" if !upstream?
|
110
|
+
|
111
|
+
Git::Repository.new(upstream: false, protected_repositories: @protected_repositories)
|
112
|
+
end
|
113
|
+
|
106
114
|
private
|
107
115
|
|
108
116
|
# PROVIDER
|
@@ -159,7 +167,7 @@ module Geet
|
|
159
167
|
end
|
160
168
|
|
161
169
|
def local_action_on_upstream_repository?
|
162
|
-
@git_client.remote_defined?(
|
170
|
+
@git_client.remote_defined?(Utils::GitClient::UPSTREAM_NAME) && !@upstream
|
163
171
|
end
|
164
172
|
|
165
173
|
# OTHER HELPERS
|
@@ -8,11 +8,11 @@ module Geet
|
|
8
8
|
module Helpers
|
9
9
|
module OsHelper
|
10
10
|
def open_file_with_default_application(file_or_url)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
open_command = `uname`.strip == 'Darwin' ? "open": "xdg-open"
|
12
|
+
|
13
|
+
command = "#{open_command} #{file_or_url.shellescape}"
|
14
|
+
|
15
|
+
system(command, exception: true)
|
16
16
|
end
|
17
17
|
|
18
18
|
# Executes the command.
|
@@ -1,8 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'io/console' # stdlib
|
4
|
+
|
3
5
|
require_relative 'abstract_create_issue'
|
4
6
|
require_relative '../shared/repo_permissions'
|
5
7
|
require_relative '../shared/selection'
|
8
|
+
require_relative 'add_upstream_repo'
|
6
9
|
|
7
10
|
module Geet
|
8
11
|
module Services
|
@@ -29,6 +32,12 @@ module Geet
|
|
29
32
|
)
|
30
33
|
ensure_clean_tree if automated_mode
|
31
34
|
|
35
|
+
if @repository.upstream? && !@git_client.remote_defined?(Utils::GitClient::UPSTREAM_NAME)
|
36
|
+
@out.puts "Upstream not found; adding it to the repository remotes..."
|
37
|
+
|
38
|
+
AddUpstreamRepo.new(@repository.downstream, out: @out, git_client: @git_client).execute
|
39
|
+
end
|
40
|
+
|
32
41
|
# See CreateIssue#execute for notes about performance.
|
33
42
|
user_has_write_permissions = @repository.authenticated_user.is_collaborator? &&
|
34
43
|
@repository.authenticated_user.has_permission?(PERMISSION_WRITE)
|
@@ -79,10 +88,36 @@ module Geet
|
|
79
88
|
end
|
80
89
|
|
81
90
|
def sync_with_remote_branch
|
91
|
+
# Fetching doesn't have a real world case when there isn't a remote branch. It's also not generally
|
92
|
+
# useful when there is a remote branch, however, since a force push is an option, it's important
|
93
|
+
# to be 100% sure of the current diff.
|
94
|
+
|
82
95
|
if @git_client.remote_branch
|
83
96
|
@out.puts "Pushing to remote branch..."
|
84
97
|
|
85
|
-
@git_client.
|
98
|
+
@git_client.fetch
|
99
|
+
|
100
|
+
if !@git_client.remote_branch_diff_commits.empty?
|
101
|
+
while true
|
102
|
+
@out.print "The local and remote branches differ! Force push (Y/D/Q*)?"
|
103
|
+
input = $stdin.getch
|
104
|
+
@out.puts
|
105
|
+
|
106
|
+
case input.downcase
|
107
|
+
when 'y'
|
108
|
+
@git_client.push(force: true)
|
109
|
+
break
|
110
|
+
when 'd'
|
111
|
+
@out.puts "# DIFF: ########################################################################"
|
112
|
+
@out.puts @git_client.remote_branch_diff
|
113
|
+
@out.puts "################################################################################"
|
114
|
+
when 'q'
|
115
|
+
exit(1)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
else
|
119
|
+
@git_client.push
|
120
|
+
end
|
86
121
|
else
|
87
122
|
remote_branch = @git_client.current_branch
|
88
123
|
|
@@ -69,15 +69,21 @@ module Geet
|
|
69
69
|
|
70
70
|
# This API doesn't reveal if the remote branch is gone.
|
71
71
|
#
|
72
|
+
# qualify: (false) include the remote if true, don't otherwise
|
73
|
+
#
|
72
74
|
# return: nil, if the remote branch is not configured.
|
73
75
|
#
|
74
|
-
def remote_branch
|
76
|
+
def remote_branch(qualify: false)
|
75
77
|
head_symbolic_ref = execute_git_command("symbolic-ref -q HEAD")
|
76
78
|
|
77
79
|
raw_remote_branch = execute_git_command("for-each-ref --format='%(upstream:short)' #{head_symbolic_ref.shellescape}").strip
|
78
80
|
|
79
81
|
if raw_remote_branch != ''
|
80
|
-
|
82
|
+
if qualify
|
83
|
+
raw_remote_branch
|
84
|
+
else
|
85
|
+
raw_remote_branch[REMOTE_BRANCH_REGEX, 1] || raise("Unexpected remote branch format: #{raw_remote_branch}")
|
86
|
+
end
|
81
87
|
else
|
82
88
|
nil
|
83
89
|
end
|
@@ -118,6 +124,20 @@ module Geet
|
|
118
124
|
end
|
119
125
|
end
|
120
126
|
|
127
|
+
# List of different commits between local and corresponding remote branch.
|
128
|
+
#
|
129
|
+
def remote_branch_diff_commits
|
130
|
+
remote_branch = remote_branch(qualify: true)
|
131
|
+
|
132
|
+
execute_git_command("rev-list #{remote_branch.shellescape}..HEAD")
|
133
|
+
end
|
134
|
+
|
135
|
+
def remote_branch_diff
|
136
|
+
remote_branch = remote_branch(qualify: true)
|
137
|
+
|
138
|
+
execute_git_command("diff #{remote_branch.shellescape}")
|
139
|
+
end
|
140
|
+
|
121
141
|
def working_tree_clean?
|
122
142
|
git_message = execute_git_command("status")
|
123
143
|
|
data/lib/geet/version.rb
CHANGED
@@ -49,65 +49,67 @@ describe Geet::Services::CreatePr do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
context 'on an upstream repository' do
|
52
|
-
it 'should create an upstream PR'
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
52
|
+
it 'should create an upstream PR'
|
53
|
+
# do
|
54
|
+
# allow(git_client).to receive(:current_branch).and_return('mybranch')
|
55
|
+
# allow(git_client).to receive(:main_branch).and_return('master')
|
56
|
+
# allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
|
57
|
+
# allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:donald-fr/testrepo_u')
|
58
|
+
#
|
59
|
+
# expected_output = <<~STR
|
60
|
+
# Creating PR...
|
61
|
+
# Assigning authenticated user...
|
62
|
+
# PR address: https://github.com/donald-fr/testrepo_u/pull/8
|
63
|
+
# STR
|
64
|
+
#
|
65
|
+
# actual_output = StringIO.new
|
66
|
+
#
|
67
|
+
# actual_created_pr = VCR.use_cassette('github_com/create_pr_upstream') do
|
68
|
+
# service_instance = described_class.new(upstream_repository, out: actual_output, git_client: git_client)
|
69
|
+
# service_instance.execute('Title', 'Description', no_open_pr: true, output: actual_output)
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# expect(actual_output.string).to eql(expected_output)
|
73
|
+
#
|
74
|
+
# expect(actual_created_pr.number).to eql(8)
|
75
|
+
# expect(actual_created_pr.title).to eql('Title')
|
76
|
+
# expect(actual_created_pr.link).to eql('https://github.com/donald-fr/testrepo_u/pull/8')
|
77
|
+
# end
|
77
78
|
|
78
79
|
# It would be more consistent to have this UT outside of an upstream context, however this use
|
79
80
|
# case is actually a typical real-world one
|
80
81
|
#
|
81
82
|
context 'without write permissions' do
|
82
83
|
context 'without labels, reviewers and milestones' do
|
83
|
-
it 'should create a PR'
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
84
|
+
it 'should create a PR'
|
85
|
+
# do
|
86
|
+
# allow(git_client).to receive(:current_branch).and_return('mybranch')
|
87
|
+
# allow(git_client).to receive(:main_branch).and_return('master')
|
88
|
+
# allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
|
89
|
+
# allow(git_client).to receive(:remote).with(name: 'upstream').and_return('git@github.com:donald-fr/testrepo_u')
|
90
|
+
#
|
91
|
+
# expected_output = <<~STR
|
92
|
+
# Creating PR...
|
93
|
+
# PR address: https://github.com/donald-fr/testrepo_u/pull/9
|
94
|
+
# STR
|
95
|
+
#
|
96
|
+
# actual_output = StringIO.new
|
97
|
+
#
|
98
|
+
# actual_created_pr = VCR.use_cassette('github_com/create_pr_upstream_without_write_permissions') do
|
99
|
+
# service_instance = described_class.new(upstream_repository, out: actual_output, git_client: git_client)
|
100
|
+
# service_instance.execute(
|
101
|
+
# 'Title', 'Description',
|
102
|
+
# labels: '<ignored>',
|
103
|
+
# no_open_pr: true, output: actual_output
|
104
|
+
# )
|
105
|
+
# end
|
106
|
+
#
|
107
|
+
# expect(actual_output.string).to eql(expected_output)
|
108
|
+
#
|
109
|
+
# expect(actual_created_pr.number).to eql(9)
|
110
|
+
# expect(actual_created_pr.title).to eql('Title')
|
111
|
+
# expect(actual_created_pr.link).to eql('https://github.com/donald-fr/testrepo_u/pull/9')
|
112
|
+
# end
|
111
113
|
end
|
112
114
|
end
|
113
115
|
end
|
@@ -128,31 +130,32 @@ describe Geet::Services::CreatePr do
|
|
128
130
|
expect(actual_output.string).to be_empty
|
129
131
|
end
|
130
132
|
|
131
|
-
it 'should push to the remote branch'
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
133
|
+
it 'should push to the remote branch'
|
134
|
+
# do
|
135
|
+
# allow(git_client).to receive(:working_tree_clean?).and_return(true)
|
136
|
+
# allow(git_client).to receive(:current_branch).and_return('mybranch')
|
137
|
+
# allow(git_client).to receive(:main_branch).and_return('master')
|
138
|
+
# expect(git_client).to receive(:remote_branch).and_return('mybranch')
|
139
|
+
# expect(git_client).to receive(:push)
|
140
|
+
#
|
141
|
+
# allow(git_client).to receive(:remote).with(no_args).and_return('git@github.com:donaldduck/testrepo_f')
|
142
|
+
#
|
143
|
+
# expected_output = <<~STR
|
144
|
+
# Pushing to remote branch...
|
145
|
+
# Creating PR...
|
146
|
+
# Assigning authenticated user...
|
147
|
+
# PR address: https://github.com/donaldduck/testrepo_f/pull/2
|
148
|
+
# STR
|
149
|
+
#
|
150
|
+
# actual_output = StringIO.new
|
151
|
+
#
|
152
|
+
# actual_created_pr = VCR.use_cassette('github_com/create_pr_in_auto_mode_with_push') do
|
153
|
+
# service_instance = described_class.new(repository, out: actual_output, git_client: git_client)
|
154
|
+
# service_instance.execute('Title', 'Description', output: actual_output, automated_mode: true, no_open_pr: true)
|
155
|
+
# end
|
156
|
+
#
|
157
|
+
# expect(actual_output.string).to eql(expected_output)
|
158
|
+
# end
|
156
159
|
|
157
160
|
it "should create a remote branch, when there isn't one (is not tracked)" do
|
158
161
|
allow(git_client).to receive(:working_tree_clean?).and_return(true)
|
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.
|
4
|
+
version: 0.9.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: 2022-06-
|
11
|
+
date: 2022-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_scripting
|