Skip to content

Commit 196a127

Browse files
committed
updates to readme
1 parent 3d3edf0 commit 196a127

File tree

2 files changed

+118
-63
lines changed

2 files changed

+118
-63
lines changed

README.md

Lines changed: 117 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,63 @@
11
# Codeowners
22

3-
**Codeowners** is a fast, Rust-based CLI for generating and validating [GitHub `CODEOWNERS` files](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners) in large repositories.
3+
**Codeowners** is a fast, Rust-based CLI for generating and validating [GitHub `CODEOWNERS` files](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners) in large repositories.
44

5-
Note: For Ruby application, it's usually easier to use `codeowners-rs` via the [code_ownership](https://github.com/rubyatscale/code_ownership) gem.
5+
Note: For Ruby applications, it's usually easier to use `codeowners-rs` via the [code_ownership](https://github.com/rubyatscale/code_ownership) gem.
66

77
## 🚀 Quick Start: Generate & Validate
88

9-
The most common workflow is to **generate and validate your CODEOWNERS file** in a single step:
9+
The most common workflow is to generate and validate in one step:
1010

1111
```sh
1212
codeowners gv
1313
```
1414

15-
- This command will:
16-
- Generate a fresh `CODEOWNERS` file (by default at `.github/CODEOWNERS`)
17-
- Validate that all files are properly owned and that the file is up to date
18-
- Exit with a nonzero code and detailed errors if validation fails
15+
- Generates a fresh `CODEOWNERS` file (default: `.github/CODEOWNERS`)
16+
- Validates ownership and that the file is up to date
17+
- Exits non-zero and prints detailed errors if validation fails
1918

2019
## Table of Contents
2120

