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

add option to tweak programmatically the configuration #31

Open
raulfdm opened this issue Aug 15, 2023 · 0 comments · May be fixed by #32
Open

add option to tweak programmatically the configuration #31

raulfdm opened this issue Aug 15, 2023 · 0 comments · May be fixed by #32

Comments

@raulfdm
Copy link
Owner

raulfdm commented Aug 15, 2023

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.

@raulfdm raulfdm linked a pull request Aug 16, 2023 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant