Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
jdewinne committed Apr 18, 2024
2 parents 58242a8 + 4275ec6 commit d128a2b
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 147 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test: build
.PHONY: prettier
prettier:
npm run prettier

.PHONY: publish
publish: test
npm publish
39 changes: 7 additions & 32 deletions dist/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ async function createChannel(vendorPortalApi, appSlug, channelName) {
}
const createChannelBody = JSON.parse(await createChannelRes.readBody());
console.log(`Created channel with id ${createChannelBody.channel.id}`);
return {
name: createChannelBody.channel.name,
id: createChannelBody.channel.id,
slug: createChannelBody.channel.channelSlug
};
return { name: createChannelBody.channel.name, id: createChannelBody.channel.id, slug: createChannelBody.channel.channelSlug };
}
exports.createChannel = createChannel;
async function getChannelDetails(vendorPortalApi, appSlug, { slug, name }) {
Expand All @@ -40,10 +36,7 @@ async function getChannelDetails(vendorPortalApi, appSlug, { slug, name }) {
throw new Error(`Must provide either a channel slug or channel name`);
}
// 2. get the channel id from the channel slug
return await getChannelByApplicationId(vendorPortalApi, app.id, {
slug,
name
});
return await getChannelByApplicationId(vendorPortalApi, app.id, { slug, name });
}
exports.getChannelDetails = getChannelDetails;
async function getChannelByApplicationId(vendorPortalApi, appid, { slug, name }) {
Expand All @@ -55,17 +48,12 @@ async function getChannelByApplicationId(vendorPortalApi, appid, { slug, name })
throw new Error(`Failed to list channels: Server responded with ${listChannelsRes.message.statusCode}`);
}
const listChannelsBody = JSON.parse(await listChannelsRes.readBody());
const channel = await findChannelDetailsInOutput(listChannelsBody.channels, {
slug,
name
});
const channel = await findChannelDetailsInOutput(listChannelsBody.channels, { slug, name });
console.log(`Found channel for channel slug ${channel.slug}`);
return channel;
}
async function archiveChannel(vendorPortalApi, appSlug, channelSlug) {
const channel = await getChannelDetails(vendorPortalApi, appSlug, {
slug: channelSlug
});
const channel = await getChannelDetails(vendorPortalApi, appSlug, { slug: channelSlug });
const http = await vendorPortalApi.client();
// 1. get the app id from the app slug
const app = await (0, applications_1.getApplicationDetails)(vendorPortalApi, appSlug);
Expand All @@ -81,24 +69,11 @@ exports.archiveChannel = archiveChannel;
async function findChannelDetailsInOutput(channels, { slug, name }) {
for (const channel of channels) {
if (slug && channel.channelSlug == slug) {
return {
name: channel.name,
id: channel.id,
slug: channel.channelSlug,
releaseSequence: channel.releaseSequence
};
return { name: channel.name, id: channel.id, slug: channel.channelSlug, releaseSequence: channel.releaseSequence };
}
if (name && channel.name == name) {
return {
name: channel.name,
id: channel.id,
slug: channel.channelSlug,
releaseSequence: channel.releaseSequence
};
return { name: channel.name, id: channel.id, slug: channel.channelSlug, releaseSequence: channel.releaseSequence };
}
}
return Promise.reject({
channel: null,
reason: `Could not find channel with slug ${slug} or name ${name}`
});
return Promise.reject({ channel: null, reason: `Could not find channel with slug ${slug} or name ${name}` });
}
22 changes: 4 additions & 18 deletions dist/channels.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ describe("findChannelDetailsInOutput", () => {
}
];
const channelSlug = "ci-reliability-matrix";
const channel = await findChannelDetailsInOutput(channels, {
slug: channelSlug
});
const channel = await findChannelDetailsInOutput(channels, { slug: channelSlug });
expect(channel.id).toBe("channelid2");
});
});
Expand All @@ -41,18 +39,8 @@ describe("ChannelsService", () => {
test("should return channel", () => {
const expectedChannels = {
channels: [
{
id: "1234abcd",
name: "Stable",
channelSlug: "stable",
releaseSequence: 1
},
{
id: "5678efgh",
name: "Beta",
channelSlug: "beta",
releaseSequence: 2
}
{ id: "1234abcd", name: "Stable", channelSlug: "stable", releaseSequence: 1 },
{ id: "5678efgh", name: "Beta", channelSlug: "beta", releaseSequence: 2 }
]
};
const channelsInteraction = new pact_1.Interaction()
Expand All @@ -77,9 +65,7 @@ describe("ChannelsService", () => {
const apiClient = new configuration_1.VendorPortalApi();
apiClient.apiToken = "abcd1234";
apiClient.endpoint = globalThis.provider.mockService.baseUrl;
return getChannelByApplicationId(apiClient, "1234abcd", {
slug: "stable"
}).then(channel => {
return getChannelByApplicationId(apiClient, "1234abcd", { slug: "stable" }).then(channel => {
expect(channel.id).toEqual(expectedChannels.channels[0].id);
expect(channel.name).toEqual(expectedChannels.channels[0].name);
expect(channel.slug).toEqual(expectedChannels.channels[0].channelSlug);
Expand Down
11 changes: 2 additions & 9 deletions dist/customers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ async function createCustomer(vendorPortalApi, appSlug, name, email, licenseType
createCustomerReqBody["is_kots_install_enabled"] = isKotsInstallEnabled;
}
if (channelSlug) {
const channel = await (0, channels_1.getChannelDetails)(vendorPortalApi, appSlug, {
slug: channelSlug
});
const channel = await (0, channels_1.getChannelDetails)(vendorPortalApi, appSlug, { slug: channelSlug });
createCustomerReqBody["channel_id"] = channel.id;
}
// expiresIn is in days, if it's 0 or less, ignore it - non-expiring license
Expand Down Expand Up @@ -65,12 +63,7 @@ async function createCustomer(vendorPortalApi, appSlug, name, email, licenseType
if (downloadLicenseRes.message.statusCode == 200) {
downloadLicenseBody = await downloadLicenseRes.readBody();
}
return {
name: name,
customerId: createCustomerBody.customer.id,
licenseId: createCustomerBody.customer.installationId,
license: downloadLicenseBody
};
return { name: name, customerId: createCustomerBody.customer.id, licenseId: createCustomerBody.customer.installationId, license: downloadLicenseBody };
}
catch (error) {
console.error(error.message);
Expand Down
10 changes: 2 additions & 8 deletions dist/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ async function createRelease(vendorPortalApi, appSlug, yamlDir) {
throw new Error(`Release ${createReleaseBody.release.sequence} is not ready`);
}
}
return {
sequence: createReleaseBody.release.sequence,
charts: createReleaseBody.release.charts
};
return { sequence: createReleaseBody.release.sequence, charts: createReleaseBody.release.charts };
}
exports.createRelease = createRelease;
async function createReleaseFromChart(vendorPortalApi, appSlug, chart) {
Expand Down Expand Up @@ -72,10 +69,7 @@ async function createReleaseFromChart(vendorPortalApi, appSlug, chart) {
throw new Error(`Release ${createReleaseBody.release.sequence} is not ready`);
}
}
return {
sequence: createReleaseBody.release.sequence,
charts: createReleaseBody.release.charts
};
return { sequence: createReleaseBody.release.sequence, charts: createReleaseBody.release.charts };
}
exports.createReleaseFromChart = createReleaseFromChart;
const gzipData = (data) => {
Expand Down
7 changes: 1 addition & 6 deletions dist/releases.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ describe("areReleaseChartsPushed", () => {
it("throws an error if any chart has error status", () => {
const charts = [
{ name: "chart1", version: "1.0.0", status: "pushed", error: null },
{
name: "chart2",
version: "1.0.0",
status: "error",
error: "Some error message"
}
{ name: "chart2", version: "1.0.0", status: "error", error: "Some error message" }
];
expect(() => {
areReleaseChartsPushed(charts);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"jest": "^29.5.0",
"mockttp": "^3.10.1",
"prettier": "^3.2.5",
"prettier": "^3.2.5",
"ts-jest": "^29.1.0"
}
}
22 changes: 4 additions & 18 deletions src/channels.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ describe("findChannelDetailsInOutput", () => {
}
];
const channelSlug = "ci-reliability-matrix";
const channel = await findChannelDetailsInOutput(channels, {
slug: channelSlug
});
const channel = await findChannelDetailsInOutput(channels, { slug: channelSlug });
expect(channel.id).toBe("channelid2");
});
});
Expand All @@ -43,18 +41,8 @@ describe("ChannelsService", () => {
test("should return channel", () => {
const expectedChannels = {
channels: [
{
id: "1234abcd",
name: "Stable",
channelSlug: "stable",
releaseSequence: 1
},
{
id: "5678efgh",
name: "Beta",
channelSlug: "beta",
releaseSequence: 2
}
{ id: "1234abcd", name: "Stable", channelSlug: "stable", releaseSequence: 1 },
{ id: "5678efgh", name: "Beta", channelSlug: "beta", releaseSequence: 2 }
]
};

Expand Down Expand Up @@ -83,9 +71,7 @@ describe("ChannelsService", () => {
apiClient.apiToken = "abcd1234";
apiClient.endpoint = globalThis.provider.mockService.baseUrl;

return getChannelByApplicationId(apiClient, "1234abcd", {
slug: "stable"
}).then(channel => {
return getChannelByApplicationId(apiClient, "1234abcd", { slug: "stable" }).then(channel => {
expect(channel.id).toEqual(expectedChannels.channels[0].id);
expect(channel.name).toEqual(expectedChannels.channels[0].name);
expect(channel.slug).toEqual(expectedChannels.channels[0].channelSlug);
Expand Down
39 changes: 7 additions & 32 deletions src/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ export async function createChannel(vendorPortalApi: VendorPortalApi, appSlug: s
const createChannelBody: any = JSON.parse(await createChannelRes.readBody());

console.log(`Created channel with id ${createChannelBody.channel.id}`);
return {
name: createChannelBody.channel.name,
id: createChannelBody.channel.id,
slug: createChannelBody.channel.channelSlug
};
return { name: createChannelBody.channel.name, id: createChannelBody.channel.id, slug: createChannelBody.channel.channelSlug };
}

interface ChannelIdentifier {
Expand All @@ -55,10 +51,7 @@ export async function getChannelDetails(vendorPortalApi: VendorPortalApi, appSlu
}

// 2. get the channel id from the channel slug
return await getChannelByApplicationId(vendorPortalApi, app.id, {
slug,
name
});
return await getChannelByApplicationId(vendorPortalApi, app.id, { slug, name });
}

async function getChannelByApplicationId(vendorPortalApi: VendorPortalApi, appid: string, { slug, name }: ChannelIdentifier): Promise<Channel> {
Expand All @@ -71,19 +64,14 @@ async function getChannelByApplicationId(vendorPortalApi: VendorPortalApi, appid
}
const listChannelsBody: any = JSON.parse(await listChannelsRes.readBody());

const channel = await findChannelDetailsInOutput(listChannelsBody.channels, {
slug,
name
});
const channel = await findChannelDetailsInOutput(listChannelsBody.channels, { slug, name });
console.log(`Found channel for channel slug ${channel.slug}`);

return channel;
}

export async function archiveChannel(vendorPortalApi: VendorPortalApi, appSlug: string, channelSlug: string) {
const channel = await getChannelDetails(vendorPortalApi, appSlug, {
slug: channelSlug
});
const channel = await getChannelDetails(vendorPortalApi, appSlug, { slug: channelSlug });

const http = await vendorPortalApi.client();

Expand All @@ -102,24 +90,11 @@ export async function archiveChannel(vendorPortalApi: VendorPortalApi, appSlug:
async function findChannelDetailsInOutput(channels: any[], { slug, name }: ChannelIdentifier): Promise<Channel> {
for (const channel of channels) {
if (slug && channel.channelSlug == slug) {
return {
name: channel.name,
id: channel.id,
slug: channel.channelSlug,
releaseSequence: channel.releaseSequence
};
return { name: channel.name, id: channel.id, slug: channel.channelSlug, releaseSequence: channel.releaseSequence };
}
if (name && channel.name == name) {
return {
name: channel.name,
id: channel.id,
slug: channel.channelSlug,
releaseSequence: channel.releaseSequence
};
return { name: channel.name, id: channel.id, slug: channel.channelSlug, releaseSequence: channel.releaseSequence };
}
}
return Promise.reject({
channel: null,
reason: `Could not find channel with slug ${slug} or name ${name}`
});
return Promise.reject({ channel: null, reason: `Could not find channel with slug ${slug} or name ${name}` });
}
11 changes: 2 additions & 9 deletions src/customers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ export async function createCustomer(vendorPortalApi: VendorPortalApi, appSlug:
createCustomerReqBody["is_kots_install_enabled"] = isKotsInstallEnabled;
}
if (channelSlug) {
const channel = await getChannelDetails(vendorPortalApi, appSlug, {
slug: channelSlug
});
const channel = await getChannelDetails(vendorPortalApi, appSlug, { slug: channelSlug });
createCustomerReqBody["channel_id"] = channel.id;
}
// expiresIn is in days, if it's 0 or less, ignore it - non-expiring license
Expand Down Expand Up @@ -86,12 +84,7 @@ export async function createCustomer(vendorPortalApi: VendorPortalApi, appSlug:
downloadLicenseBody = await downloadLicenseRes.readBody();
}

return {
name: name,
customerId: createCustomerBody.customer.id,
licenseId: createCustomerBody.customer.installationId,
license: downloadLicenseBody
};
return { name: name, customerId: createCustomerBody.customer.id, licenseId: createCustomerBody.customer.installationId, license: downloadLicenseBody };
} catch (error) {
console.error(error.message);
throw error;
Expand Down
7 changes: 1 addition & 6 deletions src/releases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,7 @@ describe("areReleaseChartsPushed", () => {
it("throws an error if any chart has error status", () => {
const charts: ReleaseChart[] = [
{ name: "chart1", version: "1.0.0", status: "pushed", error: null },
{
name: "chart2",
version: "1.0.0",
status: "error",
error: "Some error message"
}
{ name: "chart2", version: "1.0.0", status: "error", error: "Some error message" }
];

expect(() => {
Expand Down
10 changes: 2 additions & 8 deletions src/releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ export async function createRelease(vendorPortalApi: VendorPortalApi, appSlug: s
throw new Error(`Release ${createReleaseBody.release.sequence} is not ready`);
}
}
return {
sequence: createReleaseBody.release.sequence,
charts: createReleaseBody.release.charts
};
return { sequence: createReleaseBody.release.sequence, charts: createReleaseBody.release.charts };
}

export async function createReleaseFromChart(vendorPortalApi: VendorPortalApi, appSlug: string, chart: string): Promise<Release> {
Expand Down Expand Up @@ -109,10 +106,7 @@ export async function createReleaseFromChart(vendorPortalApi: VendorPortalApi, a
throw new Error(`Release ${createReleaseBody.release.sequence} is not ready`);
}
}
return {
sequence: createReleaseBody.release.sequence,
charts: createReleaseBody.release.charts
};
return { sequence: createReleaseBody.release.sequence, charts: createReleaseBody.release.charts };
}

export const gzipData = (data: any) => {
Expand Down

0 comments on commit d128a2b

Please sign in to comment.