#git-repository #codeowners #owner #file #validation #subcommand #query

app git-owners

A git subcommand to query and validate CODEOWNERS

5 stable releases

1.1.2 Oct 6, 2024
1.0.2 Oct 5, 2024
1.0.1 Oct 28, 2022
1.0.0 May 23, 2022

#627 in Filesystem

Download history 200/week @ 2024-08-21 213/week @ 2024-08-28 262/week @ 2024-09-04 344/week @ 2024-09-11 225/week @ 2024-09-18 306/week @ 2024-09-25 627/week @ 2024-10-02 511/week @ 2024-10-09 169/week @ 2024-10-16 133/week @ 2024-10-23 30/week @ 2024-10-30 5/week @ 2024-11-06 10/week @ 2024-11-13 106/week @ 2024-11-20 38/week @ 2024-11-27 32/week @ 2024-12-04

187 downloads per month

MIT license

14KB
164 lines

git-codeowners

A git subcommand to query and validate CODEOWNERS.

List owners of files based on the CODEOWNERS file of the current repository.

> git codeowners src/main.rs
src/main.rs                              @weyland
> git codeowners `git ls-files`
.gitignore                               (unowned)
Cargo.lock                               @weyland
Cargo.toml                               @weyland
LICENSE                                  (unowned)
README.md                                @weyland
src/main.rs                              @weyland
# Oops, did the last commit add unowned files?
> git diff --name-only --diff-filter=A | git codeowners
.gitignore                               @bob
LICENSE                                  (unowned)
# I need stats about my repo
> echo `git ls-files | git codeowners | grep "(unowned)"| wc -l` out of `git ls-files | git codeowners | wc -l` files in this repository do not have a corresponding CODEOWNERS entry
2 out of 6 files in this repository do not have a CODEOWNERS entry

Installation

  • via pip: pip install git-codeowners

  • via Cargo: cargo install git-owners

    Note: The Cargo crate installs an equivalent git-owners command in addition to git-codeowners, for backwards compatibility.

Usage

  • Show owner of a file

    git codeowners some/path
    
  • Show owners for a list of files

    git codeowners some/path some/other/path
    

Each path should be relative to the git repository root. This makes it easy to combine with other git commands:

  • Show owners for every tracked file in the repository

    git ls-files | git codeowners
    
  • Show owners for files modified in last five commits

    git diff --name-only HEAD~5 HEAD | git codeowners
    
  • Congratulate the user if the current changeset does not add files without owner

    git diff --diff-filter=ACR --name-only | git codeowners && echo "Great job! No unowned files added!"
    
  • Get an overview of your CODEOWNERS coverage

    echo `git ls-files | git codeowners | grep "(unowned)"| wc -l` out of `git ls-files | git codeowners | wc -l` files in this repository do not have a CODEOWNERS entry
    

Features

  • Detects the right CODEOWNERS file of the current git repository (CODEOWNERS, docs/CODEOWNERS, or .github/CODEOWNERS)
  • Works well as a pre-commit hook. Returns a non-zero exit code if unowned files are found
  • Is composable & scripting friendly
  • Is fast & written in Rust

Issues & Contributing

If you have any questions or problems, feel free to communicate using Github Issues.

Dependencies

~13–23MB
~350K SLoC