### Parse Team Metadata Source: https://github.com/noahm/codeowners/blob/main/README.md Example of a CODEOWNERS file section for team metadata. Lines starting with '##' are parsed into structured objects. ```shell ## team slack-channel engineering-manager jira-project-key ## @org/admins #project-admins @alice ADMIN ## @org/design #design @bob DESIGN ## @org/monetization #monetization-eng @charlie MONEY # ... regular codeowners file contents ... ``` -------------------------------- ### Roll Up Unowned Files by Depth (CLI) Source: https://context7.com/noahm/codeowners/llms.txt Use `codeowners audit --unowned --min-depth N` to list common parent directories of unowned files, starting from a minimum depth N. This helps identify unowned directories. ```bash # Roll up unowned files to common paths (min depth 2) $ codeowners audit --unowned --min-depth 2 config scripts ``` -------------------------------- ### Get Owners of Multiple Files (CLI) Source: https://context7.com/noahm/codeowners/llms.txt Use the `codeowners of` command with multiple file arguments to retrieve owners for each specified file. Each file and its owner(s) are listed on a new line. ```bash # Get owners of multiple files $ codeowners of src/api.js tests/api.test.js README.md src/api.js @backend-team tests/api.test.js @qa-team README.md @docs-team ``` -------------------------------- ### Get Owner of a Single File (CLI) Source: https://context7.com/noahm/codeowners/llms.txt Use the `codeowners of` command to find the owner(s) of a specific file from the command line. Output includes the filename and its assigned owner(s). ```bash # Get owner of a single file $ codeowners of src/index.ts src/index.ts @frontend-team ``` -------------------------------- ### Get Paths for a Specific Owner Source: https://context7.com/noahm/codeowners/llms.txt Use getPathsForOwner to find all path patterns associated with a given owner (username or team). This is useful for auditing responsibilities. Returns an empty array if the owner is not found. ```javascript import Codeowners from '@nmann/codeowners'; const owners = new Codeowners(); // Get all paths owned by a team const teamPaths = owners.getPathsForOwner('@frontend-team'); console.log(teamPaths); // ['src/components/*', 'src/pages/*', '*.tsx'] // Get paths for an individual const userPaths = owners.getPathsForOwner('@alice'); console.log(userPaths); // ['docs/*', 'README.md'] // Returns empty array for unknown owners const unknownPaths = owners.getPathsForOwner('@nonexistent'); console.log(unknownPaths); // [] ``` -------------------------------- ### Get Owners for a File Source: https://context7.com/noahm/codeowners/llms.txt Retrieve the owners for a given file path using the getOwner method. The method respects the CODEOWNERS specification where the last matching pattern takes precedence. Returns an empty array if no owners are found. ```javascript import Codeowners from '@nmann/codeowners'; const owners = new Codeowners(); // Get owners for a specific file const fileOwners = owners.getOwner('src/components/Button.tsx'); console.log(fileOwners); // ['@frontend-team', '@design-team'] // Returns empty array if no owners match const unownedFile = owners.getOwner('random/untracked/file.txt'); console.log(unownedFile); // [] // Works with any path format const apiOwners = owners.getOwner('api/endpoints/users.js'); console.log(apiOwners); // ['@api-team'] ``` -------------------------------- ### Initialize Codeowners Library Source: https://github.com/noahm/codeowners/blob/main/README.md Import and instantiate the Codeowners class. Optionally provide a root directory path. Use getOwner to retrieve owners for a specific file path. ```javascript import Codeowners from '@nmann/codeowners'; // defaults to process.cwd(), but can pass a different directory path to constructor const owners = new Codeowners(optionalRootDir); owners.getOwner('path/to/file.js'); // returns array of owners, e.g. ['@noahm'] ``` -------------------------------- ### Verify Multiple Potential Owners (CLI) Source: https://context7.com/noahm/codeowners/llms.txt Provide multiple owner arguments to `codeowners verify` to check if any of the specified owners match the ownership rules for the given path. The first matching owner is displayed. ```bash # Verify multiple potential owners $ codeowners verify api/ @backend-team @platform-team api/ @backend-team ``` -------------------------------- ### CLI: Specify CODEOWNERS Filename Source: https://github.com/noahm/codeowners/blob/main/README.md Use the '-c' or '--config' flag to specify a non-standard filename for the CODEOWNERS file. ```shell $ codeowners audit -c CODEKEEPERS ``` -------------------------------- ### List All Files with Owners (CLI) Source: https://context7.com/noahm/codeowners/llms.txt Run `codeowners audit` without flags to list all files in the repository along with their assigned owners. Output is formatted with filename padding for readability. ```bash # List all files with their owners $ codeowners audit src/index.ts @frontend-team src/api/users.js @backend-team README.md @docs-team ``` -------------------------------- ### CLI: Audit Unowned Files Source: https://github.com/noahm/codeowners/blob/main/README.md Use the '--unowned' flag with 'codeowners audit' to find files not covered by the CODEOWNERS file. ```shell $ codeowners audit --unowned ``` -------------------------------- ### Initialize Codeowners Parser Source: https://context7.com/noahm/codeowners/llms.txt Instantiate the Codeowners class to parse CODEOWNERS files. It can automatically detect files or use a specified path and filename. Access parsed file paths and directory information after initialization. ```javascript import Codeowners from '@nmann/codeowners'; // Use current working directory (default) const owners = new Codeowners(); // Use a specific project directory const owners = new Codeowners('/path/to/project'); // Use a custom CODEOWNERS filename const owners = new Codeowners('/path/to/project', 'CODEKEEPERS'); // Access parsed properties console.log(owners.codeownersFilePath); // '/path/to/project/.github/CODEOWNERS' console.log(owners.codeownersDirectory); // '/path/to/project' console.log(owners.contactInfo); // Array of team metadata objects ``` -------------------------------- ### CLI: Audit File Ownership Source: https://github.com/noahm/codeowners/blob/main/README.md Run 'codeowners audit' to list all files in the repository and their respective owners. ```shell $ codeowners audit ``` -------------------------------- ### Codeowners Class Constructor Source: https://context7.com/noahm/codeowners/llms.txt Initializes the Codeowners class, which automatically locates and parses the CODEOWNERS file from standard project locations. It can also be configured to use a specific project directory or a custom CODEOWNERS filename. ```APIDOC ## Codeowners Class Constructor The main class for parsing and querying CODEOWNERS files. It automatically locates and parses the CODEOWNERS file from standard locations, building an index of ownership rules and optional team metadata. ### Usage ```javascript import Codeowners from '@nmann/codeowners'; // Use current working directory (default) const owners = new Codeowners(); // Use a specific project directory const owners = new Codeowners('/path/to/project'); // Use a custom CODEOWNERS filename const owners = new Codeowners('/path/to/project', 'CODEKEEPERS'); // Access parsed properties console.log(owners.codeownersFilePath); // '/path/to/project/.github/CODEOWNERS' console.log(owners.codeownersDirectory); // '/path/to/project' console.log(owners.contactInfo); // Array of team metadata objects ``` ``` -------------------------------- ### List Orphaned CODEOWNERS Entries (CLI) Source: https://context7.com/noahm/codeowners/llms.txt Use `codeowners orphans` to identify entries in the CODEOWNERS file that do not match any files currently present in the repository. This helps in cleaning up stale rules. ```bash # Find orphaned entries $ codeowners orphans legacy/removed-module/* [ '@legacy-team' ] old-api/*.js [ '@deprecated-team', '@alice' ] ``` -------------------------------- ### CLI: Verify Path Ownership Source: https://github.com/noahm/codeowners/blob/main/README.md Use the 'codeowners verify' command to check if specific users or teams own a given path. ```shell $ codeowners verify src/ @foob_ar @contoso/engineers ``` -------------------------------- ### Use Custom CODEOWNERS Filename for Orphans (CLI) Source: https://context7.com/noahm/codeowners/llms.txt Specify a custom filename for the CODEOWNERS file when running `codeowners orphans` using the `-c` or `--config` flag. ```bash # Use custom CODEOWNERS filename $ codeowners orphans -c CODEKEEPERS ``` -------------------------------- ### Verify Ownership Failure (CLI) Source: https://context7.com/noahm/codeowners/llms.txt When `codeowners verify` is used with owners that do not match the path's CODEOWNERS rules, it prints an error message and exits with status code 1. ```bash # Fails if no specified owner matches $ codeowners verify src/ @wrong-team None of the users/teams specified own the path src/ $ echo $? ``` ```bash 1 ``` -------------------------------- ### CLI: Find Owners of Files Source: https://github.com/noahm/codeowners/blob/main/README.md Use the 'codeowners of' command to find the owner(s) for specified file paths. ```shell $ codeowners of some/file.ts [...otherfiles] ``` -------------------------------- ### Verify Team Ownership of a Path (CLI) Source: https://context7.com/noahm/codeowners/llms.txt Use `codeowners verify ` to check if a specified team or user owns a given path. The command exits with a non-zero status code if the owner does not match. ```bash # Verify a team owns a path $ codeowners verify src/ @frontend-team src/ @frontend-team ``` -------------------------------- ### Use Custom CODEOWNERS Filename (CLI) Source: https://context7.com/noahm/codeowners/llms.txt Specify a custom filename for the CODEOWNERS file when running `codeowners audit` using the `-c` or `--config` flag. ```bash # Use a custom CODEOWNERS filename $ codeowners audit -c CODEKEEPERS ``` -------------------------------- ### getOwner(filePath) Source: https://context7.com/noahm/codeowners/llms.txt Retrieves an array of owners (usernames or team names) for a specified file path. The method adheres to the CODEOWNERS specification by matching patterns in reverse order, ensuring the last matching pattern takes precedence. ```APIDOC ## getOwner(filePath) Returns an array of owners (usernames or team names) for a given file path. The method matches against CODEOWNERS patterns in reverse order, as the last matching pattern takes precedence according to CODEOWNERS specification. ### Usage ```javascript import Codeowners from '@nmann/codeowners'; const owners = new Codeowners(); // Get owners for a specific file const fileOwners = owners.getOwner('src/components/Button.tsx'); console.log(fileOwners); // ['@frontend-team', '@design-team'] // Returns empty array if no owners match const unownedFile = owners.getOwner('random/untracked/file.txt'); console.log(unownedFile); // [] // Works with any path format const apiOwners = owners.getOwner('api/endpoints/users.js'); console.log(apiOwners); // ['@api-team'] ``` ``` -------------------------------- ### Customize Filename Padding (CLI) Source: https://context7.com/noahm/codeowners/llms.txt Adjust the output padding for filenames in `codeowners audit` using the `--width` option, specifying the desired width in characters. ```bash # Customize filename padding width $ codeowners audit --width 50 ``` -------------------------------- ### Find Orphaned CODEOWNERS Entries Source: https://context7.com/noahm/codeowners/llms.txt Identify entries in the CODEOWNERS file that do not match any existing files in the repository using getOrphanedEntries. This helps in maintaining a clean and accurate ownership configuration. ```javascript import Codeowners from '@nmann/codeowners'; const owners = new Codeowners(); // Find orphaned entries const orphans = owners.getOrphanedEntries(); for (const entry of orphans) { console.log(`Orphaned: ${entry.path} (assigned to ${entry.usernames.join(', ')})`); } // Output: // Orphaned: legacy/old-module/* (assigned to @legacy-team) // Orphaned: deprecated/*.js (assigned to @alice) ``` -------------------------------- ### getPathsForOwner(owner) Source: https://context7.com/noahm/codeowners/llms.txt Returns an array of all path patterns assigned to a specific owner. This method is useful for understanding the scope of responsibility for a team or individual within the codebase. ```APIDOC ## getPathsForOwner(owner) Returns an array of all path patterns assigned to a specific owner. Useful for understanding what areas of the codebase a team or individual is responsible for. ### Usage ```javascript import Codeowners from '@nmann/codeowners'; const owners = new Codeowners(); // Get all paths owned by a team const teamPaths = owners.getPathsForOwner('@frontend-team'); console.log(teamPaths); // ['src/components/*', 'src/pages/*', '*.tsx'] // Get paths for an individual const userPaths = owners.getPathsForOwner('@alice'); console.log(userPaths); // ['docs/*', 'README.md'] // Returns empty array for unknown owners const unknownPaths = owners.getPathsForOwner('@nonexistent'); console.log(unknownPaths); // [] ``` ``` -------------------------------- ### Parse Team Metadata from CODEOWNERS Source: https://context7.com/noahm/codeowners/llms.txt Instantiate the Codeowners class to parse extended team metadata from CODEOWNERS files. Access the parsed contact information via the `contactInfo` property. Useful for retrieving team contact details like slack channels or manager assignments. ```javascript import Codeowners from '@nmann/codeowners'; // CODEOWNERS file content: // ## team slack-channel engineering-manager jira-project-key // ## @org/admins #project-admins @alice ADMIN // ## @org/design #design @bob DESIGN // ## @org/backend #backend-eng @charlie BACKEND // // src/* @org/backend // design/* @org/design const owners = new Codeowners(); // Access parsed contact info console.log(owners.contactInfo); // [ // { team: '@org/admins', 'slack-channel': '#project-admins', 'engineering-manager': '@alice', 'jira-project-key': 'ADMIN' }, // { team: '@org/design', 'slack-channel': '#design', 'engineering-manager': '@bob', 'jira-project-key': 'DESIGN' }, // { team: '@org/backend', 'slack-channel': '#backend-eng', 'engineering-manager': '@charlie', 'jira-project-key': 'BACKEND' } // ] // Look up contact info for file owners const fileOwners = owners.getOwner('src/api/users.js'); // ['@org/backend'] const teamInfo = owners.contactInfo.find(info => info.team === fileOwners[0]); console.log(`Contact ${teamInfo['slack-channel']} for questions`); // 'Contact #backend-eng for questions' ``` -------------------------------- ### getOrphanedEntries() Source: https://context7.com/noahm/codeowners/llms.txt Identifies and returns CODEOWNERS entries that do not match any files in the repository. This function is valuable for maintaining a clean and accurate CODEOWNERS file by flagging stale ownership rules. ```APIDOC ## getOrphanedEntries() Returns an array of CODEOWNERS entries that don't match any files in the repository. Useful for cleaning up stale ownership rules when files have been moved or deleted. ### Usage ```javascript import Codeowners from '@nmann/codeowners'; const owners = new Codeowners(); // Find orphaned entries const orphans = owners.getOrphanedEntries(); for (const entry of orphans) { console.log(`Orphaned: ${entry.path} (assigned to ${entry.usernames.join(', ')})`); } // Output: // Orphaned: legacy/old-module/* (assigned to @legacy-team) // Orphaned: deprecated/*.js (assigned to @alice) ``` ``` -------------------------------- ### Parsed Team Metadata Structure Source: https://github.com/noahm/codeowners/blob/main/README.md The parsed team metadata is available as an array of objects on the 'contactInfo' field of a Codeowners instance. ```javascript [ { team: '@org/admins', 'slack-channel': '#project-admins', 'engineering-manager': '@alice', 'jira-project-key': 'ADMIN', }, { team: '@org/design', 'slack-channel': '#design', 'engineering-manager': '@bob', 'jira-project-key': 'DESIGN', }, { team: '@org/monetization', 'slack-channel': '#monetization-eng', 'engineering-manager': '@charlie', 'jira-project-key': 'MONEY', }, ]; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.