Coder Social home page Coder Social logo

raulfdm / codeowners-flow Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 462 KB

A tool to script and manage the CODEOWNERS file programmatically, simplifying code ownership rules and generating platform-compatible files.

Home Page: https://github.com/raulfdm/codeowners-flow

License: MIT License

TypeScript 91.81% JavaScript 7.81% Shell 0.39%
automation code-maintance code-ownership codeowners

codeowners-flow's Issues

Error calling the CLI

Description

After installing the CLI and trying to run, I got:

$ pnpm codeowners-flow     
node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/path/to/node_modules/.pnpm/@[email protected]/node_modules/@codeowners-flow/cli/dist/index.js' imported from /path/to/node_modules/.pnpm/@[email protected]/node_modules/@codeowners-flow/cli/bin/index.js
    at new NodeError (node:internal/errors:371:5)
    at finalizeResolution (node:internal/modules/esm/resolve:418:11)
    at moduleResolve (node:internal/modules/esm/resolve:981:10)
    at defaultResolve (node:internal/modules/esm/resolve:1078:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:530:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:251:18)
    at ESMLoader.import (node:internal/modules/esm/loader:332:22)
    at importModuleDynamically (node:internal/modules/esm/translators:106:35)
    at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)
    at file:///path/to/node_modules/.pnpm/@[email protected]/node_modules/@codeowners-flow/cli/bin/index.js:4:1 {
  code: 'ERR_MODULE_NOT_FOUND'
}

Checking the node_modules, it seems the dist folder isn't there ๐Ÿซ 

CleanShot 2023-08-16 at 09 36 11

Define config API

API config

Every project would include a codeowner.config.mjs. This file must default return an array of objects.

Each object should contain:

type OwnerRule = {
  pattern: string,
  excludeMatch?: string[],
  owners: string[],
  comments?: string[]
}

type CodeOwnerManager = {
  outDir: string;
  rules: OwnerRule[]
}

Example:

export default {
  outDir: ".github",
  rules: [
    {
      pattern: "*",
      owners: ["@company/core-team"],
      comments: [
        "Everything else will be fallback to @company/core-team to approve",
      ],
    },
  ],
};

This will lead to a .github/CODEOWNERS with the following content:

# Everything else will be fallback to @company/core-team to approve
* @company/core-team

add option to tweak programmatically the configuration

Description

The user should be allowed to extend the configuration programmatically. This will be handy for automation/scripting.

import { updateConfig, defineRule } from "@codeowners-flow/cli/config";

await updateConfig((currentConfig) => {
  currentConfig.rules = defineRule({
    patterns: ["module/logger"],
    owners: ["@company/infra"],
  });

  return currentConfig;
});

Because the user gets the current config, it might be useful to provide a field like _meta so they can add and maintain info in the config level but also have access, like:

// codeowners.config.mjs

const mainTeam = { name: '@company/core-team' };

/** @type {import('@codeowners-flow/cli/config').UserConfig} */
export default {
  outDir: '.github',
  _meta: {
    mainTeam, // HERE
  },
  rules: [
    {
      patterns: ['*'],
      owners: [mainTeam],
    },
  ],
};

Then:

import { updateConfig, defineRule } from "@codeowners-flow/cli/config";

await updateConfig((currentConfig) => {
  currentConfig.rules = defineRule({
    patterns: ["module/logger"],
    owners: ["@company/infra", currentConfig._meta.mainTeam], // CONSUMING HERE
  });

  return currentConfig;
});

I'm not sure how to make this type-safe, so it'll be the user's responsibility to ensure the value is there.

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.