Skip to content
Snippets Groups Projects
Unverified Commit 455de72e authored by Michael Kriese's avatar Michael Kriese Committed by GitHub
Browse files

fix(manager/git-submodule): use appropriate hostType for auth (#17400)


Co-authored-by: default avatarJamie Magee <jamie.magee@gmail.com>
Co-authored-by: default avatarRhys Arkins <rhys@arkins.net>
parent 7b3e01f0
No related branches found
No related tags found
No related merge requests found
...@@ -7,3 +7,10 @@ ...@@ -7,3 +7,10 @@
[submodule "renovate-config"] [submodule "renovate-config"]
path = deps/renovate-config path = deps/renovate-config
url = git@github.com:renovatebot/renovate-config.git url = git@github.com:renovatebot/renovate-config.git
[submodule "some-other"]
path = some-other
url = https://domain.test/some/other.git
[submodule "some-gitlab"]
path = some-gitlab
url = https://gitlab.com/some/repo.git
...@@ -18,11 +18,16 @@ const Git = jest.requireActual('simple-git') as SimpleGitFactory; ...@@ -18,11 +18,16 @@ const Git = jest.requireActual('simple-git') as SimpleGitFactory;
describe('modules/manager/git-submodules/extract', () => { describe('modules/manager/git-submodules/extract', () => {
// flaky ci tests // flaky ci tests
jest.setTimeout(10 * 1000); //jest.setTimeout(10 * 1000);
beforeAll(() => { beforeAll(() => {
simpleGit.mockImplementation((basePath: string) => { simpleGit.mockImplementation((basePath: string) => {
const git = Git(basePath); const git = Git(basePath);
const lsRemote: Record<string, string> = {
'https://abc@domain.test/some/other.git': '',
'https://gitlab-ci-token:xyz@gitlab.com/some/repo.git':
'ref: refs/heads/dev HEAD\n',
};
return { return {
subModule(): Response<string> { subModule(): Response<string> {
return Promise.resolve( return Promise.resolve(
...@@ -40,7 +45,13 @@ describe('modules/manager/git-submodules/extract', () => { ...@@ -40,7 +45,13 @@ describe('modules/manager/git-submodules/extract', () => {
} }
return git.raw(options); return git.raw(options);
}, },
listRemote(): Response<string> { listRemote(options: TaskOptions): Response<string> {
if (
is.array(options, is.string) &&
lsRemote[options[1]] !== undefined
) {
return Promise.resolve(lsRemote[options[1]]) as Response<string>;
}
return Promise.resolve( return Promise.resolve(
'ref: refs/heads/main HEAD\n5701164b9f5edba1f6ca114c491a564ffb55a964 HEAD' 'ref: refs/heads/main HEAD\n5701164b9f5edba1f6ca114c491a564ffb55a964 HEAD'
) as Response<string>; ) as Response<string>;
...@@ -54,6 +65,16 @@ describe('modules/manager/git-submodules/extract', () => { ...@@ -54,6 +65,16 @@ describe('modules/manager/git-submodules/extract', () => {
it('extracts submodules', async () => { it('extracts submodules', async () => {
GlobalConfig.set({ localDir: `${__dirname}/__fixtures__` }); GlobalConfig.set({ localDir: `${__dirname}/__fixtures__` });
hostRules.add({ matchHost: 'github.com', token: '123test' }); hostRules.add({ matchHost: 'github.com', token: '123test' });
hostRules.add({
matchHost: 'domain.test',
token: 'abc',
hostType: 'git-refs',
});
hostRules.add({
matchHost: 'gitlab.com',
token: 'xyz',
hostType: 'gitlab',
});
let res: PackageFileContent | null; let res: PackageFileContent | null;
expect(await extractPackageFile('', '.gitmodules.1', {})).toBeNull(); expect(await extractPackageFile('', '.gitmodules.1', {})).toBeNull();
res = await extractPackageFile('', '.gitmodules.2', {}); res = await extractPackageFile('', '.gitmodules.2', {});
...@@ -64,10 +85,41 @@ describe('modules/manager/git-submodules/extract', () => { ...@@ -64,10 +85,41 @@ describe('modules/manager/git-submodules/extract', () => {
res = await extractPackageFile('', '.gitmodules.4', {}); res = await extractPackageFile('', '.gitmodules.4', {});
expect(res?.deps).toHaveLength(1); expect(res?.deps).toHaveLength(1);
res = await extractPackageFile('', '.gitmodules.5', {}); res = await extractPackageFile('', '.gitmodules.5', {});
expect(res?.deps).toHaveLength(3); expect(res).toEqual({
expect(res?.deps[2].packageName).toBe( datasource: 'git-refs',
'https://github.com/renovatebot/renovate-config.git' deps: [
); {
currentDigest: '4b825dc642cb6eb9a060e54bf8d69288fbee4904',
currentValue: 'main',
depName: 'deps/renovate',
packageName: 'https://github.com/renovatebot/renovate.git',
},
{
currentDigest: '4b825dc642cb6eb9a060e54bf8d69288fbee4904',
currentValue: 'main',
depName: 'deps/renovate-pro',
packageName: 'https://github.com/renovatebot/pro.git',
},
{
currentDigest: '4b825dc642cb6eb9a060e54bf8d69288fbee4904',
currentValue: 'main',
depName: 'deps/renovate-config',
packageName: 'https://github.com/renovatebot/renovate-config.git',
},
{
currentDigest: '4b825dc642cb6eb9a060e54bf8d69288fbee4904',
currentValue: 'master',
depName: 'some-other',
packageName: 'https://domain.test/some/other.git',
},
{
currentDigest: '4b825dc642cb6eb9a060e54bf8d69288fbee4904',
currentValue: 'dev',
depName: 'some-gitlab',
packageName: 'https://gitlab.com/some/repo.git',
},
],
});
}); });
}); });
}); });
...@@ -3,6 +3,7 @@ import Git, { SimpleGit } from 'simple-git'; ...@@ -3,6 +3,7 @@ import Git, { SimpleGit } from 'simple-git';
import upath from 'upath'; import upath from 'upath';
import { GlobalConfig } from '../../../config/global'; import { GlobalConfig } from '../../../config/global';
import { logger } from '../../../logger'; import { logger } from '../../../logger';
import { detectPlatform } from '../../../util/common';
import { simpleGitConfig } from '../../../util/git/config'; import { simpleGitConfig } from '../../../util/git/config';
import { getHttpUrl, getRemoteUrlWithToken } from '../../../util/git/url'; import { getHttpUrl, getRemoteUrlWithToken } from '../../../util/git/url';
import { regEx } from '../../../util/regex'; import { regEx } from '../../../util/regex';
...@@ -115,7 +116,8 @@ export default async function extractPackageFile( ...@@ -115,7 +116,8 @@ export default async function extractPackageFile(
// hostRules only understands HTTP URLs // hostRules only understands HTTP URLs
// Find HTTP URL, then apply token // Find HTTP URL, then apply token
let httpSubModuleUrl = getHttpUrl(subModuleUrl); let httpSubModuleUrl = getHttpUrl(subModuleUrl);
httpSubModuleUrl = getRemoteUrlWithToken(httpSubModuleUrl); const hostType = detectPlatform(httpSubModuleUrl) ?? GitRefsDatasource.id;
httpSubModuleUrl = getRemoteUrlWithToken(httpSubModuleUrl, hostType);
const currentValue = await getBranch( const currentValue = await getBranch(
gitModulesPath, gitModulesPath,
name, name,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment