Skip to content

Commit 4fa530d

Browse files
authored
Check controller repo before we set it (#2116)
1 parent ce29768 commit 4fa530d

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

extensions/ql-vscode/src/variant-analysis/run-remote-query.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,10 @@ export async function getControllerRepo(
365365
credentials: Credentials,
366366
): Promise<Repository> {
367367
// Get the controller repo from the config, if it exists.
368-
// If it doesn't exist, prompt the user to enter it, and save that value to the config.
368+
// If it doesn't exist, prompt the user to enter it, check
369+
// whether the repo exists, and save the nwo to the config.
370+
371+
let shouldSetControllerRepo = false;
369372
let controllerRepoNwo: string | undefined;
370373
controllerRepoNwo = getRemoteControllerRepo();
371374
if (!controllerRepoNwo || !REPO_REGEX.test(controllerRepoNwo)) {
@@ -390,15 +393,31 @@ export async function getControllerRepo(
390393
"Invalid repository format. Must be a valid GitHub repository in the format <owner>/<repo>.",
391394
);
392395
}
396+
397+
shouldSetControllerRepo = true;
398+
}
399+
400+
void extLogger.log(`Using controller repository: ${controllerRepoNwo}`);
401+
const controllerRepo = await getControllerRepoFromApi(
402+
credentials,
403+
controllerRepoNwo,
404+
);
405+
406+
if (shouldSetControllerRepo) {
393407
void extLogger.log(
394408
`Setting the controller repository as: ${controllerRepoNwo}`,
395409
);
396410
await setRemoteControllerRepo(controllerRepoNwo);
397411
}
398412

399-
void extLogger.log(`Using controller repository: ${controllerRepoNwo}`);
400-
const [owner, repo] = controllerRepoNwo.split("/");
413+
return controllerRepo;
414+
}
401415

416+
async function getControllerRepoFromApi(
417+
credentials: Credentials,
418+
nwo: string,
419+
): Promise<Repository> {
420+
const [owner, repo] = nwo.split("/");
402421
try {
403422
const controllerRepo = await getRepositoryFromNwo(credentials, owner, repo);
404423
void extLogger.log(`Controller repository ID: ${controllerRepo.id}`);
@@ -419,6 +438,7 @@ export async function getControllerRepo(
419438
}
420439
}
421440
}
441+
422442
export function removeWorkspaceRefs(qlpack: QlPack) {
423443
for (const [key, value] of Object.entries(qlpack.dependencies || {})) {
424444
if (value === "${workspace}") {

0 commit comments

Comments
 (0)