Skip to content

Commit e699617

Browse files
author
Alex Evanczuk
authored
Allow logged documentation to be configurable (#23)
* move create and move to pack pack logging into configuration * move remaining log events to user event logger * Remove gusto specific things * bump version * remove temporary gusto config * rubocop
1 parent d3abbdb commit e699617

File tree

9 files changed

+306
-250
lines changed

9 files changed

+306
-250
lines changed

Gemfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
use_packwerk (0.55.0)
4+
use_packwerk (0.56.0)
55
code_ownership
66
colorize
77
package_protections
@@ -12,14 +12,14 @@ PATH
1212
GEM
1313
remote: https://rubygems.org/
1414
specs:
15-
activesupport (7.0.3.1)
15+
activesupport (7.0.4)
1616
concurrent-ruby (~> 1.0, >= 1.0.2)
1717
i18n (>= 1.6, < 2)
1818
minitest (>= 5.1)
1919
tzinfo (~> 2.0)
2020
ast (2.4.2)
2121
byebug (11.1.3)
22-
code_ownership (1.28.0)
22+
code_ownership (1.28.2)
2323
code_teams (~> 1.0)
2424
parse_packwerk
2525
sorbet-runtime
@@ -34,14 +34,14 @@ GEM
3434
json (2.6.2)
3535
method_source (1.0.0)
3636
minitest (5.16.3)
37-
package_protections (1.4.0)
37+
package_protections (2.2.1)
3838
activesupport
3939
parse_packwerk
4040
rubocop
4141
rubocop-sorbet
4242
sorbet-runtime
4343
parallel (1.22.1)
44-
parse_packwerk (0.12.0)
44+
parse_packwerk (0.12.1)
4545
sorbet-runtime
4646
parser (3.1.2.0)
4747
ast (~> 2.4.1)

lib/use_packwerk.rb

Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,7 @@ def self.move_to_pack!(
6262
per_file_processors: []
6363
)
6464
Logging.section('👋 Hi!') do
65-
intro = <<~INTRO
66-
You are moving a file to a pack, which is great. Check out #{UsePackwerk.config.documentation_link} for more info!
67-
68-
Please bring any questions or issues you have in your development process to #ruby-modularity or #product-infrastructure.
69-
We'd be happy to try to help through pairing, accepting feedback, changing our process, changing our tools, and more.
70-
INTRO
65+
intro = UsePackwerk.config.user_event_logger.before_move_to_pack(pack_name)
7166
Logging.print_bold_green(intro)
7267
end
7368

@@ -78,20 +73,7 @@ def self.move_to_pack!(
7873
)
7974

8075
Logging.section('Next steps') do
81-
next_steps = <<~NEXT_STEPS
82-
Your next steps might be:
83-
84-
1) Run `bin/packwerk update-deprecations` to update the violations. Make sure to run `spring stop` if you've added new load paths (new top-level directories) in your pack.
85-
86-
2) Update TODO lists for rubocop implemented protections. See #{UsePackwerk.config.documentation_link} for more info
87-
88-
3) Touch base with each team who owns files involved in this move
89-
90-
4) Expose public API in #{pack_name}/app/public. Try `bin/use_packwerk make_public #{pack_name}/path/to/file.rb`
91-
92-
5) Update your readme at #{pack_name}/README.md
93-
NEXT_STEPS
94-
76+
next_steps = UsePackwerk.config.user_event_logger.after_move_to_pack(pack_name)
9577
Logging.print_bold_green(next_steps)
9678
end
9779
end
@@ -107,9 +89,7 @@ def self.make_public!(
10789
per_file_processors: []
10890
)
10991
Logging.section('Making files public') do
110-
intro = <<~INTRO
111-
You are moving some files into public API. See #{UsePackwerk.config.documentation_link} for other utilities!
112-
INTRO
92+
intro = UsePackwerk.config.user_event_logger.before_make_public
11393
Logging.print_bold_green(intro)
11494
end
11595

@@ -119,18 +99,7 @@ def self.make_public!(
11999
)
120100

