fast_code_owners 0.0.7-arm64-darwin → 0.0.9-arm64-darwin

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73053f90ac155bdb6bcfb007df21742bc65e77d41d3883c2d82505efb003f1a1
4
- data.tar.gz: 2af413a372c1f1c924fe9548166722c6aa875c16f31ce6ee242aa5dd82a7fc56
3
+ metadata.gz: 0e757161dbf95015021a20bb73b0665ab57fc976a7a74e43a827a0b116349371
4
+ data.tar.gz: 1dd313c712c856bb4eb8740a269be952e5dc77fb765383a5b77ba1e5d0569e17
5
5
  SHA512:
6
- metadata.gz: a19f40e0b60f13bd0613391c433661f4578f7a4ef30e367a5b20fd0073a42d64aedc753e12f346cfbd082b52c49a058511502c54694e1e599a0c33a10d5241a5
7
- data.tar.gz: 59263073d5c1f13f59a5fdbf822b0b73bda06b0c8ad951fa384ac5663e832243e14aab8b3a2f4e8473bc5e63c14807d6a5ee682a8008ea781446f9996d69a023
6
+ metadata.gz: 23b473180761d5d76ed7ea8fd833a9cc8ef92263bc5337527a5e36c81c5321141ae67cf45c2c1231f133f2b8ebceac0f1c99c61292f5389246fbbc5ced97bca0
7
+ data.tar.gz: d8e40dc729c79e507bee15362fe0b7976c10f70c272321ffa3edb15921f363ada0bb02996ddea9f0f5d86a950cb11d644b807552fd2038a0d43dcfa83c82eb68
@@ -0,0 +1,150 @@
1
+ # typed: true
2
+
3
+ require 'optparse'
4
+ require 'pathname'
5
+ require 'fileutils'
6
+
7
+ module FastCodeOwners
8
+ class Cli
9
+ def self.run!(argv)
10
+ command = argv.shift
11
+ if command == 'validate'
12
+ validate!(argv)
13
+ elsif command == 'for_file'
14
+ for_file(argv)
15
+ elsif command == 'for_team'
16
+ for_team(argv)
17
+ elsif [nil, 'help'].include?(command)
18
+ puts <<~USAGE
19
+ Usage: bin/codeownership <subcommand>
20
+
21
+ Subcommands:
22
+ validate - run all validations
23
+ for_file - find code ownership for a single file
24
+ for_team - find code ownership information for a team
25
+ help - display help information about code_ownership
26
+ USAGE
27
+ else
28
+ puts "'#{command}' is not a code_ownership command. See `bin/codeownership help`."
29
+ end
30
+ end
31
+
32
+ def self.validate!(argv)
33
+ options = {}
34
+
35
+ parser = OptionParser.new do |opts|
36
+ opts.banner = 'Usage: bin/codeownership validate [options]'
37
+
38
+ opts.on('--skip-autocorrect', 'Skip automatically correcting any errors, such as the .github/CODEOWNERS file') do
39
+ options[:skip_autocorrect] = true
40
+ end
41
+
42
+ opts.on('-d', '--diff', 'Only run validations with staged files') do
43
+ options[:diff] = true
44
+ end
45
+
46
+ opts.on('-s', '--skip-stage', 'Skips staging the CODEOWNERS file') do
47
+ options[:skip_stage] = true
48
+ end
49
+
50
+ opts.on('--help', 'Shows this prompt') do
51
+ puts opts
52
+ exit
53
+ end
54
+ end
55
+ args = parser.order!(argv)
56
+ parser.parse!(args)
57
+
58
+ files = if options[:diff]
59
+ ENV.fetch('CODEOWNERS_GIT_STAGED_FILES') { `git diff --staged --name-only` }.split("\n").select do |file|
60
+ File.exist?(file)
61
+ end
62
+ else
63
+ nil
64
+ end
65
+
66
+ result = FastCodeOwners.validate!(
67
+ files: files,
68
+ autocorrect: !options[:skip_autocorrect],
69
+ stage_changes: !options[:skip_stage]
70
+ )
71
+ puts "cli result: #{result}"
72
+ if result.nil?
73
+ puts 'No errors found'
74
+ else
75
+ puts result
76
+ end
77
+ end
78
+
79
+ # For now, this just returns team ownership
80
+ # Later, this could also return code ownership errors about that file.
81
+ def self.for_file(argv)
82
+ options = {}
83
+
84
+ # Long-term, we probably want to use something like `thor` so we don't have to implement logic
85
+ # like this. In the short-term, this is a simple way for us to use the built-in OptionParser
86
+ # while having an ergonomic CLI.
87
+ files = argv.reject { |arg| arg.start_with?('--') }
88
+
89
+ parser = OptionParser.new do |opts|
90
+ opts.banner = 'Usage: bin/codeownership for_file [options]'
91
+
92
+ opts.on('--json', 'Output as JSON') do
93
+ options[:json] = true
94
+ end
95
+
96
+ opts.on('--help', 'Shows this prompt') do
97
+ puts opts
98
+ exit
99
+ end
100
+ end
101
+ args = parser.order!(argv)
102
+ parser.parse!(args)
103
+
104
+ if files.count != 1
105
+ raise 'Please pass in one file. Use `bin/codeownership for_file --help` for more info'
106
+ end
107
+
108
+ team = FastCodeOwners.for_file(files.first)
109
+
110
+ team_name = team&.name || 'Unowned'
111
+ team_yml = team&.config_yml || 'Unowned'
112
+
113
+ if options[:json]
114
+ json = {
115
+ team_name: team_name,
116
+ team_yml: team_yml
117
+ }
118
+
119
+ puts json.to_json
120
+ else
121
+ puts <<~MSG
122
+ Team: #{team_name}
123
+ Team YML: #{team_yml}
124
+ MSG
125
+ end
126
+ end
127
+
128
+ def self.for_team(argv)
129
+ parser = OptionParser.new do |opts|
130
+ opts.banner = 'Usage: bin/codeownership for_team \'Team Name\''
131
+
132
+ opts.on('--help', 'Shows this prompt') do
133
+ puts opts
134
+ exit
135
+ end
136
+ end
137
+ teams = argv.reject { |arg| arg.start_with?('--') }
138
+ args = parser.order!(argv)
139
+ parser.parse!(args)
140
+
141
+ if teams.count != 1
142
+ raise 'Please pass in one team. Use `bin/codeownership for_team --help` for more info'
143
+ end
144
+
145
+ puts FastCodeOwners.for_team(teams.first)
146
+ end
147
+
148
+ private_class_method :validate!
149
+ end
150
+ end
@@ -14,6 +14,7 @@ module FastCodeOwners
14
14
  sig { params(file_path: String).returns(T.nilable(CodeTeams::Team)) }
