geet 0.8.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/services/create_pr.rb +29 -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 +26 -25
- 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
|
|
@@ -1,5 +1,7 @@
|
|
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'
|
@@ -86,10 +88,36 @@ module Geet
|
|
86
88
|
end
|
87
89
|
|
88
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
|
+
|
89
95
|
if @git_client.remote_branch
|
90
96
|
@out.puts "Pushing to remote branch..."
|
91
97
|
|
92
|
-
@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
|
93
121
|
else
|
94
122
|
remote_branch = @git_client.current_branch
|
95
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
@@ -130,31 +130,32 @@ describe Geet::Services::CreatePr do
|
|
130
130
|
expect(actual_output.string).to be_empty
|
131
131
|
end
|
132
132
|
|
133
|
-
it 'should push to the remote branch'
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
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
|
158
159
|
|
159
160
|
it "should create a remote branch, when there isn't one (is not tracked)" do
|
160
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
|