121101
Logging.section('Next steps') do
122-
next_steps = <<~NEXT_STEPS
123-
Your next steps might be:
124-
125-
1) Run `bin/packwerk update-deprecations` to update the violations. Make sure to run `spring stop` if you've added new load paths (new top-level directories) in your pack.
126-
127-
2) Update TODO lists for rubocop implemented protections. See #{UsePackwerk.config.documentation_link} for more info
128-
129-
3) Work to migrate clients of private API to your new public API
130-
131-
4) Update your README at packs/your_package_name/README.md
132-
NEXT_STEPS
133-
102+
next_steps = UsePackwerk.config.user_event_logger.after_make_public
134103
Logging.print_bold_green(next_steps)
135104
end
136105
end
@@ -146,9 +115,7 @@ def self.add_dependency!(
146115
dependency_name:
147116
)
148117
Logging.section('Adding a dependency') do
149-
intro = <<~INTRO
150-
You are adding a dependency. See #{UsePackwerk.config.documentation_link} for other utilities!
151-
INTRO
118+
intro = UsePackwerk.config.user_event_logger.before_add_dependency(pack_name)
152119
Logging.print_bold_green(intro)
153120
end
154121

@@ -158,14 +125,7 @@ def self.add_dependency!(
158125
)
159126

160127
Logging.section('Next steps') do
161-
next_steps = <<~NEXT_STEPS
162-
Your next steps might be:
163-
164-
1) Run `bin/packwerk validate` to ensure you haven't introduced a cyclic dependency
165-
166-
2) Run `bin/packwerk update-deprecations` to update the violations.
167-
NEXT_STEPS
168-
128+
next_steps = UsePackwerk.config.user_event_logger.after_add_dependency(pack_name)
169129
Logging.print_bold_green(next_steps)
170130
end
171131
end
@@ -183,12 +143,7 @@ def self.move_to_parent!(
183143
per_file_processors: []
184144
)
185145
Logging.section('👋 Hi!') do
186-
intro = <<~INTRO
187-
You are moving one pack to be a child of a different pack. Check out #{UsePackwerk.config.documentation_link} for more info!
188-
189-
Please bring any questions or issues you have in your development process to #ruby-modularity or #product-infrastructure.
190-
We'd be happy to try to help through pairing, accepting feedback, changing our process, changing our tools, and more.
191-
INTRO
146+
intro = UsePackwerk.config.user_event_logger.before_move_to_parent(pack_name)
192147
Logging.print_bold_green(intro)
193148
end
194149

@@ -199,13 +154,7 @@ def self.move_to_parent!(
199154
)
200155

201156
Logging.section('Next steps') do
202-
next_steps = <<~NEXT_STEPS
203-
Your next steps might be:
204-
205-
1) Delete the old pack when things look good: `rm -rf #{pack_name}`
206-
207-
2) Run `bin/packwerk update-deprecations` to update the violations. Make sure to run `spring stop` first.
208-
NEXT_STEPS
157+
next_steps = UsePackwerk.config.user_event_logger.after_move_to_parent(pack_name)
209158

210159
Logging.print_bold_green(next_steps)
211160
end

lib/use_packwerk/configuration.rb

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,32 @@
11
# typed: strict
22

3+
require 'use_packwerk/user_event_logger'
4+
require 'use_packwerk/default_user_event_logger'
5+
36
module UsePackwerk
47
class Configuration
58
extend T::Sig
69

710
sig { params(enforce_dependencies: T::Boolean).void }
811
attr_writer :enforce_dependencies
912

10-
sig { params(documentation_link: String).void }
11-
attr_writer :documentation_link
13+
sig { returns(UserEventLogger) }
14+
attr_accessor :user_event_logger
1215

1316
sig { void }
1417
def initialize
1518
@enforce_dependencies = T.let(default_enforce_dependencies, T::Boolean)
16-
@documentation_link = T.let(default_documentation_link, String)
19+
@user_event_logger = T.let(DefaultUserEventLogger.new, UserEventLogger)
1720
end
1821

1922
sig { returns(T::Boolean) }
2023
def enforce_dependencies
2124
@enforce_dependencies
2225
end
2326

24-
# Configure a link to show up for users who are looking for more info
25-
sig { returns(String) }
26-
def documentation_link
27-
@documentation_link
28-
end
29-
3027
sig { void }
3128
def bust_cache!
3229
@enforce_dependencies = default_enforce_dependencies
33-
@documentation_link = default_documentation_link
34-
end
35-
36-
sig { returns(String) }
37-
def default_documentation_link
38-
'https://go/packwerk'
3930
end
4031

4132
sig { returns(T::Boolean) }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# typed: strict
2+
3+
module UsePackwerk
4+
class DefaultUserEventLogger
5+
include UserEventLogger
6+
end
7+
end

