Skip to content

Commit 22d7199

Browse files
committed
feat: update for XLTS versions
- When retrieving changesets, XLTS versions are also supported. - In the list command, `--xlts` is changed to a filter option and includes XLTS versions in the results when enabled.
1 parent be40a73 commit 22d7199

File tree

5 files changed

+36
-114
lines changed

5 files changed

+36
-114
lines changed

src/cli.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ new Command()
5252
.example("unity-changeset list --lts --latest-patch", "List changesets of the latest patch versions (LTS only).")
5353
// Search options.
5454
.group("Search options")
55-
.option("--all", "Search all changesets (alpha/beta included)")
56-
.option("--pre-release, --beta", "Search only pre-release (alpha/beta) changesets", { conflicts: ["all", "lts", "xlts"] })
57-
.option("--lts", "Only the LTS versions", { conflicts: ["all", "pre-release", "xlts", "supported"] })
58-
.option("--xlts", "Only the LTS/XLTS versions (require 'Enterprise' or 'Industry' license to install XLTS version)", { conflicts: ["all", "pre-release", "lts", "supported"] })
59-
.option("--supported", "Only the supported versions (including Unity 6000)", { conflicts: ["all", "pre-release", "lts", "xlts"] })
55+
.option("--all", "Search in all streams (alpha/beta included)")
56+
.option("--supported", "Search in the 'SUPPORTED' stream (including Unity 6000)", { conflicts: ["all", "pre-release", "lts"] })
57+
.option("--lts", "Search in the 'LTS' stream", { conflicts: ["all", "supported", "pre-release"] })
58+
.option("--pre-release, --beta", "Search in the 'ALPHA' and 'BETA' streams", { conflicts: ["all", "supported", "lts"] })
6059
// Filter options.
6160
.group("Filter options")
61+
.option("--xlts", "Include XLTS entitlement versions (require 'Enterprise' or 'Industry' license to install XLTS version)")
6262
.option("--min <version>", "Minimum version (included)")
6363
.option("--max <version>", "Maximum version (included)")
6464
.option("--grep <regex>", "Regular expression (e.g. '20(18|19).4.*')")
@@ -82,11 +82,9 @@ new Command()
8282
? SearchMode.PreRelease
8383
: options.lts
8484
? SearchMode.LTS
85-
: options.xlts
86-
? SearchMode.XLTS
87-
: options.supported
88-
? SearchMode.SUPPORTED
89-
: SearchMode.Default;
85+
: options.supported
86+
? SearchMode.Supported
87+
: SearchMode.Default;
9088

9189
// Group mode.
9290
const groupMode = (options.latestPatch || options.minorVersionOnly)
@@ -103,7 +101,7 @@ new Command()
103101
allLifecycles: (options.allLifecycles && !options.latestLifecycle)
104102
? true
105103
: false,
106-
lts: options.lts || false,
104+
xlts: options.xlts || false,
107105
};
108106

109107
// Output mode.

