@@ -8,6 +8,7 @@ import type { RepoGlobalConfig } from '../../../config/types.ts';
88import { TEMPORARY_ERROR } from '../../../constants/error-messages.ts' ;
99import { ExecError } from '../../../util/exec/exec-error.ts' ;
1010import type { StatusResult } from '../../../util/git/types.ts' ;
11+ import * as hostRules from '../../../util/host-rules.ts' ;
1112import type { UpdateArtifactsConfig } from '../types.ts' ;
1213import * 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 ) ;
0 commit comments