foobara-empty-ruby-project-generator 0.0.7 → 0.0.8

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: 817e478ef05f69c023c000f12699acfe791c14974f90c5ed1fe6175814efc442
4
- data.tar.gz: 56fc1d66521dbdc6375351ac74a8066edd89a1b7f168a94db43ae894598097c3
3
+ metadata.gz: b46cc5ab7c3af85b233e1f3d6ed50d28d9dd979efe491466cf35827a91af698b
4
+ data.tar.gz: ac13fa15cc0b6e929b5e4ddc1b2d63219b9f548cef73d6f3abd295003ad12069
5
5
  SHA512:
6
- metadata.gz: c7c79553ba8bc9febc227d7f5e39b8cb690493f2a456f6b378e51ff90bd76c0a4fdbe85b04b350442e38288e4fa762213e8afa78da630dfb80c3c33552031c36
7
- data.tar.gz: 8b4281a99bf28c9bcc1bda5832f706373618fec52feb2bae7d56acd829aeedb1ec38556aff172f0f26591d90cddf29fce00a7eb5561bd8c70046ce4ad25a1025
6
+ metadata.gz: 2f431725b00d3f7d5c33fc644f977a63c3161634521b34d2ee88515264728a402426bef68455d65e0cdc23e9fd4568ad51ebac45f39269c3af3ec6dca72993b8
7
+ data.tar.gz: 269d8f29c559ee0444d7319f1e8719673eb33d6baafcefe2ccfcbf01ecc4cd10aba3be15d16678db3db6cc0b25454585f39edea32a19b6792d597cc166a74940
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.8] - 2024-11-07
2
+
3
+ - Add ability to extract code and git history from one repository into the new project
4
+
1
5
  ## [0.0.7] - 2024-11-01
2
6
 
3
7
  - Do not automatically push to github via gh
@@ -0,0 +1,13 @@
1
+ module Foobara
2
+ module Generators
3
+ module EmptyRubyProjectGenerator
4
+ class ExtractInputs < Foobara::Model
5
+ attributes do
6
+ repo :string, :required
7
+ paths [:string], :required
8
+ delete_extracted :boolean, default: false
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,4 +1,5 @@
1
1
  require_relative "generate_empty_ruby_project"
2
+ require "extract_repo"
2
3
 
3
4
  module Foobara
4
5
  module Generators
@@ -10,15 +11,21 @@ module Foobara
10
11
  end
11
12
  end
12
13
 
13
- depends_on GenerateEmptyRubyProject
14
+ depends_on GenerateEmptyRubyProject,
15
+ ::ExtractRepo
14
16
 
15
17
  inputs do
18
+ extract ExtractInputs
16
19
  project_config ProjectConfig, :required
17
20
  # TODO: should be able to delete this and inherit it
18
21
  output_directory :string
19
22
  end
20
23
 
21
24
  def execute
25
+ create_output_directory_if_needed
26
+ if extract_from_another_repo?
27
+ extract_from_another_repo
28
+ end
22
29
  generate_file_contents
23
30
  write_all_files_to_disk
24
31
  run_post_generation_tasks
@@ -26,6 +33,24 @@ module Foobara
26
33
  output
27
34
  end
28
35
 
36
+ def create_output_directory_if_needed
37
+ FileUtils.mkdir_p output_directory
38
+ end
39
+
40
+ def extract_from_another_repo?
41
+ !!extract
42
+ end
43
+
44
+ def extract_from_another_repo
45
+ run_subcommand!(
46
+ ExtractRepo,
47
+ repo_url: extract.repo,
48
+ paths: extract.paths,
49
+ delete_extracted: extract.delete_extracted,
50
+ output_path: output_directory
51
+ )
52
+ end
53
+
29
54
  def output_directory
30
55
  inputs[:output_directory] || default_output_directory
31
56
  end
@@ -45,7 +70,7 @@ module Foobara
45
70
  bundle_install
46
71
  make_bin_files_executable
47
72
  rubocop_autocorrect
48
- git_init
73
+ git_init unless extract_from_another_repo?
49
74
  git_add_all
50
75
  git_commit
51
76
  github_create_repo
@@ -112,17 +137,22 @@ module Foobara
112
137
  end
113
138
 
114
139
  def git_add_all
115
- unless system("git add .")
116
- # :nocov:
117
- raise "could not git add ."
118
- # :nocov:
140
+ cmd = "git add ."
141
+
142
+ Open3.popen3(cmd) do |_stdin, _stdout, stderr, wait_thr|
143
+ exit_status = wait_thr.value
144
+ unless exit_status.success?
145
+ # :nocov:
146
+ raise "could not #{cmd}\n#{stderr.read}"
147
+ # :nocov:
148
+ end
119
149
  end
120
150
  end
121
151
 
122
152
  def git_commit
123
153
  # TODO: set author/name with git config in CI so we don't have to skip this
124
154
  # :nocov:
125
- Open3.popen3("git commit -m 'Initial commit'") do |_stdin, stdout, stderr, wait_thr|
155
+ Open3.popen3("git commit -m 'Create ruby project files'") do |_stdin, stdout, stderr, wait_thr|
126
156
  exit_status = wait_thr.value
127
157
  unless exit_status.success?
128
158
  raise "could not git commit -m 'Initial commit'. OUTPUT\n#{stdout.read}\nERROR:#{stderr.read}"
@@ -136,7 +166,7 @@ module Foobara
136
166
  def github_create_repo
137
167
  puts "pushing to github..."
138
168
 
139
- cmd = "gh repo create --public --source=. #{project_config.org_slash_project_kebab}"
169
+ cmd = "gh repo create --public #{project_config.org_slash_project_kebab}"
140
170
 
141
171
  Open3.popen3(cmd) do |_stdin, _stdout, _stderr, wait_thr|
142
172
  exit_status = wait_thr.value
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-empty-ruby-project-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-01 00:00:00.000000000 Z
11
+ date: 2024-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: extract-repo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: foobara
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -64,6 +78,7 @@ files:
64
78
  - src/generators/project_generator.rb
65
79
  - src/generators/version_generator.rb
66
80
  - src/manifests/project_config.rb
81
+ - src/types/extract_inputs.rb
67
82
  - src/write_empty_ruby_project_to_disk.rb
68
83
  - templates/.bundle/config
69
84
  - templates/.github/workflows/ci.yml.erb
@@ -116,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
131
  - !ruby/object:Gem::Version
117
132
  version: '0'
118
133
  requirements: []
119
- rubygems_version: 3.5.22
134
+ rubygems_version: 3.5.23
120
135
  signing_key:
121
136
  specification_version: 4
122
137
  summary: Generates empty ruby project boilerplate code from a template