Skip to content

Commit 1815c3c

Browse files
committed
Refactor git configuration for LFS file pulling with token-based authentication
- Enhanced the process of configuring git to use GIT_PRIVATE_TOKEN and GITHUB_TOKEN by clearing existing URL configurations before setting new ones. - Improved the clarity of the URL replacement commands for better readability and maintainability. - This change ensures a more robust setup for pulling LFS files in environments requiring token authentication.
1 parent 10fc07a commit 1815c3c

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

dist/index.js

Lines changed: 16 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/model/cloud-runner/remote-client/index.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,20 @@ export class RemoteClient {
231231
throw new Error('GIT_PRIVATE_TOKEN is not available');
232232
}
233233

234+
// Clear any existing URL configurations
235+
await CloudRunnerSystem.Run(`git config --global --unset-all url."https://github.com/".insteadOf`);
236+
await CloudRunnerSystem.Run(`git config --global --unset-all url."ssh://git@github.com/".insteadOf`);
237+
await CloudRunnerSystem.Run(`git config --global --unset-all url."git@github.com".insteadOf`);
238+
239+
// Set new URL configuration with token
234240
await CloudRunnerSystem.Run(
235-
`git config --global --replace-all url."https://token:${gitPrivateToken}@github.com/".insteadOf ssh://git@github.com/`,
241+
`git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "https://github.com/"`,
236242
);
237243
await CloudRunnerSystem.Run(
238-
`git config --global --add url."https://token:${gitPrivateToken}@github.com/".insteadOf git@github.com`,
244+
`git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "ssh://git@github.com/"`,
239245
);
240246
await CloudRunnerSystem.Run(
241-
`git config --global --add url."https://token:${gitPrivateToken}@github.com/".insteadOf "https://github.com/"`,
247+
`git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "git@github.com"`,
242248
);
243249

244250
await CloudRunnerSystem.Run(`git lfs pull`);
@@ -255,15 +261,20 @@ export class RemoteClient {
255261
throw new Error('GITHUB_TOKEN is not available as fallback');
256262
}
257263

258-
// Configure git to use GITHUB_TOKEN
264+
// Clear any existing URL configurations
265+
await CloudRunnerSystem.Run(`git config --global --unset-all url."https://github.com/".insteadOf`);
266+
await CloudRunnerSystem.Run(`git config --global --unset-all url."ssh://git@github.com/".insteadOf`);
267+
await CloudRunnerSystem.Run(`git config --global --unset-all url."git@github.com".insteadOf`);
268+
269+
// Set new URL configuration with token
259270
await CloudRunnerSystem.Run(
260-
`git config --global --replace-all url."https://token:${githubToken}@github.com/".insteadOf ssh://git@github.com/`,
271+
`git config --global url."https://${githubToken}@github.com/".insteadOf "https://github.com/"`,
261272
);
262273
await CloudRunnerSystem.Run(
263-
`git config --global --add url."https://token:${githubToken}@github.com/".insteadOf git@github.com`,
274+
`git config --global url."https://${githubToken}@github.com/".insteadOf "ssh://git@github.com/"`,
264275
);
265276
await CloudRunnerSystem.Run(
266-
`git config --global --add url."https://token:${githubToken}@github.com/".insteadOf "https://github.com/"`,
277+
`git config --global url."https://${githubToken}@github.com/".insteadOf "git@github.com"`,
267278
);
268279

269280
await CloudRunnerSystem.Run(`git lfs pull`);

0 commit comments

Comments
 (0)