src/index.ts

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getUnityReleases, getUnityReleasesInLTS } from "./unityGraphQL.ts";
1+
import { getUnityReleases } from "./unityGraphQL.ts";
22
import {
33
UnityChangeset as UnityChangesetClass,
44
UnityReleaseEntitlement,
@@ -30,7 +30,11 @@ export async function getUnityChangeset(
3030

3131
let changesets: UnityChangeset[];
3232
try {
33-
changesets = await getUnityReleases(sanitizedVersion, []);
33+
changesets = await getUnityReleases(
34+
sanitizedVersion,
35+
searchModeToStreams(SearchMode.All),
36+
[UnityReleaseEntitlement.XLTS],
37+
);
3438
} catch {
3539
changesets = await getAllChangesetsFromDb();
3640
}
@@ -61,8 +65,7 @@ export enum SearchMode {
6165
Default = 2,
6266
PreRelease = 3,
6367
LTS = 4,
64-
XLTS = 5,
65-
SUPPORTED = 6,
68+
Supported = 6,
6669
}
6770

6871
/*
@@ -94,7 +97,7 @@ export interface FilterOptions {
9497
max: string;
9598
grep: string;
9699
allLifecycles: boolean;
97-
lts: boolean;
100+
xlts: boolean;
98101
}
99102

100103
/*
@@ -184,22 +187,11 @@ export function listChangesets(
184187
export async function searchChangesets(
185188
searchMode: SearchMode,
186189
): Promise<UnityChangeset[]> {
190+
const streams = searchModeToStreams(searchMode);
187191
try {
188-
switch (searchMode) {
189-
case SearchMode.All:
190-
case SearchMode.Default:
191-
case SearchMode.PreRelease:
192-
case SearchMode.SUPPORTED:
193-
return await getUnityReleases(".", searchModeToStreams(searchMode));
194-
case SearchMode.LTS:
195-
return await getUnityReleasesInLTS();
196-
case SearchMode.XLTS:
197-
return await getUnityReleasesInLTS([UnityReleaseEntitlement.XLTS]);
198-
default:
199-
throw Error(`The given search mode '${searchMode}' was not supported`);
200-
}
192+
return await getUnityReleases(".", streams, [UnityReleaseEntitlement.XLTS]);
201193
} catch {
202-
return await searchChangesetsFromDb(searchMode);
194+
return await searchChangesetsFromDb(streams);
203195
}
204196
}
205197

@@ -237,7 +229,7 @@ export function filterChangesets(
237229
(c) =>
238230
min <= c.versionNumber &&
239231
c.versionNumber <= max &&
240-
(!options.lts || c.lts) &&
232+
(options.xlts || !c.xlts) && // Include XLTS?
241233
(!regex || regex.test(c.version)) &&
242234
(!lc || lc.some((l) => l.minor == c.minor && l.lifecycle == c.lifecycle)),
243235
);
@@ -303,20 +295,17 @@ export function getAllChangesetsFromDb(): Promise<UnityChangeset[]> {
303295

304296
/**
305297
* Searches for Unity changesets from the database based on the specified search mode.
306-
* @param searchMode - The search mode to use.
298+
* @param streams - The array of release streams to filter by.
307299
* @returns A Promise that resolves to an array of UnityChangeset objects from the database.
308300
*/
309301
export function searchChangesetsFromDb(
310-
searchMode: SearchMode,
302+
streams: UnityReleaseStream[],
311303
): Promise<UnityChangeset[]> {
312304
return getAllChangesetsFromDb()
313305
.then((changesets: UnityChangeset[]) => {
314306
if (!changesets || !Array.isArray(changesets)) return [];
315307
if (changesets.length == 0) return [];
316308

317-
const streams = searchModeToStreams(searchMode);
318-
return searchMode === SearchMode.XLTS
319-
? changesets.filter((c) => streams.includes(c.stream))
320-
: changesets.filter((c) => streams.includes(c.stream) && !c.xlts);
309+
return changesets.filter((c) => streams.includes(c.stream));
321310
});
322311
}

src/unityChangeset.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import {
1313
GroupMode,
1414
SearchMode,
1515
UnityChangeset,
16+
UnityReleaseEntitlement,
1617
UnityReleaseStream,
1718
} from "./index.ts";
19+
import { searchModeToStreams } from "./utils.ts";
1820

1921
Deno.test("UnityChangeset.toNumber min", () => {
2022
assertEquals(UnityChangeset.toNumber("2018.3", false), 201803000000);
@@ -56,7 +58,7 @@ Deno.test("scrapeBetaChangesets", async () => {
5658

5759
// At least one changeset from unity 6000 version should be found.
5860
Deno.test("scrapeUnity6000Supported", async () => {
59-
const changesets = await searchChangesets(SearchMode.SUPPORTED);
61+
const changesets = await searchChangesets(SearchMode.Supported);
6062
assertNotEquals(changesets.length, 0);
6163

6264
const unity6000 = changesets.find(c => c.version.startsWith("6000"));
@@ -68,7 +70,7 @@ Deno.test("scrapeUnity6000Supported", async () => {
6870
{ searchMode: SearchMode.All },
6971
{ searchMode: SearchMode.Default },
7072
{ searchMode: SearchMode.PreRelease },
71-
{ searchMode: SearchMode.SUPPORTED },
73+
{ searchMode: SearchMode.Supported },
7274
].forEach((testcase) => {
7375
Deno.test(`filterChangesets(${JSON.stringify(testcase.searchMode)})`, async () => {
7476
const changesets = await searchChangesets(testcase.searchMode);
@@ -85,7 +87,7 @@ const changesetsForTest = [
8587
new UnityChangeset("2018.3.2f1", "000000000000"),
8688
new UnityChangeset("2018.4.0f1", "000000000000", UnityReleaseStream.LTS),
8789
new UnityChangeset("2018.4.1f1", "000000000000", UnityReleaseStream.LTS),
88-
new UnityChangeset("2018.4.2f1", "000000000000", UnityReleaseStream.LTS),
90+
new UnityChangeset("2018.4.2f1", "000000000000", UnityReleaseStream.LTS, [UnityReleaseEntitlement.XLTS]),
8991
new UnityChangeset("2019.1.0a1", "000000000000"),
9092
new UnityChangeset("2019.1.0a2", "000000000000"),
9193
new UnityChangeset("2019.1.0b1", "000000000000"),
@@ -103,11 +105,11 @@ const changesetsForTest = [
103105

104106
// filterChangesets
105107
[
106-
{ options: { min: "2018.3", max: "2018.4", grep: "", allLifecycles: false, lts: false, }, expected: 6, },
107-
{ options: { min: "2018.3", max: "", grep: "2018", allLifecycles: false, lts: false, }, expected: 6, },
108-
{ options: { min: "", max: "", grep: "", allLifecycles: false, lts: true }, expected: 3, },
109-
{ options: { min: "2019", max: "", grep: "", allLifecycles: true, lts: false, }, expected: 13, },
110-
{ options: { min: "2019", max: "", grep: "b", allLifecycles: true, lts: false, }, expected: 4, },
108+
{ options: { min: "2018.3", max: "2018.4", grep: "", allLifecycles: false, xlts: false, }, expected: 5, },
109+
{ options: { min: "2018.3", max: "", grep: "2018", allLifecycles: false, xlts: false, }, expected: 5, },
110+
{ options: { min: "2019", max: "", grep: "", allLifecycles: true, xlts: false, }, expected: 13, },
111+
{ options: { min: "2019", max: "", grep: "b", allLifecycles: true, xlts: false, }, expected: 4, },
112+
{ options: { min: "", max: "", grep: "", allLifecycles: false, xlts: true, }, expected: 14, },
111113
].forEach((testcase) => {
112114
Deno.test(`filterChangesets(${JSON.stringify(testcase.options)})`, () => {
113115
const changesets = filterChangesets(changesetsForTest, testcase.options);
@@ -129,6 +131,6 @@ const changesetsForTest = [
129131
});
130132

131133
Deno.test("scrapeArchivedChangesetsFromDb", async () => {
132-
const changesets = await searchChangesetsFromDb(SearchMode.Default);
134+
const changesets = await searchChangesetsFromDb(searchModeToStreams(SearchMode.Default));
133135
assertNotEquals(changesets.length, 0);
134136
});

src/unityGraphQL.ts

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -183,69 +183,3 @@ query GetRelease($limit: Int, $skip: Int, $version: String!, $stream: [UnityRele
183183

184184
return results;
185185
}
186-
187-
/**
188-
* Retrieves Unity releases in LTS from the GraphQL API based on entitlements.
189-
* @param entitlements - The array of entitlements to filter by.
190-
* @returns A Promise that resolves to an array of UnityChangeset objects.
191-
* @throws Error if the API response is invalid.
192-
*/
193-
export async function getUnityReleasesInLTS(
194-
entitlements: UnityReleaseEntitlement[] = [],
195-
): Promise<UnityChangeset[]> {
196-
const client = new GraphQLClient(UNITY_GRAPHQL_ENDPOINT);
197-
const query = gql`
198-
query GetReleaseMajorVersions($entitlements: [UnityReleaseEntitlement!])
199-
{
200-
getUnityReleaseMajorVersions(
201-
stream: []
202-
platform: []
203-
architecture: []
204-
entitlements: $entitlements
205-
) {
206-
version
207-
}
208-
}
209-
`;
210-
211-
const variables = {
212-
entitlements: entitlements,
213-
};
214-
215-
const cacheKey = getCacheKey(query, variables);
216-
let data: UnityReleasesMajorVersionsResponse;
217-
218-
const cached = cache.get(cacheKey);
219-
if (cached && isCacheValid(cached.timestamp)) {
220-
data = cached.data as UnityReleasesMajorVersionsResponse;
221-
} else {
222-
data = await requestWithErrorHandling<UnityReleasesMajorVersionsResponse>(
223-
client,
224-
query,
225-
variables,
226-
);
227-
cache.set(cacheKey, { data, timestamp: Date.now() });
228-
}
229-
230-
if (!data.getUnityReleaseMajorVersions) {
231-
throw new Error(
232-
"Invalid response from Unity GraphQL API: missing getUnityReleaseMajorVersions",
233-
);
234-
}
235-
236-
const results = await Promise.all(data.getUnityReleaseMajorVersions
237-
.map(async (v) => {
238-
if (!v.version) {
239-
throw new Error(
240-
"Invalid response from Unity GraphQL API: missing version in major versions",
241-
);
242-
}
243-
return await getUnityReleases(
244-
v.version,
245-
[UnityReleaseStream.LTS],
246-
entitlements,
247-
);
248-
}));
249-
250-
return results.flat();
251-
}

src/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ export function searchModeToStreams(
4040
UnityReleaseStream.BETA,
4141
];
4242
case SearchMode.LTS:
43-
case SearchMode.XLTS:
4443
return [
4544
UnityReleaseStream.LTS,
4645
];
47-
case SearchMode.SUPPORTED:
46+
case SearchMode.Supported:
4847
return [
4948
UnityReleaseStream.SUPPORTED,
5049
];

0 commit comments

Comments
 (0)