Skip to content

Commit

Permalink
fix(electron-release-publisher): change api/version endpoint in Publi…
Browse files Browse the repository at this point in the history
…sherERS to use versions/sorted (#3431)
  • Loading branch information
kgallagher52 authored Dec 1, 2023
1 parent 30af3b2 commit c56f406
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
12 changes: 10 additions & 2 deletions packages/publisher/electron-release-server/src/PublisherERS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ interface ERSVersion {
flavor: ERSFlavor;
}

interface ERSVersionSorted {
total: number;
offset: number;
page: number;
items: ERSVersion[];
}

const fetchAndCheckStatus = async (url: RequestInfo, init?: RequestInit): Promise<Response> => {
const result = await fetch(url, init);
if (result.ok) {
Expand Down Expand Up @@ -86,9 +93,10 @@ export default class PublisherERS extends PublisherBase<PublisherERSConfig> {
const { packageJSON } = makeResult;
const artifacts = makeResult.artifacts.filter((artifactPath) => path.basename(artifactPath).toLowerCase() !== 'releases');

const versions: ERSVersion[] = await (await authFetch('api/version')).json();
const versions: ERSVersionSorted = await (await authFetch('versions/sorted')).json();

// Find the version with the same name and flavor
const existingVersion = versions.find((version) => version.name === packageJSON.version && version.flavor.name === flavor);
const existingVersion = versions['items'].find((version) => version.name === packageJSON.version && version.flavor.name === flavor);

let channel = 'stable';
if (config.channel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ describe('PublisherERS', () => {
// mock login
fetch.postOnce('path:/api/auth/login', { body: { token }, status: 200 });
// mock fetch all existing versions
fetch.getOnce('path:/api/version', { body: [{ name: '2.0.0', assets: [], flavor: { name: 'default' } }], status: 200 });
fetch.getOnce('path:/versions/sorted', {
body: { total: 1, offset: 0, page: 0, items: [{ name: '2.0.0', assets: [], flavor: { name: 'default' } }] },
status: 200,
});
// mock creating a new version
fetch.postOnce('path:/api/version', { status: 200 });
// mock asset upload
Expand Down Expand Up @@ -83,7 +86,10 @@ describe('PublisherERS', () => {
// mock login
fetch.postOnce('path:/api/auth/login', { body: { token }, status: 200 });
// mock fetch all existing versions
fetch.getOnce('path:/api/version', { body: [{ name: '2.0.0', assets: [], flavor: { name: 'lite' } }], status: 200 });
fetch.getOnce('path:/versions/sorted', {
body: { total: 1, offset: 0, page: 0, items: [{ name: '2.0.0', assets: [], flavor: { name: 'lite' } }] },
status: 200,
});
// mock asset upload
fetch.post('path:/api/asset', { status: 200 });

Expand Down Expand Up @@ -123,8 +129,13 @@ describe('PublisherERS', () => {
// mock login
fetch.postOnce('path:/api/auth/login', { body: { token }, status: 200 });
// mock fetch all existing versions
fetch.getOnce('path:/api/version', {
body: [{ name: '2.0.0', assets: [{ name: 'existing-artifact', platform: 'linux_64' }], flavor: { name: 'default' } }],
fetch.getOnce('path:/versions/sorted', {
body: {
total: 1,
offset: 0,
page: 0,
items: [{ name: '2.0.0', assets: [{ name: 'existing-artifact', platform: 'linux_64' }], flavor: { name: 'default' } }],
},
status: 200,
});

Expand Down Expand Up @@ -161,7 +172,10 @@ describe('PublisherERS', () => {
// mock login
fetch.postOnce('path:/api/auth/login', { body: { token }, status: 200 });
// mock fetch all existing versions
fetch.getOnce('path:/api/version', { body: [{ name: '2.0.0', assets: [{ name: 'existing-artifact' }], flavor: { name: 'default' } }], status: 200 });
fetch.getOnce('path:/versions/sorted', {
body: { total: 1, offset: 0, page: 0, items: [{ name: '2.0.0', assets: [{ name: 'existing-artifact' }], flavor: { name: 'default' } }] },
status: 200,
});
// mock creating a new version
fetch.postOnce('path:/api/version', { status: 200 });
// mock asset upload
Expand Down

0 comments on commit c56f406

Please sign in to comment.