Skip to content

Commit ca40a5f

Browse files
committed
chore: extension publish working
1 parent 0681794 commit ca40a5f

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

src/api/publishGithubRelease.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Refer https://json-schema.org/understanding-json-schema/index.html
22
import {HTTP_STATUS_CODES} from "@aicore/libcommonutils";
3-
import {getRepoDetails, getReleaseDetails, createIssue, getOrgDetails} from "../github.js";
3+
import {getRepoDetails, getReleaseDetails, createIssue, getOrgDetails, commentOnIssue} from "../github.js";
44
import db from "../db.js";
55
import {downloader} from "../utils/downloader.js";
66
import {ZipUtils} from "../utils/zipUtils.js";
@@ -13,7 +13,9 @@ import fs from "fs";
1313
import {S3} from "../s3.js";
1414
import {syncRegistryDBToS3JSON} from "../utils/sync.js";
1515

16-
const RELEASE_STATUS_PROCESSING = "processing";
16+
const RELEASE_STATUS_PROCESSING = "processing",
17+
RELEASE_STATUS_FAILED = "failed",
18+
RELEASE_STATUS_PUBLISHED = "published";
1719

1820
const schema = {
1921
schema: {
@@ -270,9 +272,9 @@ async function _downloadAndValidateExtensionZip(githubReleaseTag, extensionZipAs
270272
updatePublishErrors: true,
271273
error};
272274
}
273-
const {existingRegistryPKGVersion, registryPKGJSON} =
275+
const {existingRegistryPKGVersion, registryPKGJSON, existingRegistryDocumentId} =
274276
await _validateExtensionPackageJson(githubReleaseTag, packageJSON, repoDetails, issueMessages);
275-
return {extensionZipPath, existingRegistryPKGVersion, registryPKGJSON};
277+
return {extensionZipPath, existingRegistryPKGVersion, existingRegistryDocumentId, registryPKGJSON};
276278
}
277279

278280
async function _createGithubIssue(release) {
@@ -290,7 +292,7 @@ async function _updatePublishErrors(release, issueMessages) {
290292
const releaseRef = `${release.owner}/${release.repo}/${release.tag}`;
291293
console.log(`existing release ${releaseRef} found: `, existingReleaseInfo);
292294
existingReleaseInfo.errors = issueMessages;
293-
existingReleaseInfo.status = "failed";
295+
existingReleaseInfo.status = RELEASE_STATUS_FAILED;
294296
existingReleaseInfo.lastUpdatedDateUTC = Date.now();
295297
if(!existingReleaseInfo.githubIssue){
296298
existingReleaseInfo.githubIssue = await _createGithubIssue(release);
@@ -332,8 +334,9 @@ async function _UpdateReleaseInfo(release, existingReleaseInfo) {
332334
githubIssue: await _createGithubIssue(release)
333335
};
334336
releaseInfo[FIELD_RELEASE_ID] = releaseRef;
335-
console.log(`Putting release ${releaseRef} details to db`,
336-
await db.put(RELEASE_DETAILS_TABLE, releaseInfo));
337+
let {documentId, isSuccess } = await db.put(RELEASE_DETAILS_TABLE, releaseInfo);
338+
releaseInfo.documentId = documentId;
339+
console.log(`Putting release ${releaseRef} details to db success: ${isSuccess}, documentId: ${documentId}`);
337340
return await _getReleaseInfo(release);
338341
}
339342
} catch (e) {
@@ -343,6 +346,24 @@ async function _UpdateReleaseInfo(release, existingReleaseInfo) {
343346
}
344347
}
345348

349+
async function _UpdateReleaseSuccess(release, existingReleaseInfo) {
350+
if(!existingReleaseInfo || !existingReleaseInfo.documentId) {
351+
console.error("_UpdateReleaseSuccess called without an existing release entry.");
352+
throw new Error("Internal error. this shouldn't have happened. Please raise an issue in https://github.com/phcode-dev/phoenix/issues");
353+
}
354+
existingReleaseInfo.errors = [];
355+
existingReleaseInfo.published = true;
356+
existingReleaseInfo.status = RELEASE_STATUS_PUBLISHED;
357+
existingReleaseInfo.lastUpdatedDateUTC = Date.now();
358+
console.log("Update release table success: ", await db.update(RELEASE_DETAILS_TABLE, existingReleaseInfo.documentId,
359+
existingReleaseInfo));
360+
if(existingReleaseInfo.githubIssue){
361+
console.error("Github issue is expected in _UpdateReleaseSuccess! ");
362+
await commentOnIssue(release.owner, release.repo, existingReleaseInfo.githubIssue,
363+
"Extension successfully published to store. You can close this issue at any time.");
364+
}
365+
}
366+
346367
async function _updateRegistryJSONinDB(existingRegistryPKGVersion, existingRegistryDocumentId, registryPKGJSON,
347368
issueMessages) {
348369
let status;
@@ -405,6 +426,8 @@ export async function publishGithubRelease(request, reply) {
405426

406427
await syncRegistryDBToS3JSON();
407428

429+
await _UpdateReleaseSuccess(githubReleaseTag, existingReleaseInfo);
430+
408431
const response = {
409432
message: "done"
410433
};

0 commit comments

Comments
 (0)