Skip to content

Commit d058f66

Browse files
committed
Rename authentication error to GitAuthenticationError and avoid Github specific code in the git library
1 parent 6500950 commit d058f66

File tree

8 files changed

+101
-131
lines changed

8 files changed

+101
-131
lines changed

packages/playground/blueprints/src/lib/v1/compile.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ export interface CompileBlueprintV1Options {
8383
* A filesystem to use for the blueprint.
8484
*/
8585
streamBundledFile?: StreamBundledFile;
86+
/**
87+
* Additional headers to pass to git operations.
88+
*/
89+
gitAdditionalHeaders?: Record<string, string>;
8690
/**
8791
* Additional steps to add to the blueprint.
8892
*/
@@ -142,6 +146,7 @@ function compileBlueprintJson(
142146
onBlueprintValidated = () => {},
143147
corsProxy,
144148
streamBundledFile,
149+
gitAdditionalHeaders,
145150
additionalSteps,
146151
}: CompileBlueprintV1Options = {}
147152
): CompiledBlueprintV1 {
@@ -321,6 +326,7 @@ function compileBlueprintJson(
321326
totalProgressWeight,
322327
corsProxy,
323328
streamBundledFile,
329+
gitAdditionalHeaders,
324330
})
325331
);
326332

@@ -514,6 +520,10 @@ interface CompileStepArgsOptions {
514520
* A filesystem to use for the "blueprint" resource type.
515521
*/
516522
streamBundledFile?: StreamBundledFile;
523+
/**
524+
* Additional headers to pass to git operations.
525+
*/
526+
gitAdditionalHeaders?: Record<string, string>;
517527
}
518528

519529
/**
@@ -532,6 +542,7 @@ function compileStep<S extends StepDefinition>(
532542
totalProgressWeight,
533543
corsProxy,
534544
streamBundledFile,
545+
gitAdditionalHeaders,
535546
}: CompileStepArgsOptions
536547
): { run: CompiledV1Step; step: S; resources: Array<Resource<any>> } {
537548
const stepProgress = rootProgressTracker.stage(
@@ -546,6 +557,7 @@ function compileStep<S extends StepDefinition>(
546557
semaphore,
547558
corsProxy,
548559
streamBundledFile,
560+
gitAdditionalHeaders,
549561
});
550562
}
551563
args[key] = value;

packages/playground/blueprints/src/lib/v1/resources.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,14 @@ export abstract class Resource<T extends File | Directory> {
157157
progress,
158158
corsProxy,
159159
streamBundledFile,
160+
gitAdditionalHeaders,
160161
}: {
161162
/** Optional semaphore to limit concurrent downloads */
162163
semaphore?: Semaphore;
163164
progress?: ProgressTracker;
164165
corsProxy?: string;
165166
streamBundledFile?: StreamBundledFile;
167+
gitAdditionalHeaders?: Record<string, string>;
166168
}
167169
): Resource<File | Directory> {
168170
let resource: Resource<File | Directory>;
@@ -185,6 +187,7 @@ export abstract class Resource<T extends File | Directory> {
185187
case 'git:directory':
186188
resource = new GitDirectoryResource(ref, progress, {
187189
corsProxy,
190+
additionalHeaders: gitAdditionalHeaders,
188191
});
189192
break;
190193
case 'literal:directory':
@@ -556,12 +559,18 @@ export class UrlResource extends FetchResource {
556559
*/
557560
export class GitDirectoryResource extends Resource<Directory> {
558561
private reference: GitDirectoryReference;
559-
private options?: { corsProxy?: string };
562+
private options?: {
563+
corsProxy?: string;
564+
additionalHeaders?: Record<string, string>;
565+
};
560566

561567
constructor(
562568
reference: GitDirectoryReference,
563569
_progress?: ProgressTracker,
564-
options?: { corsProxy?: string }
570+
options?: {
571+
corsProxy?: string;
572+
additionalHeaders?: Record<string, string>;
573+
}
565574
) {
566575
super();
567576
this.reference = reference;
@@ -574,11 +583,19 @@ export class GitDirectoryResource extends Resource<Directory> {
574583
? `${this.options.corsProxy}${this.reference.url}`
575584
: this.reference.url;
576585

577-
const commitHash = await resolveCommitHash(repoUrl, {
578-
value: this.reference.ref,
579-
type: this.reference.refType ?? 'infer',
580-
});
581-
const allFiles = await listGitFiles(repoUrl, commitHash);
586+
const commitHash = await resolveCommitHash(
587+
repoUrl,
588+
{
589+
value: this.reference.ref,
590+
type: this.reference.refType ?? 'infer',
591+
},
592+
this.options?.additionalHeaders
593+
);
594+
const allFiles = await listGitFiles(
595+
repoUrl,
596+
commitHash,
597+
this.options?.additionalHeaders
598+
);
582599

583600
const requestedPath = (this.reference.path ?? '').replace(/^\/+/, '');
584601
const filesToClone = listDescendantFiles(allFiles, requestedPath);
@@ -588,6 +605,7 @@ export class GitDirectoryResource extends Resource<Directory> {
588605
filesToClone,
589606
{
590607
withObjects: this.reference['.git'],
608+
additionalHeaders: this.options?.additionalHeaders,
591609
}
592610
);
593611
let files = checkout.files;

packages/playground/client/src/blueprints-v1-handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class BlueprintsV1Handler {
2121
onBlueprintValidated,
2222
onBlueprintStepCompleted,
2323
corsProxy,
24+
gitAdditionalHeaders,
2425
mounts,
2526
sapiName,
2627
scope,
@@ -72,6 +73,7 @@ export class BlueprintsV1Handler {
7273
onStepCompleted: onBlueprintStepCompleted,
7374
onBlueprintValidated,
7475
corsProxy,
76+
gitAdditionalHeaders,
7577
});
7678
await runBlueprintV1Steps(compiled, playground);
7779
}

packages/playground/client/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export interface StartPlaygroundOptions {
8585
* your Blueprint to replace all cross-origin URLs with the proxy URL.
8686
*/
8787
corsProxy?: string;
88+
/**
89+
* Additional headers to pass to git operations.
90+
*/
91+
gitAdditionalHeaders?: Record<string, string>;
8892
/**
8993
* The version of the SQLite driver to use.
9094
* Defaults to the latest development version.

0 commit comments

Comments
 (0)