renovate icon indicating copy to clipboard operation
renovate copied to clipboard

Add a function to allow dynamic configuration of managers based on repository data

Open secustor opened this issue 8 months ago • 0 comments

Discussed in https://github.com/renovatebot/renovate/discussions/29792

Originally posted by secustor June 21, 2024

Tell us more.

From time to time we have the use case to enable managers instead of another one based on e.g. the presence of a file.

The most recent case is this https://github.com/renovatebot/renovate/discussions/29786#discussioncomment-9836728

The manager interfaces would get a new optional field preflight which provides the ability to add functions/methods which are run before the extraction.

export interface ManagerApi extends ModuleApi {
  defaultConfig: Record<string, unknown>;

  categories?: Category[];
  supportsLockFileMaintenance?: boolean;
  supersedesManagers?: string[];
  supportedDatasources: string[];

+preflight?(): ((RenovateConfig) => RenovateConfig)[]

  extractPackageFile?(
    content: string,
    packageFile?: string,
    config?: ExtractConfig,
  ): Result<PackageFileContent | null>;
...

That way we can provide dynamic configuration based on the state of the repository and we can pull logic from the extractAllPackagesFiles.

Specific to the use case above. We would check if dot files contain OpenTofu references instead of Terraform and then configure the Terraform manager accordingly.

Other possibilities are the split up of managers which handle multiple package manager but should not be run in parallel. e.g. npm or pep621

secustor avatar Jun 23 '24 07:06 secustor