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

feat(config): Support presets in subdirectories #8724

Merged
merged 40 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
213f7cf
Support presets in subdirectories
ArmaanT Feb 16, 2021
a9ca935
Fix custom endpoint tests
ArmaanT Feb 16, 2021
54ac513
Fix local parsing
ArmaanT Feb 16, 2021
818a672
Merge branch 'master' into feat/8674-preset-subdirectories
rarkins Feb 18, 2021
a204584
refactor: pass versioning to getUpdateType
rarkins Feb 18, 2021
d052984
refactor: UpdateTypeConfig
rarkins Feb 18, 2021
ebd727f
chore(deps): update dependency @types/cacache to v15 (#8756)
renovate[bot] Feb 18, 2021
21c3b86
docs: update references to renovate/renovate (#8757)
renovate[bot] Feb 18, 2021
42a3249
refactor: remove superfluous valid check
rarkins Feb 18, 2021
4662518
refactor: fixedVersion calculation
rarkins Feb 18, 2021
8362c7a
feat(datasource): Normalize releaseTimestamp field (#8753)
zharinov Feb 18, 2021
a01029f
feat(gomod): do not shorten depName (#8758)
viceice Feb 18, 2021
e45c672
chore(deps): update dependency @types/fs-extra to v9.0.7 (#8764)
renovate[bot] Feb 19, 2021
ccedce1
chore(deps): update dependency @types/graceful-fs to v4.1.5 (#8765)
renovate[bot] Feb 19, 2021
5cfcebe
build(deps): update dependency crypto-random-string to v3.3.1 (#8766)
renovate[bot] Feb 19, 2021
10e850b
feat: matchFiles (#8769)
rarkins Feb 19, 2021
23d8ce4
build(deps): update dependency semantic-release to v17.3.9 (#8781)
renovate[bot] Feb 20, 2021
4533aa9
feat: per-file vulnerability alerts (#8770)
rarkins Feb 20, 2021
4699b42
feat(internal): repository cache revision (#8782)
rarkins Feb 20, 2021
e815aa0
feat: matchFiles + lockFiles (#8783)
rarkins Feb 20, 2021
0456f5a
fix: use small delay before posting branch status to gitlab (#8759) (…
bobvandevijver Feb 20, 2021
043133f
Validate configs
ArmaanT Feb 20, 2021
1c2dfa3
Fix top-level parsing
ArmaanT Feb 20, 2021
4c2d155
Merge remote-tracking branch 'upstream/master' into feat/8674-preset-…
ArmaanT Feb 20, 2021
d085cbb
Add additional test
ArmaanT Feb 21, 2021
d5b49e2
Merge branch 'master' into feat/8674-preset-subdirectories
viceice Feb 23, 2021
9c4ed91
Merge branch 'master' into feat/8674-preset-subdirectories
rarkins Feb 24, 2021
b60a069
Merge branch 'master' into feat/8674-preset-subdirectories
rarkins Feb 28, 2021
fb12e59
Add bitbucket
ArmaanT Mar 1, 2021
a8b786d
Fix tests
ArmaanT Mar 1, 2021
43eba23
Add additional path test for bitbucket
ArmaanT Mar 1, 2021
84a4418
Merge remote-tracking branch 'upstream/master' into feat/8674-preset-…
ArmaanT Mar 5, 2021
bc2c95b
Modify regex
ArmaanT Mar 5, 2021
c674cdb
Add additional test
ArmaanT Mar 5, 2021
6e7d914
Merge branch 'master' into feat/8674-preset-subdirectories
viceice Mar 9, 2021
dc990d8
Update lib/config/presets/index.ts
viceice Mar 9, 2021
827203a
Add note to table
ArmaanT Mar 14, 2021
d41e15e
Merge remote-tracking branch 'upstream/master' into feat/8674-preset-…
ArmaanT Mar 15, 2021
15518e8
Merge branch 'master' into feat/8674-preset-subdirectories
rarkins Mar 20, 2021
b79052a
Merge branch 'master' into feat/8674-preset-subdirectories
ArmaanT Mar 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions docs/usage/config-presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ In order to achieve these goals, preset configs allow for a very modular approac
In general, GitHub, GitLab or Gitea-based preset hosting is easier than npm because you avoid the "publish" step - simply commit preset code to the default branch and it will be picked up by Renovate the next time it runs.
An additional benefit of using source code hosting is that the same token/authentication can be reused by Renovate in case you want to make your config private.

| name | example use | preset | resolves as | filename |
| ----------------------- | -------------------- | --------- | ------------------------------------ | --------------------------------- |
| GitHub default | `github>abc/foo` | `default` | `https://github.com/abc/foo` | `default.json` or `renovate.json` |
| GitHub with preset name | `github>abc/foo:xyz` | `xyz` | `https://github.com/abc/foo` | `xyz.json` |
| GitLab default | `gitlab>abc/foo` | `default` | `https://gitlab.com/abc/foo` | `default.json` or `renovate.json` |
| GitLab with preset name | `gitlab>abc/foo:xyz` | `xyz` | `https://gitlab.com/abc/foo` | `xyz.json` |
| Gitea default | `gitea>abc/foo` | `default` | `https://gitea.com/abc/foo` | `default.json` or `renovate.json` |
| Gitea with preset name | `gitea>abc/foo:xyz` | `xyz` | `https://gitea.com/abc/foo` | `xyz.json` |
| Local default | `local>abc/foo` | `default` | `https://github.company.com/abc/foo` | `default.json` or `renovate.json` |
| name | example use | preset | resolves as | filename |
| ----------------------- | -------------------------- | --------- | ------------------------------------ | --------------------------------- |
| GitHub default | `github>abc/foo` | `default` | `https://github.com/abc/foo` | `default.json` or `renovate.json` |
| GitHub with preset name | `github>abc/foo:xyz` | `xyz` | `https://github.com/abc/foo` | `xyz.json` |
| GitHub with preset path | `github>abc/foo//path/xyz` | `xyz` | `https://github.com/abc/foo` | `path/xyz.json` |
viceice marked this conversation as resolved.
Show resolved Hide resolved
| GitLab default | `gitlab>abc/foo` | `default` | `https://gitlab.com/abc/foo` | `default.json` or `renovate.json` |
| GitLab with preset name | `gitlab>abc/foo:xyz` | `xyz` | `https://gitlab.com/abc/foo` | `xyz.json` |
| GitLab with preset path | `gitlab>abc/foo//path/xyz` | `xyz` | `https://gitlab.com/abc/foo` | `path/xyz.json` |
| Gitea default | `gitea>abc/foo` | `default` | `https://gitea.com/abc/foo` | `default.json` or `renovate.json` |
| Gitea with preset name | `gitea>abc/foo:xyz` | `xyz` | `https://gitea.com/abc/foo` | `xyz.json` |
| Local default | `local>abc/foo` | `default` | `https://github.company.com/abc/foo` | `default.json` or `renovate.json` |
| Local with preset path | `local>abc/foo//path/xyz` | `default` | `https://github.company.com/abc/foo` | `path/xyz.json` |

## Example configs

Expand Down
32 changes: 32 additions & 0 deletions lib/config/presets/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Object {
"packageName": "some/repo",
"params": undefined,
"presetName": "default",
"presetPath": undefined,
"presetSource": "gitea",
}
`;
Expand All @@ -96,6 +97,17 @@ Object {
"packageName": "some/repo",
"params": undefined,
"presetName": "default",
"presetPath": undefined,
"presetSource": "github",
}
`;

exports[`config/presets parsePreset parses github subdirectories 1`] = `
Object {
"packageName": "some/repo",
"params": undefined,
"presetName": "somefile",
"presetPath": "somepath/somesubpath",
"presetSource": "github",
}
`;
Expand All @@ -105,6 +117,7 @@ Object {
"packageName": "some/repo",
"params": undefined,
"presetName": "somefile",
"presetPath": undefined,
"presetSource": "github",
}
`;
Expand All @@ -114,6 +127,7 @@ Object {
"packageName": "some/repo",
"params": undefined,
"presetName": "somefile/somepreset/somesubpreset",
"presetPath": undefined,
"presetSource": "github",
}
`;
Expand All @@ -123,6 +137,7 @@ Object {
"packageName": "some/repo",
"params": undefined,
"presetName": "somefile/somepreset",
"presetPath": undefined,
"presetSource": "github",
}
`;
Expand All @@ -132,6 +147,7 @@ Object {
"packageName": "some/repo",
"params": undefined,
"presetName": "default",
"presetPath": undefined,
"presetSource": "gitlab",
}
`;
Expand All @@ -141,6 +157,7 @@ Object {
"packageName": "some/repo",
"params": undefined,
"presetName": "default",
"presetPath": undefined,
"presetSource": "local",
}
`;
Expand All @@ -150,6 +167,7 @@ Object {
"packageName": "some/repo",
"params": undefined,
"presetName": "default",
"presetPath": undefined,
"presetSource": "local",
}
`;
Expand All @@ -159,6 +177,7 @@ Object {
"packageName": "default",
"params": undefined,
"presetName": "base",
"presetPath": undefined,
"presetSource": "internal",
}
`;
Expand All @@ -171,6 +190,7 @@ Object {
"eslint",
],
"presetName": "group",
"presetPath": undefined,
"presetSource": "internal",
}
`;
Expand All @@ -180,6 +200,7 @@ Object {
"packageName": "renovate-config-somepackage",
"params": undefined,
"presetName": "default",
"presetPath": undefined,
"presetSource": "npm",
}
`;
Expand All @@ -189,6 +210,7 @@ Object {
"packageName": "renovate-config-somepackage",
"params": undefined,
"presetName": "webapp",
"presetPath": undefined,
"presetSource": "npm",
}
`;
Expand All @@ -198,6 +220,7 @@ Object {
"packageName": "renovate-config-somepackage",
"params": undefined,
"presetName": "webapp",
"presetPath": undefined,
"presetSource": "npm",
}
`;
Expand All @@ -209,6 +232,7 @@ Object {
"param1",
],
"presetName": "webapp",
"presetPath": undefined,
"presetSource": "npm",
}
`;
Expand All @@ -218,6 +242,7 @@ Object {
"packageName": "@somescope/somepackagename",
"params": undefined,
"presetName": "default",
"presetPath": undefined,
"presetSource": "npm",
}
`;
Expand All @@ -231,6 +256,7 @@ Object {
"param3",
],
"presetName": "default",
"presetPath": undefined,
"presetSource": "npm",
}
`;
Expand All @@ -240,6 +266,7 @@ Object {
"packageName": "@somescope/somepackagename",
"params": undefined,
"presetName": "somePresetName",
"presetPath": undefined,
"presetSource": "npm",
}
`;
Expand All @@ -252,6 +279,7 @@ Object {
"param2",
],
"presetName": "somePresetName",
"presetPath": undefined,
"presetSource": "npm",
}
`;
Expand All @@ -261,6 +289,7 @@ Object {
"packageName": "@somescope/renovate-config",
"params": undefined,
"presetName": "somePresetName",
"presetPath": undefined,
"presetSource": "npm",
}
`;
Expand All @@ -272,6 +301,7 @@ Object {
"param1",
],
"presetName": "somePresetName",
"presetPath": undefined,
"presetSource": "npm",
}
`;
Expand All @@ -281,6 +311,7 @@ Object {
"packageName": "@somescope/renovate-config",
"params": undefined,
"presetName": "default",
"presetPath": undefined,
"presetSource": "npm",
}
`;
Expand All @@ -292,6 +323,7 @@ Object {
"param1",
],
"presetName": "default",
"presetPath": undefined,
"presetSource": "npm",
}
`;
Expand Down
1 change: 1 addition & 0 deletions lib/config/presets/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type Preset = RenovateConfig & Record<string, unknown>;

export type PresetConfig = {
packageName: string;
presetPath?: string;
presetName?: string;
baseConfig?: RenovateConfig;
};
Expand Down
16 changes: 16 additions & 0 deletions lib/config/presets/gitea/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ Array [
]
`;

exports[`config/presets/gitea/index getPreset() should query custom paths 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"authorization": "token abc",
"host": "gitea.com",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://gitea.com/api/v1/repos/some/repo/contents/path%2Fcustom.json?",
},
]
`;

exports[`config/presets/gitea/index getPreset() should query preset within the file 1`] = `
Array [
Object {
Expand Down
17 changes: 17 additions & 0 deletions lib/config/presets/gitea/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ describe(getName(__filename), () => {
expect(httpMock.getTrace()).toMatchSnapshot();
});

it('should query custom paths', async () => {
httpMock
.scope(giteaApiHost)
.get(`${basePath}/path%2Fcustom.json`)
.reply(200, {
content: Buffer.from('{"foo":"bar"}').toString('base64'),
});
const content = await gitea.getPreset({
packageName: 'some/repo',
presetName: 'custom',
presetPath: 'path',
});
expect(content).toEqual({ foo: 'bar' });
expect(httpMock.getTrace()).toMatchSnapshot();
});

it('should throws not-found', async () => {
httpMock
.scope(giteaApiHost)
Expand Down Expand Up @@ -185,6 +201,7 @@ describe(getName(__filename), () => {
.getPresetFromEndpoint(
'some/repo',
'default',
undefined,
'https://api.gitea.example.org'
)
.catch(() => ({ from: 'api' }))
Expand Down
5 changes: 4 additions & 1 deletion lib/config/presets/gitea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ export async function fetchJSONFile(
export function getPresetFromEndpoint(
pkgName: string,
filePreset: string,
presetPath?: string,
endpoint = Endpoint
): Promise<Preset> {
return fetchPreset({
pkgName,
filePreset,
presetPath,
endpoint,
fetch: fetchJSONFile,
});
Expand All @@ -53,6 +55,7 @@ export function getPresetFromEndpoint(
export function getPreset({
packageName: pkgName,
presetName = 'default',
presetPath,
}: PresetConfig): Promise<Preset> {
return getPresetFromEndpoint(pkgName, presetName, Endpoint);
return getPresetFromEndpoint(pkgName, presetName, presetPath, Endpoint);
}
16 changes: 16 additions & 0 deletions lib/config/presets/github/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ Array [
]
`;

exports[`config/presets/github/index getPreset() should query custom paths 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/vnd.github.v3+json",
"accept-encoding": "gzip, deflate",
"authorization": "token abc",
"host": "api.github.com",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://api.github.com/repos/some/repo/contents/path/custom.json",
},
]
`;

exports[`config/presets/github/index getPreset() should query preset within the file 1`] = `
Array [
Object {
Expand Down
17 changes: 17 additions & 0 deletions lib/config/presets/github/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ describe(getName(__filename), () => {
expect(httpMock.getTrace()).toMatchSnapshot();
});

it('should query custom paths', async () => {
httpMock
.scope(githubApiHost)
.get(`${basePath}/path/custom.json`)
.reply(200, {
content: Buffer.from('{"foo":"bar"}').toString('base64'),
});
const content = await github.getPreset({
packageName: 'some/repo',
presetName: 'custom',
presetPath: 'path',
});
expect(content).toEqual({ foo: 'bar' });
expect(httpMock.getTrace()).toMatchSnapshot();
});

it('should throws not-found', async () => {
httpMock
.scope(githubApiHost)
Expand Down Expand Up @@ -183,6 +199,7 @@ describe(getName(__filename), () => {
.getPresetFromEndpoint(
'some/repo',
'default',
undefined,
'https://api.github.example.org'
)
.catch(() => ({ from: 'api' }))
Expand Down
5 changes: 4 additions & 1 deletion lib/config/presets/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ export async function fetchJSONFile(
export function getPresetFromEndpoint(
pkgName: string,
filePreset: string,
presetPath?: string,
endpoint = Endpoint
): Promise<Preset> {
return fetchPreset({
pkgName,
filePreset,
presetPath,
endpoint,
fetch: fetchJSONFile,
});
Expand All @@ -53,6 +55,7 @@ export function getPresetFromEndpoint(
export function getPreset({
packageName: pkgName,
presetName = 'default',
presetPath,
}: PresetConfig): Promise<Preset> {
return getPresetFromEndpoint(pkgName, presetName, Endpoint);
return getPresetFromEndpoint(pkgName, presetName, presetPath, Endpoint);
}
Loading