code_ownership 1.28.2 → 1.29.0

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: bf48240fd31979132287823a3f9d40d6b03776df405583c31a56cb87e6dfbe40
4
- data.tar.gz: 1cbd9b0fee826c7a23dd71335043eab358f99157bb7f677a94b8d4abc1782f4e
3
+ metadata.gz: 8008aad63593c3be910dc1e7f45f2518150d0e76a92f8a021279902995499402
4
+ data.tar.gz: 551585001712db071af3e33607bfd121ff48524fa66776f8ee48a299da28ef1a
5
5
  SHA512:
6
- metadata.gz: 68721e648bcd3e8888f3f94d33baf0d38b642c3d6104db0964e6aff3194860407e72c9ad88ffec357285006bff87490b49b92a238fbbf83d37509d34868ea0fe
7
- data.tar.gz: 0d878620986f0fe3e6168fa8ea0db1a1a530d27c0f35410f70b3f876146df2b184f9db3486ef9e4e74c0583a067b48ad4462af6877d7452e5d1574bec61ebd8f
6
+ metadata.gz: a2b94a65f309e158505b6dd4aa740cf3cfedc7076d9ccb0e7fbc1fe04ce147c8355cbe9cfd687a6b0e05e5ad755bb703f8fc1b530ad40f9b24fb9a4d8326a18f
7
+ data.tar.gz: 895352504690505cce06da848c5a400b3e48f1a9e10d49baa5a1e0093bd29c70c6042eaaa9c21dea14cbe8b0e7e44d15a8bf124150528f33280abee5eb101d97
data/README.md CHANGED
@@ -92,6 +92,17 @@ Under the hood, this finds the file where the class is defined and returns the o
92
92
 
93
93
  See `code_ownership_spec.rb` for an example.
94
94
 
95
+ ### `for_team`
96
+ `CodeOwnership.for_team` can be used to generate an ownership report for a team.
97
+ ```ruby
98
+ CodeOwnership.for_team('My Team')
99
+ ```
100
+
101
+ You can shovel this into a markdown file for easy viewing using the CLI:
102
+ ```
103
+ bin/codeownership for_team 'My Team' > tmp/ownership_report.md
104
+ ```
105
+
95
106
  ## Usage: Generating a `CODEOWNERS` file
96
107
 
97
108
  A `CODEOWNERS` file defines who owns specific files or paths in a repository. When you run `bin/codeownership validate`, a `.github/CODEOWNERS` file will automatically be generated and updated.
@@ -11,6 +11,8 @@ module CodeOwnership
11
11
  validate!(argv)
12
12
  elsif command == 'for_file'
13
13
  for_file(argv)
14
+ elsif command == 'for_team'
15
+ for_team(argv)
14
16
  elsif [nil, "help"].include?(command)
15
17
  puts <<~USAGE
16
18
  Usage: bin/codeownership <subcommand>
@@ -18,6 +20,7 @@ module CodeOwnership
18
20
  Subcommands:
19
21
  validate - run all validations
20
22
  for_file - find code ownership for a single file
23
+ for_team - find code ownership information for a team
21
24
  help - display help information about code_ownership
22
25
  USAGE
23
26
  else
@@ -116,6 +119,28 @@ module CodeOwnership
116
119
  end
117
120
  end
118
121
 
122
+ def self.for_team(argv)
123
+ options = {}
124
+
125
+ parser = OptionParser.new do |opts|
126
+ opts.banner = 'Usage: bin/codeownership for_team \'Team Name\''
127
+
128
+ opts.on('--help', 'Shows this prompt') do
129
+ puts opts
130
+ exit
131
+ end
132
+ end
133
+ teams = argv.select { |arg| !arg.start_with?('--') }
134
+ args = parser.order!(argv) {}
135
+ parser.parse!(args)
136
+
137
+ if teams.count != 1
138
+ raise "Please pass in one team. Use `bin/codeownership for_team --help` for more info"
139
+ end
140
+
141
+ puts CodeOwnership.for_team(teams.first)
142
+ end
143
+
119
144
  private_class_method :validate!
120
145
  end
121
146
  end
@@ -35,6 +35,36 @@ module CodeOwnership
35
35
  @for_file[file] = owner
36
36
  end
37
37
 
38
+ sig { params(team: T.any(CodeTeams::Team, String)).returns(String) }
39
+ def for_team(team)
40
+ team = T.must(CodeTeams.find(team)) if team.is_a?(String)
41
+ ownership_information = T.let([], T::Array[String])
42
+
43
+ ownership_information << "# Code Ownership Report for `#{team.name}` Team"
44
+ Private.mappers.each do |mapper|
45
+ ownership_information << "## #{mapper.description}"
46
+ codeowners_lines = mapper.codeowners_lines_to_owners
47
+ ownership_for_mapper = []
48
+ codeowners_lines.each do |line, team_for_line|
49
+ next if team_for_line.nil?
50
+ if team_for_line.name == team.name
51
+ ownership_for_mapper << "- #{line}"
52
+ end
53
+ end
54
+
55
+ if ownership_for_mapper.empty?
56
+ ownership_information << 'This team owns nothing in this category.'
57
+ else
58
+ ownership_information += ownership_for_mapper
59
+ end
60
+
61
+
62
+ ownership_information << ""
63
+ end
64
+
65
+ ownership_information.join("\n")
66
+ end
67
+
38
68
  class InvalidCodeOwnershipConfigurationError < StandardError
39
69
  end
40
70
 
data/sorbet/config CHANGED
@@ -1,4 +1,5 @@
1
1
  --dir
2
2
  .
3
3
  --ignore=/spec
4
+ --ignore=/vendor/bundle
4
5
  --enable-experimental-requires-ancestor
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_ownership
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.28.2
4
+ version: 1.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-18 00:00:00.000000000 Z
11
+ date: 2022-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_teams
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  - !ruby/object:Gem::Version
177
177
  version: '0'
178
178
  requirements: []
179
- rubygems_version: 3.3.7
179
+ rubygems_version: 3.1.6
180
180
  signing_key:
181
181
  specification_version: 4
182
182
  summary: A gem to help engineering teams declare ownership of code