Skip to content

Commit cef0945

Browse files
Replace todo files with README.md (#166)
* change add readme todo to add readme * create a directory rather than a public/TODO.md file * bump version * Update spec/packs_spec.rb Co-authored-by: Teal Stannard <[email protected]> Update spec/packs_spec.rb Co-authored-by: Teal Stannard <[email protected]> * fix tests --------- Co-authored-by: Teal Stannard <[email protected]>
1 parent 332b8f5 commit cef0945

File tree

5 files changed

+58
-72
lines changed

5 files changed

+58
-72
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ GIT
1717
PATH
1818
remote: .
1919
specs:
20-
packs (0.1.0)
20+
packs (0.2.0)
2121
bigdecimal
2222
code_ownership (>= 1.33.0)
2323
packs-specification

lib/packs/private.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def self.create_pack!(pack_name:, enforce_dependencies:, enforce_privacy:, enfor
6969
team: team
7070
)
7171
add_public_directory(package) if package.enforce_privacy
72-
add_readme_todo(package)
72+
add_readme(package)
7373

7474
Logging.section('Next steps') do
7575
next_steps = Packs.config.user_event_logger.after_create_pack(pack_name)
@@ -140,7 +140,7 @@ def self.move_to_pack!(pack_name:, paths_relative_to_root:, per_file_processors:
140140
end
141141
end
142142

143-
add_readme_todo(package)
143+
add_readme(package)
144144

145145
per_file_processors.each do |processor|
146146
processor.after_move_files!(file_move_operations)
@@ -446,18 +446,22 @@ def self.add_public_directory(package)
446446

447447
if public_directory.glob('**/**.rb').none?
448448
FileUtils.mkdir_p(public_directory)
449-
todo_md = Packs.config.user_event_logger.on_create_public_directory_todo(package.name)
450-
public_directory.join('TODO.md').write(todo_md)
449+
package_name = package.directory.basename.to_s
450+
FileUtils.mkdir_p(public_directory.join(package_name))
451451
end
452452
end
453453

454454
sig { params(package: ParsePackwerk::Package).void }
455-
def self.add_readme_todo(package)
455+
def self.add_readme(package)
456456
pack_directory = package.directory
457457

458458
if !pack_directory.join('README.md').exist?
459-
readme_todo_md = Packs.config.user_event_logger.on_create_readme_todo(package.name)
460-
pack_directory.join('README_TODO.md').write(readme_todo_md)
459+
readme_md = Packs.config.user_event_logger.on_create_readme(package.name)
460+
pack_directory.join('README.md').write(readme_md)
461+
462+
if pack_directory.join('README_TODO.md').exist?
463+
pack_directory.join('README_TODO.md').delete
464+
end
461465
end
462466
end
463467

lib/packs/user_event_logger.rb

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,30 +124,7 @@ def after_move_to_folder(pack_name)
124124
end
125125

126126
sig { params(pack_name: String).returns(String) }
127-
def on_create_public_directory_todo(pack_name)
128-
<<~MSG
129-
This directory holds your public API!
130-
131-
Any classes, constants, or modules that you want other packs to use and you intend to support should go in here.
132-
Anything that is considered private should go in other folders.
133-
134-
If another pack uses classes, constants, or modules that are not in your public folder, it will be considered a "privacy violation" by packwerk.
135-
You can prevent other packs from using private API by using packwerk.
136-
137-
Want to find how your private API is being used today?
138-
Try running: `bin/packs list_top_violations privacy #{pack_name}`
139-
140-
Want to move something into this folder?
141-
Try running: `bin/packs make_public #{pack_name}/path/to/file.rb`
142-
143-
One more thing -- feel free to delete this file and replace it with a README.md describing your package in the main package directory.
144-
145-
See #{documentation_link} for more info!
146-
MSG
147-
end
148-
149-
sig { params(pack_name: String).returns(String) }
150-
def on_create_readme_todo(pack_name)
127+
def on_create_readme(pack_name)
151128
readme_template_pathname = Packs.config.readme_template_pathname
152129
readme_template = readme_template_pathname.read if readme_template_pathname.exist?
153130

packs.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = 'packs'
3-
spec.version = '0.1.0'
3+
spec.version = '0.2.0'
44
spec.authors = ['Gusto Engineers']
55
spec.email = ['[email protected]']
66

spec/packs_spec.rb

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -256,21 +256,22 @@ def write_codeownership_config
256256
end
257257

258258
context 'app has no public dir' do
259-
it 'adds a TODO.md file letting someone know what to do with it' do
259+
it 'adds a public directory' do
260260
Packs.create_pack!(pack_name: 'packs/organisms')
261-
actual_todo = Pathname.new('packs/organisms/app/public/TODO.md').read
262-
expect(actual_todo).to eq expected_todo
261+
public_directory = Pathname.new('packs/organisms/app/public')
262+
expect(public_directory.exist?).to eq true
263+
expect(public_directory.join('organisms').exist?).to eq true
263264
end
264265

265266
context 'pack not enforcing privacy' do
266-
it 'does not add a TODO.md file' do
267+
it 'does not add a public directory' do
267268
Packs.create_pack!(pack_name: 'packs/organisms', enforce_privacy: false)
268269

269270
ParsePackwerk.bust_cache!
270271
package = ParsePackwerk.find('packs/organisms')
271272
expect(package.enforce_privacy).to eq(false)
272-
todo_file = Pathname.new('packs/organisms/app/public/TODO.md')
273-
expect(todo_file.exist?).to eq false
273+
public_directory = Pathname.new('packs/organisms/app/public')
274+
expect(public_directory.exist?).to eq false
274275
end
275276
end
276277
end
@@ -286,7 +287,7 @@ def write_codeownership_config
286287
end
287288

288289
describe 'setting the README' do
289-
let(:expected_readme_todo) do
290+
let(:expected_readme) do
290291
<<~EXPECTED
291292
Welcome to `packs/organisms`!
292293
@@ -306,41 +307,44 @@ def write_codeownership_config
306307
EXPECTED
307308
end
308309

309-
it 'adds a README_TODO.md file as a placeholder' do
310+
it 'adds a README.md file as a placeholder' do
310311
Packs.create_pack!(pack_name: 'packs/organisms')
311312
ParsePackwerk.bust_cache!
312-
actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
313-
expect(actual_readme_todo.read).to eq expected_readme_todo
313+
actual_readme = ParsePackwerk.find('packs/organisms').directory.join('README.md')
314+
expect(actual_readme.read).to eq expected_readme
314315
end
315316

316317
context 'app has one pack with an outdated README_TODO.md' do
317-
it 'overwrites the README_TODO.md' do
318+
it 'deletes the README_TODO.md and adds a README' do
318319
write_file('packs/organisms/README_TODO.md', 'This is outdated')
319320
write_package_yml('packs/organisms')
320-
actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
321-
expect(actual_readme_todo.read).to eq 'This is outdated'
321+
readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
322+
expect(readme_todo.read).to eq 'This is outdated'
323+
322324
Packs.create_pack!(pack_name: 'packs/organisms')
323-
expect(actual_readme_todo.read).to eq expected_readme_todo
325+
actual_readme = ParsePackwerk.find('packs/organisms').directory.join('README.md')
326+
expect(actual_readme.read).to eq expected_readme
327+
expect(readme_todo.exist?).to eq false
324328
end
325329
end
326330

327331
context 'app has one pack with a README.md' do
328-
it 'does not add a README_TODO.md file' do
332+
it 'does not change the README.md file' do
329333
write_package_yml('packs/organisms')
330-
write_file('packs/organisms/README.md')
331-
actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
334+
write_file('packs/organisms/README.md', 'This is the original README.md')
335+
actual_readme = ParsePackwerk.find('packs/organisms').directory.join('README.md')
332336
Packs.create_pack!(pack_name: 'packs/organisms')
333-
expect(actual_readme_todo.exist?).to eq false
337+
expect(actual_readme.read).to eq 'This is the original README.md'
334338
end
335339
end
336340

337341
context 'when the app has a README template' do
338-
it 'uses the template to create the README_TODO.md' do
342+
it 'uses the template to create the README.md' do
339343
write_file('README_TEMPLATE.md', 'This is the template')
340344
Packs.create_pack!(pack_name: 'packs/organisms')
341345
ParsePackwerk.bust_cache!
342-
actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
343-
expect(actual_readme_todo.read).to eq 'This is the template'
346+
actual_readme = ParsePackwerk.find('packs/organisms').directory.join('README.md')
347+
expect(actual_readme.read).to eq 'This is the template'
344348
end
345349

346350
context 'and a custom path is specified for the README template' do
@@ -350,12 +354,12 @@ def write_codeownership_config
350354
YML
351355
end
352356

353-
it 'uses the template to create the README_TODO.md' do
357+
it 'uses the template to create the README.md' do
354358
write_file('my_folder/README_STUFF.md', 'This is the custom template')
355359
Packs.create_pack!(pack_name: 'packs/organisms')
356360
ParsePackwerk.bust_cache!
357-
actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
358-
expect(actual_readme_todo.read).to eq 'This is the custom template'
361+
actual_readme = ParsePackwerk.find('packs/organisms').directory.join('README.md')
362+
expect(actual_readme.read).to eq 'This is the custom template'
359363
end
360364
end
361365
end
@@ -812,16 +816,15 @@ def write_codeownership_config
812816
end
813817

814818
context 'app has no public dir' do
815-
it 'adds a TODO.md file letting someone know what to do with it' do
819+
it 'adds a public directory' do
816820
write_file('app/services/foo.rb')
817821
write_package_yml('packs/organisms')
818822
Packs.move_to_pack!(
819823
pack_name: 'packs/organisms',
820824
paths_relative_to_root: ['app/services/foo.rb']
821825
)
822826

823-
actual_todo = Pathname.new('packs/organisms/app/public/TODO.md').read
824-
expect(actual_todo).to eq expected_todo
827+
expect(Pathname.new('packs/organisms/app/public/organisms').exist?).to eq true
825828
end
826829

827830
context 'pack not enforcing privacy' do
@@ -856,7 +859,7 @@ def write_codeownership_config
856859
end
857860

858861
describe 'setting the README' do
859-
let(:expected_readme_todo) do
862+
let(:expected_readme) do
860863
<<~EXPECTED
861864
Welcome to `packs/organisms`!
862865
@@ -876,44 +879,46 @@ def write_codeownership_config
876879
EXPECTED
877880
end
878881

879-
it 'adds a README_TODO.md file as a placeholder' do
882+
it 'adds a README.md file as a placeholder' do
880883
write_file('app/services/foo.rb')
881884
write_package_yml('packs/organisms')
882885
Packs.move_to_pack!(
883886
pack_name: 'packs/organisms',
884887
paths_relative_to_root: ['app/services/foo.rb']
885888
)
886889

887-
actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
888-
expect(actual_readme_todo.read).to eq expected_readme_todo
890+
actual_readme = ParsePackwerk.find('packs/organisms').directory.join('README.md')
891+
expect(actual_readme.read).to eq expected_readme
889892
end
890893

891894
context 'app has one pack with an outdated README_TODO.md' do
892-
it 'overwrites the README_TODO.md' do
895+
it 'deletes the README_TODO.md and adds a README' do
893896
write_file('app/services/foo.rb')
894897
write_package_yml('packs/organisms')
895898
write_file('packs/organisms/README_TODO.md', 'This is outdated')
896-
actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
897-
expect(actual_readme_todo.read).to eq 'This is outdated'
899+
readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
900+
expect(readme_todo.read).to eq 'This is outdated'
898901
Packs.move_to_pack!(
899902
pack_name: 'packs/organisms',
900903
paths_relative_to_root: ['app/services/foo.rb']
901904
)
902-
expect(actual_readme_todo.read).to eq expected_readme_todo
905+
actual_readme = ParsePackwerk.find('packs/organisms').directory.join('README.md')
906+
expect(actual_readme.read).to eq expected_readme
907+
expect(readme_todo.exist?).to eq false
903908
end
904909
end
905910

906911
context 'app has one pack with a README.md' do
907-
it 'does not add a README_TODO.md file' do
912+
it 'does not change the README.md file' do
908913
write_file('app/services/foo.rb')
909914
write_package_yml('packs/organisms')
910-
write_file('packs/organisms/README.md')
911-
actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
915+
write_file('packs/organisms/README.md', 'This is the original README.md')
916+
actual_readme = ParsePackwerk.find('packs/organisms').directory.join('README.md')
912917
Packs.move_to_pack!(
913918
pack_name: 'packs/organisms',
914919
paths_relative_to_root: ['app/services/foo.rb']
915920
)
916-
expect(actual_readme_todo.exist?).to eq false
921+
expect(actual_readme.read).to eq 'This is the original README.md'
917922
end
918923
end
919924
end

0 commit comments

Comments
 (0)