code_ownership 1.36.3 → 1.37.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 +4 -4
- data/README.md +24 -0
- data/lib/code_ownership/private/ownership_mappers/directory_ownership.rb +23 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c854c774447149078df69925e183be064e8ac92ea464da9eea83cec2cfb10931
|
4
|
+
data.tar.gz: 5a42650db0cdc8f14fd8878a0c70587b21a722a284a45104051062464f73a4a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25025e91fa585614f864ab1f84d829037b5769cd491dcca93bf822e25ecb3222388d8d9315bf7dd3fe5a645645855c391028a9df01592199ce0857d47276656e
|
7
|
+
data.tar.gz: 8f8035f102b184ac7ea866df6bff7cee92f0bd2fe5337b49956c85e2ead483a5868c0969030392c63dda1575f9bf33ae085058c0114ef027140b3bf629a60895
|
data/README.md
CHANGED
@@ -8,6 +8,30 @@ Check out [`code_ownership_spec.rb`](https://github.com/rubyatscale/code_ownersh
|
|
8
8
|
|
9
9
|
There is also a [companion VSCode Extension]([url](https://github.com/rubyatscale/code-ownership-vscode)) for this gem. Just search `Gusto.code-ownership-vscode` in the VSCode Extension Marketplace.
|
10
10
|
|
11
|
+
## Getting started
|
12
|
+
|
13
|
+
To get started there's a few things you should do.
|
14
|
+
|
15
|
+
1) Create a `config/code_ownership.yml` file and declare where your files live. Here's a sample to start with:
|
16
|
+
```yml
|
17
|
+
owned_globs:
|
18
|
+
- '{app,components,config,frontend,lib,packs,spec}/**/*.{rb,rake,js,jsx,ts,tsx}'
|
19
|
+
js_package_paths: []
|
20
|
+
unowned_globs:
|
21
|
+
- db/**/*
|
22
|
+
- app/services/some_file1.rb
|
23
|
+
- app/services/some_file2.rb
|
24
|
+
- frontend/javascripts/**/__generated__/**/*
|
25
|
+
```
|
26
|
+
2) Declare some teams. Here's an example, that would live at `config/teams/operations.yml`:
|
27
|
+
```yml
|
28
|
+
name: Operations
|
29
|
+
github:
|
30
|
+
team: '@my-org/operations-team'
|
31
|
+
```
|
32
|
+
3) Declare ownership. You can do this at a directory level or at a file level. All of the files within the `owned_globs` you declared in step 1 will need to have an owner assigned (or be opted out via `unowned_globs`). See the next section for more detail.
|
33
|
+
4) Run validations when you commit, and/or in CI. If you run validations in CI, ensure that if your `.github/CODEOWNERS` file gets changed, that gets pushed to the PR.
|
34
|
+
|
11
35
|
## Usage: Declaring Ownership
|
12
36
|
|
13
37
|
There are three ways to declare code ownership using this gem.
|
@@ -48,7 +48,8 @@ module CodeOwnership
|
|
48
48
|
.map(&:cleanpath)
|
49
49
|
.each_with_object({}) do |pathname, res|
|
50
50
|
owner = owner_for_codeowners_file(pathname)
|
51
|
-
|
51
|
+
glob = glob_for_codeowners_file(pathname)
|
52
|
+
res[glob] = owner
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
@@ -77,7 +78,7 @@ module CodeOwnership
|
|
77
78
|
# Takes a file and finds the relevant `.codeowner` file by walking up the directory
|
78
79
|
# structure. Example, given `a/b/c.rb`, this looks for `a/b/.codeowner`, `a/.codeowner`,
|
79
80
|
# and `.codeowner` in that order, stopping at the first file to actually exist.
|
80
|
-
# If the
|
81
|
+
# If the provided file is a directory, it will look for `.codeowner` in that directory and then upwards.
|
81
82
|
# We do additional caching so that we don't have to check for file existence every time.
|
82
83
|
sig { params(file: String).returns(T.nilable(CodeTeams::Team)) }
|
83
84
|
def map_file_to_relevant_owner(file)
|
@@ -123,6 +124,26 @@ module CodeOwnership
|
|
123
124
|
|
124
125
|
team
|
125
126
|
end
|
127
|
+
|
128
|
+
sig { params(codeowners_file: Pathname).returns(String) }
|
129
|
+
def glob_for_codeowners_file(codeowners_file)
|
130
|
+
unescaped = codeowners_file.dirname.cleanpath.join('**/**').to_s
|
131
|
+
|
132
|
+
# Globs can contain certain regex characters, like "[" and "]".
|
133
|
+
# However, when we are generating a glob from a .codeowner file, we
|
134
|
+
# need to escape bracket characters and interpret them literally.
|
135
|
+
# Otherwise the resulting glob will not actually match the directory
|
136
|
+
# containing the .codeowner file.
|
137
|
+
#
|
138
|
+
# Example
|
139
|
+
# file: "/some/[dir]/.codeowner"
|
140
|
+
# unescaped: "/some/[dir]/**/**"
|
141
|
+
# matches: "/some/d/file"
|
142
|
+
# matches: "/some/i/file"
|
143
|
+
# matches: "/some/r/file"
|
144
|
+
# does not match!: "/some/[dir]/file"
|
145
|
+
unescaped.gsub(/[\[\]]/) { |x| "\\#{x}" }
|
146
|
+
end
|
126
147
|
end
|
127
148
|
end
|
128
149
|
end
|
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.37.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: 2024-
|
11
|
+
date: 2024-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: code_teams
|