code_ownership 1.28.2 → 1.29.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/code_ownership/cli.rb +26 -0
- data/lib/code_ownership.rb +30 -0
- data/sorbet/config +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd3be735f88cd50d9ba9d9e3d73d6adbf58ebcb20aaa4bceaf3955deedaa497c
|
4
|
+
data.tar.gz: 6a9ca2b07221580d8926218ab912ff418d7c24631a13b04767108e715f19ce57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4931c183eb23c08d0ca13bd1d6455c09aa69c9a5fce4f6b7387a3d4da4034c817c341bd74e38efe5bb958ec191f021d749fbb939bc03d9b956836d52e400b312
|
7
|
+
data.tar.gz: a102028da11aefab9899f6eb194b4078846747f6afd2fea76d4e9aa78c66dfecb7c18f8f7482a02a5d43b8d8c4452b7d4492b2704aa3d07ebcdc238a89f363eb
|
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.
|
data/lib/code_ownership/cli.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'pathname'
|
5
|
+
require 'fileutils'
|
5
6
|
|
6
7
|
module CodeOwnership
|
7
8
|
class Cli
|
@@ -11,6 +12,8 @@ module CodeOwnership
|
|
11
12
|
validate!(argv)
|
12
13
|
elsif command == 'for_file'
|
13
14
|
for_file(argv)
|
15
|
+
elsif command == 'for_team'
|
16
|
+
for_team(argv)
|
14
17
|
elsif [nil, "help"].include?(command)
|
15
18
|
puts <<~USAGE
|
16
19
|
Usage: bin/codeownership <subcommand>
|
@@ -18,6 +21,7 @@ module CodeOwnership
|
|
18
21
|
Subcommands:
|
19
22
|
validate - run all validations
|
20
23
|
for_file - find code ownership for a single file
|
24
|
+
for_team - find code ownership information for a team
|
21
25
|
help - display help information about code_ownership
|
22
26
|
USAGE
|
23
27
|
else
|
@@ -116,6 +120,28 @@ module CodeOwnership
|
|
116
120
|
end
|
117
121
|
end
|
118
122
|
|
123
|
+
def self.for_team(argv)
|
124
|
+
options = {}
|
125
|
+
|
126
|
+
parser = OptionParser.new do |opts|
|
127
|
+
opts.banner = 'Usage: bin/codeownership for_team \'Team Name\''
|
128
|
+
|
129
|
+
opts.on('--help', 'Shows this prompt') do
|
130
|
+
puts opts
|
131
|
+
exit
|
132
|
+
end
|
133
|
+
end
|
134
|
+
teams = argv.select { |arg| !arg.start_with?('--') }
|
135
|
+
args = parser.order!(argv) {}
|
136
|
+
parser.parse!(args)
|
137
|
+
|
138
|
+
if teams.count != 1
|
139
|
+
raise "Please pass in one team. Use `bin/codeownership for_team --help` for more info"
|
140
|
+
end
|
141
|
+
|
142
|
+
puts CodeOwnership.for_team(teams.first)
|
143
|
+
end
|
144
|
+
|
119
145
|
private_class_method :validate!
|
120
146
|
end
|
121
147
|
end
|
data/lib/code_ownership.rb
CHANGED
@@ -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
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.
|
4
|
+
version: 1.29.1
|
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-
|
11
|
+
date: 2022-11-30 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.
|
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
|