15
15
  def for_file(file_path)
16
16
  return nil if file_path.start_with?('./')
17
+
17
18
  return FilePathTeamCache.get(file_path) if FilePathTeamCache.cached?(file_path)
18
19
 
19
20
  result = T.let(RustCodeOwners.for_file(file_path), T.nilable(T::Hash[Symbol, String]))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastCodeOwners
4
- VERSION = '0.0.7'
4
+ VERSION = '0.0.9'
5
5
  end
@@ -9,6 +9,7 @@ require_relative 'fast_code_owners/file_path_team_cache'
9
9
  require_relative 'fast_code_owners/team_finder'
10
10
  require_relative 'fast_code_owners/version'
11
11
  require_relative 'fast_code_owners/file_path_finder'
12
+ require_relative 'fast_code_owners/cli'
12
13
 
13
14
  begin
14
15
  RUBY_VERSION =~ /(\d+\.\d+)/
@@ -24,6 +25,25 @@ module FastCodeOwners
24
25
  extend T::Helpers
25
26
  requires_ancestor { Kernel }
26
27
 
28
+ sig do
29
+ params(
30
+ autocorrect: T::Boolean,
31
+ stage_changes: T::Boolean,
32
+ files: T.nilable(T::Array[String])
33
+ ).returns(T.nilable(T::Hash[Symbol, String]))
34
+ end
35
+ def validate!(
36
+ autocorrect: true,
37
+ stage_changes: true,
38
+ files: nil
39
+ )
40
+ if autocorrect
41
+ ::RustCodeOwners.generate_and_validate
42
+ else
43
+ ::RustCodeOwners.validate
44
+ end
45
+ end
46
+
27
47
  sig { params(file_path: String).returns(T.nilable(CodeTeams::Team)) }
28
48
  def for_file(file_path)
29
49
  TeamFinder.for_file(file_path)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_code_owners
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: arm64-darwin
6
6
  authors:
7
7
  - Perry Hertler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-05-17 00:00:00.000000000 Z
11
+ date: 2025-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_teams
@@ -140,6 +140,7 @@ files:
140
140
  - lib/fast_code_owners.rb
141
141
  - lib/fast_code_owners/3.2/fast_code_owners.bundle
142
142
  - lib/fast_code_owners/3.4/fast_code_owners.bundle
143
+ - lib/fast_code_owners/cli.rb
143
144
  - lib/fast_code_owners/file_path_finder.rb
144
145
  - lib/fast_code_owners/file_path_team_cache.rb
145
146
  - lib/fast_code_owners/team_finder.rb