mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-09 13:36:26 +00:00
feat(pre-commit): support python additional_dependencies (#33417)
This commit is contained in:
parent
147b620187
commit
59455c0512
6 changed files with 82 additions and 0 deletions
|
@ -13,11 +13,18 @@ repos:
|
|||
rev: 19.3b0
|
||||
hooks:
|
||||
- id: black
|
||||
language: python
|
||||
additional_dependencies:
|
||||
- "request==1.1.1"
|
||||
- "" # broken pypi package
|
||||
- repo: https://gitlab.com/psf/black
|
||||
# should also detect gitlab
|
||||
rev: 19.3b0
|
||||
hooks:
|
||||
- id: black
|
||||
# missing language, not extracted
|
||||
additional_dependencies:
|
||||
- "urllib==24.9.0"
|
||||
- repo: http://gitlab.com/psf/black
|
||||
# should also detect http
|
||||
rev: 19.3b0
|
||||
|
@ -48,3 +55,7 @@ repos:
|
|||
- repo: some_invalid_url
|
||||
# case with invlalid url.
|
||||
rev: v1.0.0
|
||||
|
||||
# pre-commit meta hooks
|
||||
- repo: meta
|
||||
hooks: []
|
||||
|
|
|
@ -10,6 +10,14 @@ exports[`modules/manager/pre-commit/extract extractPackageFile() extracts from c
|
|||
"depType": "repository",
|
||||
"packageName": "pre-commit/pre-commit-hooks",
|
||||
},
|
||||
{
|
||||
"currentValue": "==1.1.1",
|
||||
"currentVersion": "1.1.1",
|
||||
"datasource": "pypi",
|
||||
"depName": "request",
|
||||
"depType": "pre-commit-python",
|
||||
"packageName": "request",
|
||||
},
|
||||
{
|
||||
"currentValue": "19.3b0",
|
||||
"datasource": "github-tags",
|
||||
|
|
|
@ -2,6 +2,7 @@ import { mockDeep } from 'jest-mock-extended';
|
|||
import { Fixtures } from '../../../../test/fixtures';
|
||||
import { mocked } from '../../../../test/util';
|
||||
import * as _hostRules from '../../../util/host-rules';
|
||||
import { PypiDatasource } from '../../datasource/pypi';
|
||||
import { extractPackageFile } from '.';
|
||||
|
||||
jest.mock('../../../util/host-rules', () => mockDeep());
|
||||
|
@ -81,6 +82,14 @@ describe('modules/manager/pre-commit/extract', () => {
|
|||
expect(result).toMatchSnapshot({
|
||||
deps: [
|
||||
{ depName: 'pre-commit/pre-commit-hooks', currentValue: 'v3.3.0' },
|
||||
{
|
||||
currentValue: '==1.1.1',
|
||||
currentVersion: '1.1.1',
|
||||
datasource: PypiDatasource.id,
|
||||
depName: 'request',
|
||||
depType: 'pre-commit-python',
|
||||
packageName: 'request',
|
||||
},
|
||||
{ depName: 'psf/black', currentValue: '19.3b0' },
|
||||
{ depName: 'psf/black', currentValue: '19.3b0' },
|
||||
{ depName: 'psf/black', currentValue: '19.3b0' },
|
||||
|
|
|
@ -7,6 +7,7 @@ import { regEx } from '../../../util/regex';
|
|||
import { parseSingleYaml } from '../../../util/yaml';
|
||||
import { GithubTagsDatasource } from '../../datasource/github-tags';
|
||||
import { GitlabTagsDatasource } from '../../datasource/gitlab-tags';
|
||||
import { pep508ToPackageDependency } from '../pep621/utils';
|
||||
import type { PackageDependency, PackageFileContent } from '../types';
|
||||
import {
|
||||
matchesPrecommitConfigHeuristic,
|
||||
|
@ -137,6 +138,23 @@ function findDependencies(precommitFile: PreCommitConfig): PackageDependency[] {
|
|||
}
|
||||
const packageDependencies: PackageDependency[] = [];
|
||||
precommitFile.repos.forEach((item) => {
|
||||
// meta hooks is defined from pre-commit and doesn't support `additional_dependencies`
|
||||
if (item.repo !== 'meta') {
|
||||
item.hooks?.forEach((hook) => {
|
||||
// normally language are not defined in yaml
|
||||
// only support it when it's explicitly defined.
|
||||
// this avoid to parse hooks from pre-commit-hooks.yaml from git repo
|
||||
if (hook.language === 'python') {
|
||||
hook.additional_dependencies?.map((req) => {
|
||||
const dep = pep508ToPackageDependency('pre-commit-python', req);
|
||||
if (dep) {
|
||||
packageDependencies.push(dep);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (matchesPrecommitDependencyHeuristic(item)) {
|
||||
logger.trace(item, 'Matched pre-commit dependency spec');
|
||||
const repository = String(item.repo);
|
||||
|
|
|
@ -26,3 +26,33 @@ To enable the `pre-commit` manager, add the following config:
|
|||
```
|
||||
|
||||
Alternatively, add `:enablePreCommit` to your `extends` array.
|
||||
|
||||
### Additional Dependencies
|
||||
|
||||
renovate has partial support for `additional_dependencies`, currently python only.
|
||||
|
||||
for python hooks, you will need to **explicitly add language** to your hooks with `additional_dependencies`
|
||||
to let renovatebot know what kind of dependencies they are.
|
||||
|
||||
For example, this work for `request`:
|
||||
|
||||
```yaml
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 19.3b0
|
||||
hooks:
|
||||
- id: black
|
||||
language: python
|
||||
additional_dependencies:
|
||||
- 'request==1.1.1'
|
||||
```
|
||||
|
||||
this won't work:
|
||||
|
||||
```yaml
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 19.3b0
|
||||
hooks:
|
||||
- id: black
|
||||
additional_dependencies:
|
||||
- 'request==1.1.1'
|
||||
```
|
||||
|
|
|
@ -2,7 +2,13 @@ export interface PreCommitConfig {
|
|||
repos: PreCommitDependency[];
|
||||
}
|
||||
|
||||
export interface PreCommitHook {
|
||||
language?: string;
|
||||
additional_dependencies?: Array<string>;
|
||||
}
|
||||
|
||||
export interface PreCommitDependency {
|
||||
repo: string;
|
||||
hooks?: Array<PreCommitHook>;
|
||||
rev: string;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue