Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: API for generating codeowners files #13

Open
ThisIsMissEm opened this issue Aug 31, 2020 · 0 comments
Open

Feature: API for generating codeowners files #13

ThisIsMissEm opened this issue Aug 31, 2020 · 0 comments

Comments

@ThisIsMissEm
Copy link

ThisIsMissEm commented Aug 31, 2020

Hi!

I've recently been working on a project where I programmatically generate the codeowners file based on some configuration. So far, I've written a fairly simple class that gives an API to describe a codeowners file (rules, comments, and newlines), and I'm wondering if you'd like this contributed back?

I'm thinking more along the lines of parsing a CODEOWNERS file to a simple AST (see below), and then set of methods to work with that AST and a means to convert the AST to a CODEOWNERS file.

Example AST:

{
  type: 'rule' | 'comment' | 'newline'
  // For type == comment
  message?: string
  // For type == rule
  pattern: string
  owners: string[]
}

The Codeowners function would then change to:

// If options.read == true, then call Codeowners.prototype.readSync() followed by Codeowners.prototype.parse()
// options.read will default to true, as this closest resembles the existing behaviour
new Codeowners(currentPath, fileName = 'CODEOWNERS', options?: { read: true })
Codeowners.prototype.getOwner(filepath: string);

Codeowners.prototype.parse() // called by constructor

Codeowners.prototype.addComment(message?: string)
Codeowners.prototype.addRule(pattern: string, owners: string[])
Codeowners.prototype.addNewline()

Codeowners.prototype.toString() // output the current AST as a CODEOWNERS file

async Codeowners.prototype.read()
async Codeowners.prototype.write()

Codeowners.prototype.readSync()
Codeowners.prototype.writeSync()

Thoughts? This would allow programmatic management of CODEOWNERS files, we could also optionally do a breaking API change of:

new Codeowners(filepath: string, options?: { read: true });

Codeowners.discover(currentPath: string, filename = 'CODEOWNERS')

Such that existing code using the API would be:

- const owners = new Codeowners(workingDir);
+ const ownersFile = Codeowners.discover(workingDir);
+ const owners = new Codeowners(ownersFile, options?: { read: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant