Skip to content

Commit 49c3ded

Browse files
gblanc-1aGuillaume BLANC
authored andcommitted
feat: allow migration from awesome-copilot to github source types
fix: resolve lint errors in source type migration files
1 parent 63b1e8d commit 49c3ded

13 files changed

Lines changed: 1879 additions & 13 deletions

apps/vscode-extension/src/adapters/github-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ export class GitHubAdapter extends RepositoryAdapter {
560560
manifest = await this.fetchManifestWithCache(manifestAsset.url, manifestAsset.name);
561561
} catch (manifestError) {
562562
this.logger.warn(`Failed to fetch manifest for ${release.tag_name}: ${manifestError}`);
563-
// Continue without manifest data - use fallback values
563+
return null;
564564
}
565565

566566
// Locate the README release asset by the filename recorded in the manifest.

apps/vscode-extension/src/services/hub-manager.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ import {
4747
SchemaValidator,
4848
ValidationResult,
4949
} from './schema-validator';
50+
import {
51+
SourceTypeReconciler,
52+
} from './source-type-reconciler';
5053

5154
const execAsync = promisify(exec);
5255

@@ -904,7 +907,7 @@ export class HubManager {
904907
this.logger.info(`Found ${hubSources.length} sources in hub ${hubId}`);
905908

906909
// Get existing sources to avoid duplicates
907-
const existingSources = await this.registryManager.listSources();
910+
let existingSources = await this.registryManager.listSources();
908911

909912
let addedCount = 0;
910913
let skippedCount = 0;
@@ -963,6 +966,42 @@ export class HubManager {
963966
continue;
964967
}
965968

969+
// @migration-cleanup(source-type-migration): Remove this block once all sources have migrated
970+
// Detect awesome-copilot → github type change by URL match
971+
const typeChangedSource = SourceTypeReconciler.detectTypeChange(hubSource, existingSources);
972+
if (typeChangedSource) {
973+
this.logger.info(
974+
`Detected source type change: ${typeChangedSource.id} (${typeChangedSource.type}) → ${hubSource.type} for URL ${hubSource.url}`
975+
);
976+
977+
try {
978+
const reconciler = new SourceTypeReconciler(
979+
this.registryManager,
980+
this.registryManager.getStorage(),
981+
this.storage
982+
);
983+
984+
const reconcileResult = await reconciler.reconcile(
985+
typeChangedSource,
986+
hubSource,
987+
hubId,
988+
sourceId
989+
);
990+
991+
existingSources = await this.registryManager.listSources();
992+
if (reconcileResult.bundleResults.some((r) => r.success)) {
993+
updatedCount++;
994+
}
995+
} catch (error) {
996+
this.logger.error(
997+
`Failed to reconcile source type change for ${hubSource.url}`,
998+
error as Error
999+
);
1000+
}
1001+
1002+
continue;
1003+
}
1004+
9661005
// Add new source
9671006
this.logger.info(`Adding new hub source: ${sourceId} (${hubSource.name})`);
9681007

apps/vscode-extension/src/services/registry-manager.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
} from '../types/settings';
5757
import {
5858
BundleIdentityMatcher,
59+
extractGitHubMetadata,
5960
} from '../utils/bundle-identity-matcher';
6061
import {
6162
CONCURRENCY_CONSTANTS,
@@ -457,11 +458,36 @@ export class RegistryManager {
457458
}
458459

459460
const sourceType: SourceType = (installed.sourceType as SourceType) ?? 'local';
460-
return BundleIdentityMatcher.matches(
461+
const primaryMatch = BundleIdentityMatcher.matches(
461462
installed.bundleId,
462463
latest.id,
463464
sourceType
464465
);
466+
467+
if (primaryMatch) {
468+
return true;
469+
}
470+
471+
// @migration-cleanup(source-type-migration): Remove this fallback
472+
if (sourceType === 'awesome-copilot') {
473+
return this.matchesCrossTypeFallback(installed.bundleId, latest);
474+
}
475+
476+
return false;
477+
}
478+
479+
// @migration-cleanup(source-type-migration): Remove with the fallback call sites
480+
private matchesCrossTypeFallback(installedBundleId: string, candidate: Bundle): boolean {
481+
const source = this.sourcesCache.find((s) => s.id === candidate.sourceId);
482+
if (source?.type !== 'github') {
483+
return false;
484+
}
485+
const metadata = source.url ? extractGitHubMetadata(source.url) : undefined;
486+
return BundleIdentityMatcher.matchesAwesomeCopilotToGithub(
487+
installedBundleId,
488+
candidate.id,
489+
metadata
490+
);
465491
}
466492

467493
/**
@@ -470,7 +496,8 @@ export class RegistryManager {
470496
* @param latestBundles
471497
*/
472498
private findMatchingLatestBundle(installedBundle: InstalledBundle, latestBundles: Bundle[]): Bundle | undefined {
473-
return latestBundles.find((lb) => {
499+
// Primary match: same source type
500+
const primaryMatch = latestBundles.find((lb) => {
474501
if (installedBundle.sourceType === 'github') {
475502
return BundleIdentityMatcher.matches(
476503
installedBundle.bundleId,
@@ -484,6 +511,17 @@ export class RegistryManager {
484511
return installedBaseId === latestBaseId;
485512
}
486513
});
514+
515+
if (primaryMatch) {
516+
return primaryMatch;
517+
}
518+
519+
// @migration-cleanup(source-type-migration): Remove this fallback
520+
if (installedBundle.sourceType === 'awesome-copilot') {
521+
return latestBundles.find((lb) => this.matchesCrossTypeFallback(installedBundle.bundleId, lb));
522+
}
523+
524+
return undefined;
487525
}
488526

489527
/**

0 commit comments

Comments
 (0)