@@ -21,7 +21,7 @@ import {
2121import { ProgressCallback , UserCancellationException } from "../commandRunner" ;
2222import { RequestError } from "@octokit/types/dist-types" ;
2323import { QueryMetadata } from "../pure/interface-types" ;
24- import { REPO_REGEX } from "../pure/helpers-pure" ;
24+ import { getErrorMessage , REPO_REGEX } from "../pure/helpers-pure" ;
2525import * as ghApiClient from "./gh-api/gh-api-client" ;
2626import {
2727 getRepositorySelection ,
@@ -99,6 +99,8 @@ async function generateQueryPack(
9999
100100 void logger . log ( `Copied ${ copiedCount } files to ${ queryPackDir } ` ) ;
101101
102+ await fixPackFile ( queryPackDir , packRelativePath ) ;
103+
102104 language = await findLanguage ( cliServer , Uri . file ( targetQueryFileName ) ) ;
103105 } else {
104106 // open popup to ask for language if not already hardcoded
@@ -115,6 +117,7 @@ async function generateQueryPack(
115117 dependencies : {
116118 [ `codeql/${ language } -all` ] : "*" ,
117119 } ,
120+ defaultSuite : generateDefaultSuite ( packRelativePath ) ,
118121 } ;
119122 await fs . writeFile (
120123 path . join ( queryPackDir , "qlpack.yml" ) ,
@@ -125,8 +128,6 @@ async function generateQueryPack(
125128 throw new UserCancellationException ( "Could not determine language." ) ;
126129 }
127130
128- await ensureNameAndSuite ( queryPackDir , packRelativePath ) ;
129-
130131 // Clear the cliServer cache so that the previous qlpack text is purged from the CLI.
131132 await cliServer . clearCache ( ) ;
132133
@@ -298,33 +299,48 @@ export async function prepareRemoteQueryRun(
298299}
299300
300301/**
301- * Updates the default suite of the query pack. This is used to ensure
302- * only the specified query is run.
302+ * Fixes the qlpack.yml file to be correct in the context of the MRVA request.
303303 *
304- * Also, ensure the query pack name is set to the name expected by the server.
304+ * Performs the following fixes:
305+ *
306+ * - Updates the default suite of the query pack. This is used to ensure
307+ * only the specified query is run.
308+ * - Ensures the query pack name is set to the name expected by the server.
309+ * - Removes any `${workspace}` version references from the qlpack.yml file. Converts them
310+ * to `*` versions.
305311 *
306312 * @param queryPackDir The directory containing the query pack
307313 * @param packRelativePath The relative path to the query pack from the root of the query pack
308314 */
309- async function ensureNameAndSuite (
315+ async function fixPackFile (
310316 queryPackDir : string ,
311317 packRelativePath : string ,
312318) : Promise < void > {
313319 const packPath = path . join ( queryPackDir , "qlpack.yml" ) ;
314320 const qlpack = yaml . load ( await fs . readFile ( packPath , "utf8" ) ) as QlPack ;
315- delete qlpack . defaultSuiteFile ;
316321
322+ // update pack name
317323 qlpack . name = QUERY_PACK_NAME ;
318324
319- qlpack . defaultSuite = [
325+ // update default suite
326+ delete qlpack . defaultSuiteFile ;
327+ qlpack . defaultSuite = generateDefaultSuite ( packRelativePath ) ;
328+
329+ // remove any ${workspace} version references
330+ removeWorkspaceRefs ( qlpack ) ;
331+
332+ await fs . writeFile ( packPath , yaml . dump ( qlpack ) ) ;
333+ }
334+
335+ function generateDefaultSuite ( packRelativePath : string ) {
336+ return [
320337 {
321338 description : "Query suite for variant analysis" ,
322339 } ,
323340 {
324341 query : packRelativePath . replace ( / \\ / g, "/" ) ,
325342 } ,
326343 ] ;
327- await fs . writeFile ( packPath , yaml . dump ( qlpack ) ) ;
328344}
329345
330346export function getQueryName (
@@ -385,13 +401,22 @@ export async function getControllerRepo(
385401 fullName : controllerRepo . full_name ,
386402 private : controllerRepo . private ,
387403 } ;
388- } catch ( e : any ) {
404+ } catch ( e ) {
389405 if ( ( e as RequestError ) . status === 404 ) {
390406 throw new Error ( `Controller repository "${ owner } /${ repo } " not found` ) ;
391407 } else {
392408 throw new Error (
393- `Error getting controller repository "${ owner } /${ repo } ": ${ e . message } ` ,
409+ `Error getting controller repository "${ owner } /${ repo } ": ${ getErrorMessage (
410+ e ,
411+ ) } `,
394412 ) ;
395413 }
396414 }
397415}
416+ export function removeWorkspaceRefs ( qlpack : QlPack ) {
417+ for ( const [ key , value ] of Object . entries ( qlpack . dependencies || { } ) ) {
418+ if ( value === "${workspace}" ) {
419+ qlpack . dependencies [ key ] = "*" ;
420+ }
421+ }
422+ }
0 commit comments