@@ -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
0 commit comments