Skip to content

Commit

Permalink
Merge pull request #52 from replicatedhq/divolgin/sc-111264/release-n…
Browse files Browse the repository at this point in the history
…otes-argument-for-create-release

Add release notes to promoteRelease
  • Loading branch information
divolgin authored Jan 10, 2025
2 parents d92f049 + 17602e8 commit a8eda32
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
10 changes: 10 additions & 0 deletions pacts/npm_consumer-vp_service.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@
"description": "a request for promoting a release",
"providerState": "release promoted",
"request": {
"body": {
"channelIds": [
"channelid"
],
"releaseNotesGzip": "H4sIAAAAAAAAA1MqSs1JTSxOVcjLL0ktVgIAxFWEEQ8AAAA=",
"versionLabel": "v1.0.0"
},
"headers": {
"Content-Type": "application/json"
},
"method": "POST",
"path": "/app/1234abcd/release/1/promote"
},
Expand Down
11 changes: 8 additions & 3 deletions src/releases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ReleaseChart, exportedForTesting, KotsSingleSpec, createReleaseFromChar
import * as mockttp from "mockttp";
import * as fs from "fs-extra";
import * as path from "path";
import { sl } from "date-fns/locale";
import { gzip } from "pako";

const areReleaseChartsPushed = exportedForTesting.areReleaseChartsPushed;
const getReleaseByAppId = exportedForTesting.getReleaseByAppId;
Expand All @@ -23,7 +23,12 @@ describe("Promote Release", () => {
uponReceiving: "a request for promoting a release",
withRequest: {
method: "POST",
path: "/app/1234abcd/release/1/promote"
path: "/app/1234abcd/release/1/promote",
body: {
versionLabel: "v1.0.0",
channelIds: ["channelid"],
releaseNotesGzip: Buffer.from(gzip(JSON.stringify("release notes"))).toString("base64")
}
},
willRespondWith: {
status: 200,
Expand All @@ -35,7 +40,7 @@ describe("Promote Release", () => {
apiClient.apiToken = "abcd1234";
apiClient.endpoint = globalThis.provider.mockService.baseUrl;

return promoteReleaseByAppId(apiClient, "1234abcd", "channelid", 1, "v1.0.0")
return promoteReleaseByAppId(apiClient, "1234abcd", "channelid", 1, "v1.0.0", "release notes")
.then(() => {
expect(true).toEqual(true);
})
Expand Down
9 changes: 6 additions & 3 deletions src/releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,23 @@ function isSupportedExt(ext: string): boolean {
return supportedExts.includes(ext);
}

export async function promoteRelease(vendorPortalApi: VendorPortalApi, appSlug: string, channelId: string, releaseSequence: number, version: string) {
export async function promoteRelease(vendorPortalApi: VendorPortalApi, appSlug: string, channelId: string, releaseSequence: number, version: string, releaseNotes?: string) {
// 1. get the app id from the app slug
const app = await getApplicationDetails(vendorPortalApi, appSlug);

// 2. promote the release
await promoteReleaseByAppId(vendorPortalApi, app.id, channelId, releaseSequence, version);
await promoteReleaseByAppId(vendorPortalApi, app.id, channelId, releaseSequence, version, releaseNotes);
}

async function promoteReleaseByAppId(vendorPortalApi: VendorPortalApi, appId: string, channelId: string, releaseSequence: number, version: string) {
async function promoteReleaseByAppId(vendorPortalApi: VendorPortalApi, appId: string, channelId: string, releaseSequence: number, version: string, releaseNotes?: string) {
const http = await vendorPortalApi.client();
const reqBody = {
versionLabel: version,
channelIds: [channelId]
};
if (releaseNotes) {
reqBody["releaseNotesGzip"] = gzipData(releaseNotes);
}
const uri = `${vendorPortalApi.endpoint}/app/${appId}/release/${releaseSequence}/promote`;
const res = await http.post(uri, JSON.stringify(reqBody));
if (res.message.statusCode != 200) {
Expand Down

0 comments on commit a8eda32

Please sign in to comment.