code_ownership 1.36.3 → 1.37.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb464ff5e39c0c9f2712a7af6498f30b3b42e3c456e7da52a5209d7f30467346
4
- data.tar.gz: 5fd3f8974a041ff298fbdaceca0b3eccee027f4d9c94bdfaa344ae9b8ade72d5
3
+ metadata.gz: c854c774447149078df69925e183be064e8ac92ea464da9eea83cec2cfb10931
4
+ data.tar.gz: 5a42650db0cdc8f14fd8878a0c70587b21a722a284a45104051062464f73a4a7
5
5
  SHA512:
6
- metadata.gz: ef51049577f74ab3faed01b4a37df119eaf577465fa10f342b79c0fabf7bc89b59ed993f8c1d8f687c53a3957745dfe579430e081473b9eb63f9b3cbe1f8eb19
7
- data.tar.gz: ba03e839b81e0dcdfd1c07356b99dbf850b9abddaa83049c2c74e458012c4b81bdfaead12ed6c59fc744848261e078d715f6512df876d1d1fa238362910bfcb9
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
- res[pathname.dirname.cleanpath.join('**/**').to_s] = owner
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 parovided file is a directory, it will look for `.codeowner` in that directory and then upwards.
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.36.3
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-07-30 00:00:00.000000000 Z
11
+ date: 2024-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_teams