lib/use_packwerk/private.rb

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ def self.replace_in_file(file:, find:, replace_with:)
4949
end
5050
def self.create_pack!(pack_name:, enforce_privacy:, enforce_dependencies:)
5151
Logging.section('👋 Hi!') do
52-
intro = <<~INTRO
53-
You are creating a pack, which is great. Check out #{UsePackwerk.config.documentation_link} for more info!
54-
55-
Please bring any questions or issues you have in your development process to #ruby-modularity or #product-infrastructure.
56-
We'd be happy to try to help through pairing, accepting feedback, changing our process, changing our tools, and more.
57-
INTRO
52+
intro = UsePackwerk.config.user_event_logger.before_create_pack(pack_name)
5853
Logging.print_bold_green(intro)
5954
end
6055

@@ -65,19 +60,7 @@ def self.create_pack!(pack_name:, enforce_privacy:, enforce_dependencies:)
6560
add_readme_todo(package)
6661

6762
Logging.section('Next steps') do
68-
next_steps = <<~NEXT_STEPS
69-
Your next steps might be:
70-
71-
1) Move files into your pack with `bin/use_packwerk move #{pack_name} path/to/file.rb`
72-
73-
2) Run `bin/packwerk update-deprecations` to update the violations. Make sure to run `spring stop` if you've added new load paths (new top-level directories) in your pack.
74-
75-
3) Update TODO lists for rubocop implemented protections. See #{UsePackwerk.config.documentation_link} for more info
76-
77-
4) Expose public API in #{pack_name}/app/public. Try `bin/use_packwerk make_public #{pack_name}/path/to/file.rb`
78-
79-
5) Update your readme at #{pack_name}/README.md
80-
NEXT_STEPS
63+
next_steps = UsePackwerk.config.user_event_logger.after_create_pack(pack_name)
8164

8265
Logging.print_bold_green(next_steps)
8366
end
@@ -332,25 +315,7 @@ def self.add_public_directory(package)
332315

333316
if public_directory.glob('**/**.rb').none?
334317
FileUtils.mkdir_p(public_directory)
335-
todo_md = <<~TODO
336-
This directory holds your public API!
337-
338-
Any classes, constants, or modules that you want other packs to use and you intend to support should go in here.
339-
Anything that is considered private should go in other folders.
340-
341-
If another pack uses classes, constants, or modules that are not in your public folder, it will be considered a "privacy violation" by packwerk.
342-
You can prevent other packs from using private API by using package_protections.
343-
344-
Want to find how your private API is being used today?
345-
Try running: `bin/use_packwerk list_top_privacy_violations #{package.name}`
346-
347-
Want to move something into this folder?
348-
Try running: `bin/use_packwerk make_public #{package.name}/path/to/file.rb`
349-
350-
One more thing -- feel free to delete this file and replace it with a README.md describing your package in the main package directory.
351-
352-
See #{UsePackwerk.config.documentation_link} for more info!
353-
TODO
318+
todo_md = UsePackwerk.config.user_event_logger.on_create_public_directory_todo(package.name)
354319
public_directory.join('TODO.md').write(todo_md)
355320
end
356321
end
@@ -360,23 +325,7 @@ def self.add_readme_todo(package)
360325
pack_directory = package.directory
361326

362327
if !pack_directory.join('README.md').exist?
363-
readme_todo_md = <<~TODO
364-
Welcome to `#{package.name}`!
365-
366-
If you're the author, please consider replacing this file with a README.md, which may contain:
367-
- What your pack is and does
368-
- How you expect people to use your pack
369-
- Example usage of your pack's public API (which lives in `#{package.name}/app/public`)
370-
- Limitations, risks, and important considerations of usage
371-
- How to get in touch with eng and other stakeholders for questions or issues pertaining to this pack (note: it is recommended to add ownership in `#{package.name}/package.yml` under the `owner` metadata key)
372-
- What SLAs/SLOs (service level agreements/objectives), if any, your package provides
373-
- When in doubt, keep it simple
374-
- Anything else you may want to include!
375-
376-
README.md files are under version control and should change as your public API changes.#{' '}
377-
378-
See #{UsePackwerk.config.documentation_link} for more info!
379-
TODO
328+
readme_todo_md = UsePackwerk.config.user_event_logger.on_create_readme_todo(package.name)
380329
pack_directory.join('README_TODO.md').write(readme_todo_md)
381330
end
382331
end

0 commit comments

Comments
 (0)