Skip to content

Commit b4b520a

Browse files
committed
Make pushing to github optional
1 parent 40ffe80 commit b4b520a

File tree

7 files changed

+59
-13
lines changed

7 files changed

+59
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.0.6] - 2025-05-03
2+
3+
- Make pushing to github off by default and make failures not stop the generator
4+
15
## [0.0.5] - 2025-05-03
26

37
- Create github repositories as private instead of public

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
foobara-empty-typescript-react-project-generator (0.0.5)
4+
foobara-empty-typescript-react-project-generator (0.0.6)
55
foobara (~> 0.0.116)
66
foobara-files-generator (~> 0.0.1)
77

@@ -20,10 +20,10 @@ GEM
2020
foobara-lru-cache (~> 0.0.2)
2121
foobara-util (~> 0.0.11)
2222
inheritable-thread-vars (~> 0.0.1)
23-
foobara-files-generator (0.0.6)
23+
foobara-files-generator (0.0.7)
2424
foobara (~> 0.0.116)
2525
foobara-lru-cache (0.0.2)
26-
foobara-rubocop-rules (0.0.8)
26+
foobara-rubocop-rules (0.0.9)
2727
rubocop
2828
rubocop-rspec
2929
foobara-spec-helpers (0.0.4)

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ require "rubocop/rake_task"
77

88
RuboCop::RakeTask.new
99

10-
task default: %i[spec rubocop]
10+
task default: [:spec, :rubocop]

spec/foobara/generators/write_empty_typescript_react_project_to_disk_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@
1111
end
1212
let(:empty_typescript_react_project_config) do
1313
{
14-
project_dir:
14+
project_dir:,
15+
push_to_github: true
1516
}
1617
end
1718
let(:project_dir) { "test-project" }
1819
let(:output_directory) { "#{__dir__}/../../../tmp/rspec-output" }
1920

2021
before do
21-
allow(command).to receive_messages(git_commit: nil, rubocop_autocorrect: nil)
22+
# rubocop:disable RSpec/AnyInstance
23+
# Stubbing these to let more lines of the code be hit by the test suite
24+
allow_any_instance_of(described_class).to receive(:push_to_github_failed).and_return(nil)
25+
# rubocop:enable RSpec/AnyInstance
26+
2227
FileUtils.rm_rf output_directory
2328
end
2429

src/empty_typescript_react_project_config.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class EmptyTypescriptReactProjectConfig < Foobara::Model
77
attributes do
88
project_dir :string, :required
99
github_organization :string
10+
push_to_github :boolean, default: false
1011
end
1112
end
1213
end

src/write_empty_typescript_react_project_to_disk.rb

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def project_directory
4444
Pathname.new(path).realpath.to_s
4545
end
4646

47+
def push_to_github?
48+
empty_typescript_react_project_config.push_to_github
49+
end
50+
4751
def generate_file_contents
4852
self.paths_to_source_code = run_subcommand!(GenerateEmptyTypescriptReactProject,
4953
empty_typescript_react_project_config.attributes)
@@ -91,10 +95,13 @@ def run_post_generation_tasks
9195
eslint_fix
9296
git_add_all
9397
git_commit_generated_files
94-
gh_repo_create
95-
git_add_remote_origin
9698
git_branch_main
97-
push_to_github
99+
100+
if push_to_github?
101+
gh_repo_create
102+
git_add_remote_origin
103+
push_to_github
104+
end
98105
end
99106

100107
def fix_uncorrectable_lint_violations
@@ -152,25 +159,50 @@ def git_repo_path
152159
"#{org}/#{empty_typescript_react_project_config.project_dir}"
153160
end
154161

162+
attr_accessor :push_to_github_failed
163+
164+
def push_to_github_failed?
165+
push_to_github_failed
166+
end
167+
155168
def gh_repo_create
169+
return if push_to_github_failed?
170+
156171
cmd = "gh repo create --private --push --source=. #{git_repo_path}"
157172

158173
Dir.chdir project_directory do
159-
run_cmd_and_write_output(cmd, raise_if_fails: false)
174+
exit_status = run_cmd_and_write_output(cmd, raise_if_fails: false)
175+
176+
unless exit_status&.success?
177+
self.push_to_github_failed = true
178+
end
160179
end
161180
end
162181

163182
def git_add_remote_origin
183+
return if push_to_github_failed?
184+
164185
git_remote_cmd = "git remote"
165186
git_remote_add_cmd = "git remote add origin git@github.com:#{git_repo_path}.git"
166187

167188
Dir.chdir project_directory do
168189
remotes = run_cmd_and_return_output(git_remote_cmd)
169190

170191
if remotes !~ /^origin$/
171-
run_cmd_and_write_output(git_remote_add_cmd)
192+
exit_status = run_cmd_and_write_output(git_remote_add_cmd)
193+
194+
unless exit_status&.success?
195+
# :nocov:
196+
self.push_to_github_failed = true
197+
# :nocov:
198+
end
172199
end
173200
end
201+
rescue CouldNotExecuteError => e
202+
# :nocov:
203+
self.push_to_github_failed = true
204+
warn e.message
205+
# :nocov:
174206
end
175207

176208
def git_branch_main
@@ -185,7 +217,11 @@ def push_to_github
185217
cmd = "git push -u origin main"
186218

187219
Dir.chdir project_directory do
188-
run_cmd_and_write_output(cmd, raise_if_fails: false)
220+
exit_status = run_cmd_and_write_output(cmd, raise_if_fails: false)
221+
222+
unless exit_status&.success?
223+
self.push_to_github_failed = true
224+
end
189225
end
190226
end
191227
end

version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Foobara
22
module Generators
33
module EmptyTypescriptReactProjectGenerator
4-
VERSION = "0.0.5".freeze
4+
VERSION = "0.0.6".freeze
55

66
local_ruby_version = File.read("#{__dir__}/.ruby-version").chomp
77
local_ruby_version_minor = local_ruby_version[/\A(\d+\.\d+)\.\d+\z/, 1]

0 commit comments

Comments
 (0)