diff --git a/lib/manager/pre-commit/extract.spec.ts b/lib/manager/pre-commit/extract.spec.ts index d2fa9d17ab73fa25d5c6a3c79c9445ea175ae297..d537a9392e922064113b127b3937d5446d514b22 100644 --- a/lib/manager/pre-commit/extract.spec.ts +++ b/lib/manager/pre-commit/extract.spec.ts @@ -6,6 +6,8 @@ import { extractPackageFile } from './extract'; jest.mock('../../util/host-rules'); const hostRules = mocked(_hostRules); +const filename = '.pre-commit.yaml'; + const complexPrecommitConfig = readFileSync( 'lib/manager/pre-commit/__fixtures__/complex.pre-commit-config.yaml', 'utf8' @@ -42,45 +44,45 @@ describe('lib/manager/precommit/extract', () => { jest.resetAllMocks(); }); it('returns null for invalid yaml file content', () => { - const result = extractPackageFile('nothing here: ['); + const result = extractPackageFile('nothing here: [', filename); expect(result).toBeNull(); }); it('returns null for empty yaml file content', () => { - const result = extractPackageFile(''); + const result = extractPackageFile('', filename); expect(result).toBeNull(); }); it('returns null for no file content', () => { - const result = extractPackageFile(null); + const result = extractPackageFile(null, filename); expect(result).toBeNull(); }); it('returns null for no repos', () => { - const result = extractPackageFile(noReposPrecommitConfig); + const result = extractPackageFile(noReposPrecommitConfig, filename); expect(result).toBeNull(); }); it('returns null for empty repos', () => { - const result = extractPackageFile(emptyReposPrecommitConfig); + const result = extractPackageFile(emptyReposPrecommitConfig, filename); expect(result).toBeNull(); }); it('returns null for invalid repo', () => { - const result = extractPackageFile(invalidRepoPrecommitConfig); + const result = extractPackageFile(invalidRepoPrecommitConfig, filename); expect(result).toBeNull(); }); it('extracts from values.yaml correctly with same structure as "pre-commit sample-config"', () => { - const result = extractPackageFile(examplePrecommitConfig); + const result = extractPackageFile(examplePrecommitConfig, filename); expect(result).toMatchSnapshot(); }); it('extracts from complex config file correctly', () => { - const result = extractPackageFile(complexPrecommitConfig); + const result = extractPackageFile(complexPrecommitConfig, filename); expect(result).toMatchSnapshot(); }); it('can handle private git repos', () => { hostRules.find.mockReturnValue({ token: 'value' }); - const result = extractPackageFile(enterpriseGitPrecommitConfig); + const result = extractPackageFile(enterpriseGitPrecommitConfig, filename); expect(result).toMatchSnapshot(); }); it('can handle invalid private git repos', () => { hostRules.find.mockReturnValue({}); - const result = extractPackageFile(enterpriseGitPrecommitConfig); + const result = extractPackageFile(enterpriseGitPrecommitConfig, filename); expect(result).toMatchSnapshot(); }); it('can handle unknown private git repos', () => { @@ -88,7 +90,7 @@ describe('lib/manager/precommit/extract', () => { hostRules.find.mockReturnValueOnce({ token: 'value' }); // But all subsequent checks (those with hostType), then fail: hostRules.find.mockReturnValue({}); - const result = extractPackageFile(enterpriseGitPrecommitConfig); + const result = extractPackageFile(enterpriseGitPrecommitConfig, filename); expect(result).toMatchSnapshot(); }); }); diff --git a/lib/manager/pre-commit/extract.ts b/lib/manager/pre-commit/extract.ts index e49eaa1dadffc9e5825ce45b4a7849407d3daefe..a641908a3c5a512e9778385260ea6fc6f45fc1b9 100644 --- a/lib/manager/pre-commit/extract.ts +++ b/lib/manager/pre-commit/extract.ts @@ -150,30 +150,39 @@ function findDependencies( return packageDependencies; } -export function extractPackageFile(content: string): PackageFile | null { +export function extractPackageFile( + content: string, + filename: string +): PackageFile | null { let parsedContent: Record<string, unknown> | PreCommitConfig; try { parsedContent = yaml.safeLoad(content, { json: true }) as any; } catch (err) { - logger.debug({ err }, 'Failed to parse pre-commit config YAML'); + logger.debug({ filename, err }, 'Failed to parse pre-commit config YAML'); return null; } if (!is.plainObject<Record<string, unknown>>(parsedContent)) { - logger.warn(`Parsing of pre-commit config YAML returned invalid result`); + logger.warn( + { filename }, + `Parsing of pre-commit config YAML returned invalid result` + ); return null; } if (!matchesPrecommitConfigHeuristic(parsedContent)) { - logger.info(`File does not look like a pre-commit config file`); + logger.debug( + { filename }, + `File does not look like a pre-commit config file` + ); return null; } try { const deps = findDependencies(parsedContent); if (deps.length) { - logger.debug({ deps }, 'Found dependencies in pre-commit config'); + logger.trace({ deps }, 'Found dependencies in pre-commit config'); return { deps }; } } catch (err) /* istanbul ignore next */ { - logger.error({ err }, 'Error scanning parsed pre-commit config'); + logger.error({ filename, err }, 'Error scanning parsed pre-commit config'); } return null; }