From 603ba87958e3b14c5be7ef081026009170b61ffd Mon Sep 17 00:00:00 2001 From: Pavel Yudakov Date: Sun, 15 Sep 2024 13:02:04 +0300 Subject: [PATCH 1/5] fix: limit on the number of versions per request from electron-release-server --- .../electron-release-server/src/PublisherERS.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/publisher/electron-release-server/src/PublisherERS.ts b/packages/publisher/electron-release-server/src/PublisherERS.ts index 20495f41bc..631ccdca10 100644 --- a/packages/publisher/electron-release-server/src/PublisherERS.ts +++ b/packages/publisher/electron-release-server/src/PublisherERS.ts @@ -29,7 +29,7 @@ interface ERSVersion { interface ERSVersionSorted { total: number; offset: number; - page: number; + page: string; items: ERSVersion[]; } @@ -93,10 +93,16 @@ export default class PublisherERS extends PublisherBase { const { packageJSON } = makeResult; const artifacts = makeResult.artifacts.filter((artifactPath) => path.basename(artifactPath).toLowerCase() !== 'releases'); - const versions: ERSVersionSorted = await (await authFetch('versions/sorted')).json(); - // Find the version with the same name and flavor - const existingVersion = versions['items'].find((version) => version.name === packageJSON.version && version.flavor.name === flavor); + const findVersion = (versions: ERSVersion[]) => versions.find((version) => version.name === packageJSON.version && version.flavor.name === flavor); + + let versions: ERSVersionSorted = await (await authFetch('versions/sorted')).json(); + let existingVersion: ERSVersion | undefined = findVersion(versions.items); + + while (!existingVersion && versions.offset + versions.items.length < versions.total) { + versions = await (await authFetch(`versions/sorted?page=${Number(versions.page) + 1}`)).json(); + existingVersion = findVersion(versions.items); + } let channel = 'stable'; if (config.channel) { From 028e82aed43eb187c66a5261f99944192f5cf563 Mon Sep 17 00:00:00 2001 From: Pavel Yudakov Date: Sun, 15 Sep 2024 13:13:35 +0300 Subject: [PATCH 2/5] fix: type ERSVersionSorted --- packages/publisher/electron-release-server/src/PublisherERS.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publisher/electron-release-server/src/PublisherERS.ts b/packages/publisher/electron-release-server/src/PublisherERS.ts index 631ccdca10..03d434b307 100644 --- a/packages/publisher/electron-release-server/src/PublisherERS.ts +++ b/packages/publisher/electron-release-server/src/PublisherERS.ts @@ -29,7 +29,7 @@ interface ERSVersion { interface ERSVersionSorted { total: number; offset: number; - page: string; + page: string | number; items: ERSVersion[]; } From bed014868c1e0b8999edc223326d1b84404fbcc1 Mon Sep 17 00:00:00 2001 From: Pavel Yudakov Date: Thu, 23 Jan 2025 13:11:01 +0300 Subject: [PATCH 3/5] chore: another way to fix problem --- .../src/PublisherERS.ts | 40 +++++++------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/packages/publisher/electron-release-server/src/PublisherERS.ts b/packages/publisher/electron-release-server/src/PublisherERS.ts index 767807a43c..834aa529be 100644 --- a/packages/publisher/electron-release-server/src/PublisherERS.ts +++ b/packages/publisher/electron-release-server/src/PublisherERS.ts @@ -26,13 +26,6 @@ interface ERSVersion { flavor: ERSFlavor; } -interface ERSVersionSorted { - total: number; - offset: number; - page: string | number; - items: ERSVersion[]; -} - const fetchAndCheckStatus = async (url: RequestInfo, init?: RequestInit): Promise => { const result = await fetch(url, init); if (result.ok) { @@ -94,25 +87,22 @@ export default class PublisherERS extends PublisherBase { const artifacts = makeResult.artifacts.filter((artifactPath) => path.basename(artifactPath).toLowerCase() !== 'releases'); // Find the version with the same name and flavor - const findVersion = (versions: ERSVersion[]) => versions.find((version) => version.name === packageJSON.version && version.flavor.name === flavor); - - let versions: ERSVersionSorted = await (await authFetch('versions/sorted')).json(); - let existingVersion: ERSVersion | undefined = findVersion(versions.items); - - while (!existingVersion && versions.offset + versions.items.length < versions.total) { - versions = await (await authFetch(`versions/sorted?page=${Number(versions.page) + 1}`)).json(); - existingVersion = findVersion(versions.items); - } - - let channel = 'stable'; + const existingVersion = await authFetch(`api/version?name=${packageJSON.version}&flavor=${flavor}`) + .then(res => res.json()) + .then(versions => versions.find((version) => { + return version.name === packageJSON.version && version.flavor.name === flavor + })) + .catch(() => undefined) + + let channel = "stable" if (config.channel) { - channel = config.channel; - } else if (packageJSON.version.includes('rc')) { - channel = 'rc'; - } else if (packageJSON.version.includes('beta')) { - channel = 'beta'; - } else if (packageJSON.version.includes('alpha')) { - channel = 'alpha'; + channel = config.channel + } else if (packageJSON.version.includes("rc")) { + channel = "rc" + } else if (packageJSON.version.includes("beta")) { + channel = "beta" + } else if (packageJSON.version.includes("alpha")) { + channel = "alpha" } if (!existingVersion) { From af029501f889107d0e4b20444fc0e4d043fe4757 Mon Sep 17 00:00:00 2001 From: Pavel Yudakov Date: Thu, 23 Jan 2025 13:16:09 +0300 Subject: [PATCH 4/5] chore: fix types --- .../publisher/electron-release-server/src/PublisherERS.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/publisher/electron-release-server/src/PublisherERS.ts b/packages/publisher/electron-release-server/src/PublisherERS.ts index 834aa529be..dc824c664c 100644 --- a/packages/publisher/electron-release-server/src/PublisherERS.ts +++ b/packages/publisher/electron-release-server/src/PublisherERS.ts @@ -87,9 +87,9 @@ export default class PublisherERS extends PublisherBase { const artifacts = makeResult.artifacts.filter((artifactPath) => path.basename(artifactPath).toLowerCase() !== 'releases'); // Find the version with the same name and flavor - const existingVersion = await authFetch(`api/version?name=${packageJSON.version}&flavor=${flavor}`) + const existingVersion: ERSVersion = await authFetch(`api/version?name=${packageJSON.version}&flavor=${flavor}`) .then(res => res.json()) - .then(versions => versions.find((version) => { + .then(versions => versions.find((version: ERSVersion) => { return version.name === packageJSON.version && version.flavor.name === flavor })) .catch(() => undefined) From 1c90289a14664f664ddda2ed12eea31c95b6f4ae Mon Sep 17 00:00:00 2001 From: Pavel Yudakov Date: Thu, 23 Jan 2025 13:31:17 +0300 Subject: [PATCH 5/5] chore: fix codestyle --- .../src/PublisherERS.ts | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/publisher/electron-release-server/src/PublisherERS.ts b/packages/publisher/electron-release-server/src/PublisherERS.ts index dc824c664c..e4bbe34ebf 100644 --- a/packages/publisher/electron-release-server/src/PublisherERS.ts +++ b/packages/publisher/electron-release-server/src/PublisherERS.ts @@ -88,21 +88,23 @@ export default class PublisherERS extends PublisherBase { // Find the version with the same name and flavor const existingVersion: ERSVersion = await authFetch(`api/version?name=${packageJSON.version}&flavor=${flavor}`) - .then(res => res.json()) - .then(versions => versions.find((version: ERSVersion) => { - return version.name === packageJSON.version && version.flavor.name === flavor - })) - .catch(() => undefined) - - let channel = "stable" + .then((res) => res.json()) + .then((versions) => + versions.find((version: ERSVersion) => { + return version.name === packageJSON.version && version.flavor.name === flavor; + }) + ) + .catch(() => undefined); + + let channel = 'stable'; if (config.channel) { - channel = config.channel - } else if (packageJSON.version.includes("rc")) { - channel = "rc" - } else if (packageJSON.version.includes("beta")) { - channel = "beta" - } else if (packageJSON.version.includes("alpha")) { - channel = "alpha" + channel = config.channel; + } else if (packageJSON.version.includes('rc')) { + channel = 'rc'; + } else if (packageJSON.version.includes('beta')) { + channel = 'beta'; + } else if (packageJSON.version.includes('alpha')) { + channel = 'alpha'; } if (!existingVersion) {