Skip to content

Commit 0c235ba

Browse files
frostebiteclaude
andcommitted
fix: improve changeset extraction to use context-aware fallback
The final fallback pattern for extracting changesets now searches within a ~500-character context window around the version string, rather than globally searching the entire HTML. This prevents the fallback from matching changeset markers from unrelated versions. This ensures each version gets paired with the correct changeset, allowing versions to be discovered even when HTML structure varies. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 6ceb756 commit 0c235ba

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

functions/src/logic/ingestUnityVersions/scrapeVersions.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,33 @@ export const scrapeRecentOfficialUnityVersions = async (): Promise<EditorVersion
5555
processedVersions.add(version);
5656

5757
const escapedVersion = version.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
58+
let changeset: string | undefined;
59+
5860
const changesetMatch =
5961
new RegExp(`unityhub://${escapedVersion}/([a-f0-9]{12})`, 'i').exec(html) ||
60-
new RegExp(`${escapedVersion}[^a-f0-9]*([a-f0-9]{12})`, 'i').exec(html) ||
61-
/Changeset:\s*([a-f0-9]{12})/i.exec(html);
62+
new RegExp(`${escapedVersion}[^a-f0-9]*([a-f0-9]{12})`, 'i').exec(html);
6263

6364
if (changesetMatch?.[1]) {
65+
changeset = changesetMatch[1];
66+
} else {
67+
// As a last resort, search for changeset within a context window near the version
68+
// Extract ~500 chars around the version match for local context search
69+
const versionIndex = html.indexOf(version);
70+
if (versionIndex !== -1) {
71+
const contextStart = Math.max(0, versionIndex - 200);
72+
const contextEnd = Math.min(html.length, versionIndex + 300);
73+
const context = html.substring(contextStart, contextEnd);
74+
const contextChangesetMatch = /[Cc]hangeset:\s*([a-f0-9]{12})/i.exec(context);
75+
if (contextChangesetMatch?.[1]) {
76+
changeset = contextChangesetMatch[1];
77+
}
78+
}
79+
}
80+
81+
if (changeset) {
6482
versions.push({
6583
version,
66-
changeset: changesetMatch[1],
84+
changeset,
6785
});
6886
}
6987
}

0 commit comments

Comments
 (0)