diff --git a/lib/modules/manager/nix/artifacts.spec.ts b/lib/modules/manager/nix/artifacts.spec.ts index c3fe645e9b826ef6b2684c2dede6654b807127ed..779513f29c00c8e74e02d9cc7568bb42a3c34b2d 100644 --- a/lib/modules/manager/nix/artifacts.spec.ts +++ b/lib/modules/manager/nix/artifacts.spec.ts @@ -155,6 +155,36 @@ describe('modules/manager/nix/artifacts', () => { expect(execSnapshots).toMatchObject([{ cmd: updateInputTokenCmd }]); }); + it('trims "x-access-token:" prefix from GitHub token', async () => { + fs.readLocalFile.mockResolvedValueOnce('current flake.lock'); + const execSnapshots = mockExecAll(); + git.getRepoStatus.mockResolvedValue( + partial<StatusResult>({ + modified: ['flake.lock'], + }) + ); + fs.readLocalFile.mockResolvedValueOnce('new flake.lock'); + hostRules.find.mockReturnValueOnce({ token: 'x-access-token:token' }); + + const res = await updateArtifacts({ + packageFileName: 'flake.nix', + updatedDeps: [{ depName: 'nixpkgs' }], + newPackageFileContent: 'some new content', + config: { ...config, constraints: { python: '3.7' } }, + }); + + expect(res).toEqual([ + { + file: { + contents: 'new flake.lock', + path: 'flake.lock', + type: 'addition', + }, + }, + ]); + expect(execSnapshots).toMatchObject([{ cmd: updateInputTokenCmd }]); + }); + it('supports docker mode', async () => { GlobalConfig.set(dockerAdminConfig); const execSnapshots = mockExecAll(); diff --git a/lib/modules/manager/nix/artifacts.ts b/lib/modules/manager/nix/artifacts.ts index a563b84efb6c8fae68c64b0580b5b06f13e705cb..236004dffcd6c60fc20fd86c7fd2363c563e5d79 100644 --- a/lib/modules/manager/nix/artifacts.ts +++ b/lib/modules/manager/nix/artifacts.ts @@ -1,6 +1,7 @@ import is from '@sindresorhus/is'; import { quote } from 'shlex'; import { logger } from '../../../logger'; +import { findGithubToken } from '../../../util/check-token'; import { exec } from '../../../util/exec'; import type { ExecOptions } from '../../../util/exec/types'; import { readLocalFile } from '../../../util/fs'; @@ -25,10 +26,12 @@ export async function updateArtifacts({ --extra-experimental-features nix-command \ --extra-experimental-features flakes `; - const { token } = hostRules.find({ - hostType: 'github', - url: 'https://api.github.com/', - }); + const token = findGithubToken( + hostRules.find({ + hostType: 'github', + url: 'https://api.github.com/', + }) + ); if (token) { cmd += `--extra-access-tokens github.com=${token} `;