Skip to content

Commit fdde07c

Browse files
jamietannaClaude Sonnet 4.5
andauthored
feat(vendir): convert Host Rules to Git authentication (renovatebot#41458)
When using Vendir with Git repositories, we do not currently provide authentication via Host Rules, which means we cannot access private repositories. Instead, we should set these, so they can be used by `vendir sync` to authenticate to private repos. Co-authored-by: Claude Sonnet 4.5 <jamie.tanna+github-copilot@mend.io>
1 parent 702f8f9 commit fdde07c

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

lib/modules/manager/vendir/artifacts.spec.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { RepoGlobalConfig } from '../../../config/types.ts';
88
import { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';
99
import { ExecError } from '../../../util/exec/exec-error.ts';
1010
import type { StatusResult } from '../../../util/git/types.ts';
11+
import * as hostRules from '../../../util/host-rules.ts';
1112
import type { UpdateArtifactsConfig } from '../types.ts';
1213
import * as vendir from './index.ts';
1314

@@ -37,6 +38,10 @@ describe('modules/manager/vendir/artifacts', () => {
3738
GlobalConfig.set(adminConfig);
3839
});
3940

41+
afterEach(() => {
42+
hostRules.clear();
43+
});
44+
4045
it('returns null if no vendir.lock.yml found', async () => {
4146
const updatedDeps = [{ depName: 'dep1' }];
4247
expect(
@@ -341,6 +346,88 @@ describe('modules/manager/vendir/artifacts', () => {
341346
]);
342347
});
343348

349+
it('sets GIT_CONFIG variables when Host Rules are configured', async () => {
350+
fs.readLocalFile.mockResolvedValueOnce(vendirLockFile1);
351+
fs.getSiblingFileName.mockReturnValueOnce('vendir.lock.yml');
352+
fs.readLocalFile.mockResolvedValueOnce(vendirLockFile2);
353+
const execSnapshots = mockExecAll();
354+
fs.privateCacheDir.mockReturnValue(
355+
'/tmp/renovate/cache/__renovate-private-cache',
356+
);
357+
fs.getParentDir.mockReturnValue('');
358+
359+
hostRules.add({
360+
hostType: 'github',
361+
matchHost: 'api.github.com',
362+
token: 'some-token',
363+
});
364+
hostRules.add({
365+
hostType: 'github',
366+
matchHost: 'github.enterprise.com',
367+
token: 'some-enterprise-token',
368+
});
369+
hostRules.add({
370+
hostType: 'gitlab',
371+
matchHost: 'gitlab.enterprise.com',
372+
token: 'some-gitlab-token',
373+
});
374+
375+
// artifacts
376+
fs.getSiblingFileName.mockReturnValueOnce('vendor');
377+
git.getRepoStatus.mockResolvedValueOnce(
378+
partial<StatusResult>({
379+
not_added: ['vendor/Chart.yaml'],
380+
}),
381+
);
382+
const updatedDeps = [{ depName: 'dep1' }];
383+
384+
await vendir.updateArtifacts({
385+
packageFileName: 'vendir.yml',
386+
updatedDeps,
387+
newPackageFileContent: vendirFile,
388+
config: {
389+
...config,
390+
},
391+
});
392+
393+
expect(execSnapshots).toEqual(
394+
expect.arrayContaining([
395+
expect.objectContaining({
396+
options: expect.objectContaining({
397+
env: expect.objectContaining({
398+
GIT_CONFIG_COUNT: '9',
399+
GIT_CONFIG_KEY_0:
400+
'url.https://ssh:some-token@github.com/.insteadOf',
401+
GIT_CONFIG_KEY_1:
402+
'url.https://git:some-token@github.com/.insteadOf',
403+
GIT_CONFIG_KEY_2: 'url.https://some-token@github.com/.insteadOf',
404+
GIT_CONFIG_KEY_3:
405+
'url.https://ssh:some-enterprise-token@github.enterprise.com/.insteadOf',
406+
GIT_CONFIG_KEY_4:
407+
'url.https://git:some-enterprise-token@github.enterprise.com/.insteadOf',
408+
GIT_CONFIG_KEY_5:
409+
'url.https://some-enterprise-token@github.enterprise.com/.insteadOf',
410+
GIT_CONFIG_KEY_6:
411+
'url.https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/.insteadOf',
412+
GIT_CONFIG_KEY_7:
413+
'url.https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/.insteadOf',
414+
GIT_CONFIG_KEY_8:
415+
'url.https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/.insteadOf',
416+
GIT_CONFIG_VALUE_0: 'ssh://git@github.com/',
417+
GIT_CONFIG_VALUE_1: 'git@github.com:',
418+
GIT_CONFIG_VALUE_2: 'https://github.com/',
419+
GIT_CONFIG_VALUE_3: 'ssh://git@github.enterprise.com/',
420+
GIT_CONFIG_VALUE_4: 'git@github.enterprise.com:',
421+
GIT_CONFIG_VALUE_5: 'https://github.enterprise.com/',
422+
GIT_CONFIG_VALUE_6: 'ssh://git@gitlab.enterprise.com/',
423+
GIT_CONFIG_VALUE_7: 'git@gitlab.enterprise.com:',
424+
}),
425+
}),
426+
}),
427+
]),
428+
);
429+
});
430+
344431
it('works explicit global binarySource', async () => {
345432
GlobalConfig.set({ ...adminConfig, binarySource: 'global' });
346433
fs.readLocalFile.mockResolvedValueOnce(vendirLockFile1);

lib/modules/manager/vendir/artifacts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
readLocalFile,
99
writeLocalFile,
1010
} from '../../../util/fs/index.ts';
11+
import { getGitEnvironmentVariables } from '../../../util/git/auth.ts';
1112
import { getRepoStatus } from '../../../util/git/index.ts';
1213
import type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';
1314

@@ -33,6 +34,7 @@ export async function updateArtifacts({
3334
await writeLocalFile(packageFileName, newPackageFileContent);
3435
logger.debug('Updating Vendir artifacts');
3536
const execOptions: ExecOptions = {
37+
extraEnv: { ...getGitEnvironmentVariables([]) },
3638
cwdFile: packageFileName,
3739
docker: {},
3840
toolConstraints: [

0 commit comments

Comments
 (0)