Coder Social home page Coder Social logo

coscribe's Introduction

Coscribe

About

This package provides commands to generate and update CODEOWNERS file entries. Currently, this is done by invoking shell commands with shelljs.

Each git-tracked file (that does not have preset pattern in the configuration file) will be examined for authors via the git blame --porcelain shell command (We define the author-mail field output by the git blame --porcelain command as an author here). All authors will added as owners for that file in CODEOWNERS. Note that if no authors are resolved for a file or pattern, it will be omitted as a CODEOWNERS entry.

Configuration (coscribe.yml | coscribe.yaml)

A configuration file can be optionally provided (coscribe.yaml or coscribe.yml) to override some behavior. Commands will, by default, look for this file in the directory where they were invoked. See Usage

# The relative path to the CODEOWNERS file.
# If not defined, default to the current directory where the command is invoked
codeOwnersFile: <relativePathtoCodeOwnersFile>

# During examination of a file, if an author is in the set of keys
# in this configuration, the command will remap it to the value.
authorRemap:
    '[email protected]': '[email protected]'
    '[email protected]': '[email protected]'
    # ...

# During examination of a file, if an author is in this set,
# the author will be omitted from any set of authors.
omittedAuthors:
    - '[email protected]'
    - '[email protected]'
    # ...

# These items will be converted into entries and added to the CODEOWNERS file first.
# Any file that matches any of these patterns will be omitted.
# Patterns need to be well-formed relative to the CODEOWNER rules.
presetDirectories:
    # Will convert to in CODEOWNERS file: `pattern1 author1`
    'pattern1':
        - 'author1'
    # Will convert to in CODEOWNERS file: `pattern2 author1 author2`
    'pattern2':
        - 'author1'
        - 'author2'
    # Will convert to in CODEOWNERS file: `pattern3  author2`
    'pattern3':
        - 'author2'
    # ...

# These items will be converted into entries and added to the CODEOWNERS file
# instead the entries that would have resolved from the examination process.
# These items are not patterns, just relative-path'ed files
presetFiles:
    'file1.txt':
        - 'author1'
        - 'author2'
        - 'author3'
    'a/b/c.json':
        - 'author1'
        - 'author5'
        - 'author6'
    # ...

# These pattern items will be used to filter out entries.
omittedPatterns:
    - file1.json
    - a/d/e.cpp
    # ...

Installation

Install it globally on your system.

> yarn add global coscribe

Install locally in a project

> yarn add coscribe

Usage

Run this command in the root directory of a git project. Once installed, there are two commands that can be invoked, Generate, and Update. Both commands use the currently checked out git branch.

When installed globally, you can invoke the help command with:

> coscribe -h

Or, when installed locally:

> ./node_modules/.bin/coscribe -h

Both should provide the following output

Usage: coscribe [options] [command]

Options:
  -h, --help                      display help for command

Commands:
  generate [options]              Generate code owners file
  update [options] <base-branch>  Update code owners file
  help [command]                  display help for command

Generate

When installed globally, you can invoke the help command with:

> coscribe generate -h

Or, when installed locally:

> ./node_modules/.bin/coscribe generate -h

Both should provide the following output

Usage: coscribe generate [options]

Generate code owners file

Options:
  --coscribe-file <coscribeFile>  Provide another (relative path from command execution dir) location for the config file (default: "coscribe")
  -h, --help                    display help for command

To invoke the command when installed globally:

> coscribe generate

Or, locally:

> ./node_modules/.bin/coscribe generate

Update

When installed globally, you can invoke the help command with:

> coscribe update -h

Or, when installed locally:

> ./node_modules/.bin/coscribe update -h

Both should provide the following output

Usage: coscribe update [options] <base-branch>

Update code owners file

Arguments:
  base-branch                   The base branch used for the comparison of changes

Options:
  [target-branch]               The target branch used for comparison of changes
  --coscribe-file <coscribeFile>  Provide another (relative path from command execution dir) location for the config file (default: "coscribe")
  -h, --help                    display help for command

If you want to use the currently checked out branch to derive the entry changes, relative to a base branch, Invoke the command in the following manner when the package was installed globally:

> coscribe update base-branch-name

Or when it was installed locally

> ./node_modules/.bin/coscribe update base-branch-name

If you don't want to use the currently checked out branch to derive the entry changes, relative to a base branch, Invoke the command in the following manner when the package was installed globally:

> coscribe update base-branch-name target-branch

Or when it was installed locally

> ./node_modules/.bin/coscribe update base-branch-name target-branch

Dependencies

The following OS command line programs are required to run the commands:

  • git
  • tr
  • sort
  • grep
  • sed
  • awk

Environments

This package has been tested on the following software versions

OS node git sort grep sed awk tr
Mac OS Version 13.3.1 v19.9.0 git version 2.39.2 (Apple Git-143) 2.3-Apple (154) grep (BSD grep, GNU compatible) 2.6.0-FreeBSD PROJECT:text_cmds-154 awk version 20200816 PROJECT:text_cmds-154

TODO

  • better validation throughout the process
  • Adapter for nodegit
  • More strategies to create file entries
  • testing

coscribe's People

Contributors

omizzy avatar

Stargazers

Frederick Stark avatar

Watchers

 avatar

coscribe's Issues

Crash when processing file with spaces or special chars

Hi there, thanks for creating coscribe! It looks like it has a lot of promise :D

I've run into a crash for files with spaces (and brackets) in the filename.
I've worked around it by adding the problematic folder to presetDirectories so it skips autogeneration.

Here's the terminal output:

Progress ██████████████████████████░░░░░░░░░░░░░░ | 64% | 2351/3636 Files | Skip: No authors resolved for file public/assets/motivations-characters/WA3.svg
Error: Command failed `git blame --porcelain public/assets/motivations/bubble-color/Achievement (bubble).svg | grep -a author-mail | grep -v 'not.committed.yet' | sed 's/<//g; s/>//g' | awk '{print $2}' | sort -u | tr '\n' ' '`

It looks to me like shelljs doesn't do any escaping before executing a command in the shell.

I also did a quick test editing the authorsCommand to git blame --porcelain '${file}' (ie. putting single quotes around the file) and that solved the issue too.
I'm not a shell expert so unsure if that has any other implications.

Happy to put this in a PR if you'd like, the change is pretty minimal so feels unnecessary to create a PR for it

Idea: Assign top n file authors instead of all

I've been running coscribe against a decent size codebase that's been around for a few years with a not small number of authors.
For my use case, the default settings result in a very long list of owners for the files

I've been playing around with the authorsCommand and I'm getting good results limiting authors using this command:

const authorsCommand = `git log --format='%aE' --no-merges -- '${file}' | sort | uniq -c | sort -rn | head -n ${maxAuthors} | awk '{print $2}' | tr '\n' ' '`;

Using maxAuthors to limit the owners.

Definitely has some limitations. For example the omittedAuthors are only applied after this limit resulting in fewer or no owners (probably easier to move the limit to getAutogeneratedFileEntry instead of the shell command).

No idea if this is desired — especially since I haven't thought about the automated updating use-case — but thought I would throw this your way anyway

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.