add option to tweak programmatically the configuration
Opened this issue · 0 comments
raulfdm commented
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.