22-
- [Quick Start: Generate & Validate](#-quick-start-generate--validate)
21+
- [Quick Start: Generate & Validate](#quick-start-generate--validate)
22+
- [Installation](#installation)
2323
- [Getting Started](#getting-started)
2424
- [Declaring Ownership](#declaring-ownership)
2525
- [Directory-Based Ownership](#1-directory-based-ownership)
2626
- [File Annotation](#2-file-annotation)
2727
- [Package-Based Ownership](#3-package-based-ownership)
2828
- [Glob-Based Ownership](#4-glob-based-ownership)
2929
- [JavaScript Package Ownership](#5-javascript-package-ownership)
30-
- [Other CLI Commands](#other-cli-commands)
30+
- [CLI Reference](#cli-reference)
31+
- [Global Flags](#global-flags)
32+
- [Commands](#commands)
3133
- [Examples](#examples)
32-
- [Find the owner of a file](#find-the-owner-of-a-file)
33-
- [Ownership report for a team](#ownership-report-for-a-team)
34+
- [Configuration](#configuration)
35+
- [Cache](#cache)
3436
- [Validation](#validation)
37+
- [Library Usage](#library-usage)
3538
- [Development](#development)
36-
- [Configuration](#configuration)
3739

38-
## Getting Started
40+
## Installation
41+
42+
You can run `codeowners` without installing a platform-specific binary by using DotSlash, or install from source with Cargo.
43+
44+
### Option A: DotSlash (recommended)
3945

40-
1. **Install DotSlash**
41-
[Install DotSlash](https://dotslash-cli.com/docs/installation/)
42-
Releases include a DotSlash text file that will automatically download and run the correct binary for your system.
46+
1. Install DotSlash: see [https://dotslash-cli.com/docs/installation/](https://dotslash-cli.com/docs/installation/)
47+
2. Download the latest DotSlash text file from a release, for example [https://github.com/rubyatscale/codeowners-rs/releases](https://github.com/rubyatscale/codeowners-rs/releases).
48+
3. Execute the downloaded file with DotSlash; it will fetch and run the correct binary.
4349

44-
2. **Download the Latest DotSlash Text File**
45-
Releases contain a DotSlash text file. Example: [codeowners release v0.2.4](https://github.com/rubyatscale/codeowners-rs/releases/download/v0.2.4/codeowners).
46-
Running this file with DotSlash installed will execute `codeowners`.
50+
### Option B: From source with Cargo
51+
52+
Requires Rust toolchain.
53+
54+
```sh
55+
cargo install --git https://github.com/rubyatscale/codeowners-rs codeowners
56+
```
4757

48-
3. **Configure Ownership**
58+
## Getting Started
59+
60+
1. **Configure Ownership**
4961
Create a `config/code_ownership.yml` file. Example:
5062

5163
```yaml
@@ -58,7 +70,7 @@ codeowners gv
5870
- frontend/javascripts/**/__generated__/**/*
5971
```
6072
61-
4. **Declare Teams**
73+
2. **Declare Teams**
6274
Example: `config/teams/operations.yml`
6375

6476
```yaml
@@ -67,7 +79,7 @@ codeowners gv
6779
team: '@my-org/operations-team'
6880
```
6981

70-
5. **Run the Main Workflow**
82+
3. **Run the Main Workflow**
7183

7284
```sh
7385
codeowners gv
@@ -92,7 +104,15 @@ Add an annotation at the top of a file:
92104
```ruby
93105
# @team MyTeam
94106
```
95-
107+
```typescript
108+
// @team MyTeam
109+
```
110+
```html
111+
<!-- @team MyTeam -->
112+
```
113+
```erb
114+
<%# @team: Foo %>
115+
```
96116
### 3. Package-Based Ownership
97117

98118
In `package.yml` (for Ruby Packwerk):
@@ -133,29 +153,27 @@ js_package_paths:
133153
- frontend/javascripts/packages/*
134154
```
135155

156+
## CLI Reference
136157

137-
## Other CLI Commands
158+
### Global Flags
138159

139-
While `codeowners gv` is the main workflow, the CLI also supports:
140-
141-
```text
142-
Usage: codeowners [OPTIONS] <COMMAND>
160+
- `--codeowners-file-path <path>`: Path for the CODEOWNERS file. Default: `./.github/CODEOWNERS`
161+
- `--config-path <path>`: Path to `code_ownership.yml`. Default: `./config/code_ownership.yml`
162+
- `--project-root <path>`: Project root. Default: `.`
163+
- `--no-cache`: Disable on-disk caching (useful in CI)
164+
- `-V, --version`, `-h, --help`
143165

144-
Commands:
145-
for-file Finds the owner of a given file. [aliases: f]
146-
for-team Finds code ownership information for a given team [aliases: t]
147-
generate Generate the CODEOWNERS file [aliases: g]
148-
validate Validate the CODEOWNERS file [aliases: v]
149-
generate-and-validate Chains both `generate` and `validate` [aliases: gv]
150-
help Print this message or the help of the given subcommand(s)
166+
### Commands
151167

152-
Options:
153-
--codeowners-file-path <CODEOWNERS_FILE_PATH> [default: ./.github/CODEOWNERS]
154-
--config-path <CONFIG_PATH> [default: ./config/code_ownership.yml]
155-
--project-root <PROJECT_ROOT> [default: .]
156-
-h, --help
157-
-V, --version
158-
```
168+
- `generate` (`g`): Generate the CODEOWNERS file and write it to `--codeowners-file-path`.
169+
- Flags: `--skip-stage, -s` to avoid `git add` after writing
170+
- `validate` (`v`): Validate the CODEOWNERS file and configuration.
171+
- `generate-and-validate` (`gv`): Run `generate` then `validate`.
172+
- Flags: `--skip-stage, -s`
173+
- `for-file <path>` (`f`): Print the owner of a file.
174+
- Flags: `--from-codeowners` to resolve using only the CODEOWNERS rules
175+
- `for-team <name>` (`t`): Print ownership report for a team.
176+
- `delete-cache` (`d`): Delete the persisted cache.
159177

160178
### Examples
161179

@@ -171,37 +189,54 @@ codeowners for-file path/to/file.rb
171189
codeowners for-team Payroll
172190
```
173191

174-
## Validation
192+
#### Generate but do not stage the file
175193

176-
`codeowners validate` (or `codeowners gv`) ensures:
194+
```sh
195+
codeowners generate --skip-stage
196+
```
177197

178-
1. Only one mechanism defines ownership for any file.
179-
2. All referenced teams are valid.
180-
3. All files in `owned_globs` are owned, unless in `unowned_globs`.
181-
4. The `CODEOWNERS` file is up to date.
198+
#### Run without using the cache
182199

183-
## Development
200+
```sh
201+
codeowners gv --no-cache
202+
```
184203

185-
- Written in Rust for speed and reliability.
186-
- To build locally, install Rust:
204+
## Configuration
187205

188-
```sh
189-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
190-
```
206+
`config/code_ownership.yml` keys and defaults:
191207

192-
- Please update `CHANGELOG.md` and this `README.md` when making changes.
208+
- `owned_globs` (required): Glob patterns that must be owned.
209+
- `ruby_package_paths` (default: `['packs/**/*', 'components/**']`)
210+
- `js_package_paths` / `javascript_package_paths` (default: `['frontend/**/*']`)
211+
- `team_file_glob` (default: `['config/teams/**/*.yml']`)
212+
- `unowned_globs` (default: `['frontend/**/node_modules/**/*', 'frontend/**/__generated__/**/*']`)
213+
- `vendored_gems_path` (default: `'vendored/'`)
214+
- `cache_directory` (default: `'tmp/cache/codeowners'`)
215+
- `ignore_dirs` (default includes: `.git`, `node_modules`, `tmp`, etc.)
193216

194-
### Module layout (for library users)
217+
See examples in `tests/fixtures/**/config/` for reference setups.
195218

196-
- `src/runner.rs`: public façade re-exporting the API and types.
197-
- `src/runner/api.rs`: externally available functions used by the CLI and other crates.
198-
- `src/runner/types.rs`: `RunConfig`, `RunResult`, and runner `Error`.
199-
- `src/ownership/`: all ownership logic (parsing, mapping, validation, generation).
200-
- `src/ownership/codeowners_query.rs`: CODEOWNERS-only queries consumed by the façade.
219+
## Cache
201220

202-
Import public APIs from `codeowners::runner::*`.
221+
By default, cache is stored under `tmp/cache/codeowners` relative to the project root. This speeds up repeated runs.
203222

204-
### Library usage example
223+
- Disable cache for a run: add the global flag `--no-cache`
224+
- Clear all cache: `codeowners delete-cache`
225+
226+
## Validation
227+
228+
`codeowners validate` (or `codeowners gv`) ensures:
229+
230+
1. Only one mechanism defines ownership for any file.
231+
2. All referenced teams are valid.
232+
3. All files in `owned_globs` are owned, unless matched by `unowned_globs`.
233+
4. The generated `CODEOWNERS` file is up to date.
234+
235+
Exit status is non-zero on errors.
236+
237+
## Library Usage
238+
239+
Import public APIs from `codeowners::runner::*`.
205240

206241
```rust
207242
use codeowners::runner::{RunConfig, for_file, teams_for_files_from_codeowners};
@@ -231,3 +266,22 @@ fn main() {
231266
}
232267
}
233268
```
269+
270+
## Development
271+
272+
- Written in Rust for speed and reliability.
273+
- To build locally, install Rust:
274+
275+
```sh
276+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
277+
```
278+
279+
- Please update `CHANGELOG.md` and this `README.md` when making changes.
280+
281+
### Module layout
282+
283+
- `src/runner.rs`: public façade re-exporting the API and types.
284+
- `src/runner/api.rs`: externally available functions used by the CLI and other crates.
285+
- `src/runner/types.rs`: `RunConfig`, `RunResult`, and runner `Error`.
286+
- `src/ownership/`: all ownership logic (parsing, mapping, validation, generation).
287+
- `src/ownership/codeowners_query.rs`: CODEOWNERS-only queries consumed by the façade.

src/runner/api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub fn crosscheck_owners(run_config: &RunConfig) -> RunResult {
4040
run(run_config, |runner| runner.crosscheck_owners())
4141
}
4242

43+
// Returns the highest priority owner for a file. More to come here.
4344
pub fn file_owner_for_file(run_config: &RunConfig, file_path: &str) -> error_stack::Result<Option<FileOwner>, Error> {
4445
let runner = Runner::new(run_config)?;
4546
let owners = runner.owners_for_file(file_path)?;

0 commit comments

Comments
 (0)