@@ -4,8 +4,10 @@ import {getRepoDetails, getReleaseDetails, createIssue} from "../github.js";
44import db from "../db.js" ;
55import { downloader } from "../utils/downloader.js" ;
66import { 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
1012const 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+
151173async 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