Skip to content

Commit 7063e2c

Browse files
committed
chore: package.json validation in zip
1 parent 0313fd1 commit 7063e2c

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/api/publishGithubRelease.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import {getRepoDetails, getReleaseDetails, createIssue} from "../github.js";
44
import db from "../db.js";
55
import {downloader} from "../utils/downloader.js";
66
import {ZipUtils} from "../utils/zipUtils.js";
7-
import {FIELD_RELEASE_ID, RELEASE_DETAILS_TABLE, EXTENSION_SIZE_LIMIT_MB, BASE_URL,
8-
EXTENSION_DOWNLOAD_DIR, PROCESSING_TIMEOUT_MS} from "../constants.js";
7+
import {
8+
FIELD_RELEASE_ID, RELEASE_DETAILS_TABLE, EXTENSION_SIZE_LIMIT_MB, BASE_URL,
9+
EXTENSION_DOWNLOAD_DIR, PROCESSING_TIMEOUT_MS, EXTENSIONS_DETAILS_TABLE, FIELD_EXTENSION_ID
10+
} from "../constants.js";
911

1012
const RELEASE_STATUS_PROCESSING = "processing";
1113

@@ -148,6 +150,26 @@ function _validateGitHubReleaseAssets(githubReleaseDetails, issueMessages) {
148150
return extensionZipAsset;
149151
}
150152

153+
async function _validateExtensionPackageJson(githubReleaseTag, packageJSON, issueMessages) {
154+
const queryObj = {};
155+
const newOwner = `github:${githubReleaseTag.owner}`;
156+
const releaseRef = `${githubReleaseTag.owner}/${githubReleaseTag.repo}/${githubReleaseTag.tag}`;
157+
queryObj[FIELD_EXTENSION_ID] = packageJSON.name;
158+
let registryPKG = await db.getFromIndex(EXTENSIONS_DETAILS_TABLE, queryObj);
159+
if(!registryPKG.isSuccess){
160+
// unexpected error
161+
throw new Error("Error getting extensionPKG details from db: " + releaseRef);
162+
}
163+
registryPKG = registryPKG.documents.length === 1 ? registryPKG.documents[0] : null;
164+
if(registryPKG && registryPKG.owner !== newOwner) {
165+
let error = `Extension of the same name "${packageJSON.name}" already exists (owned by https://github.com/${registryPKG.owner.split(":")[1]}).`;
166+
issueMessages.push(error);
167+
throw {status: HTTP_STATUS_CODES.BAD_REQUEST,
168+
updatePublishErrors: true,
169+
error};
170+
}
171+
}
172+
151173
async function _downloadAndValidateExtensionZip(githubReleaseTag, extensionZipAsset, issueMessages) {
152174
const targetPath = `${EXTENSION_DOWNLOAD_DIR}/${githubReleaseTag.owner}_${githubReleaseTag.repo}_${githubReleaseTag.tag}_${extensionZipAsset.name}`;
153175
await downloader.downloadFile(extensionZipAsset.browser_download_url, targetPath);
@@ -175,6 +197,7 @@ async function _downloadAndValidateExtensionZip(githubReleaseTag, extensionZipAs
175197
updatePublishErrors: true,
176198
error};
177199
}
200+
await _validateExtensionPackageJson(githubReleaseTag, packageJSON, issueMessages);
178201
return targetPath;
179202
}
180203

0 commit comments

Comments
 (0)