Skip to content

Commit

Permalink
Save query text in a temporary file
Browse files Browse the repository at this point in the history
  • Loading branch information
shati-patel committed Dec 9, 2021
1 parent 56b618c commit dc72f5a
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions extensions/ql-vscode/src/remote-queries/run-remote-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export async function runRemoteQuery(
return;
}

const remoteQuery = buildRemoteQueryEntity(repositories, queryFile, owner, repo, queryStartTime, workflowRunId);
const remoteQuery = await buildRemoteQueryEntity(repositories, queryFile, owner, repo, queryStartTime, workflowRunId);

// don't return the path because it has been deleted
return { query: remoteQuery };
Expand Down Expand Up @@ -567,14 +567,14 @@ export async function getResultIndex(
}
}

function buildRemoteQueryEntity(
async function buildRemoteQueryEntity(
repositories: string[],
queryFilePath: string,
controllerRepoOwner: string,
controllerRepoName: string,
queryStartTime: Date,
workflowRunId: number
): RemoteQuery {
): Promise<RemoteQuery> {
// For now, just use the file name as the query name.
const queryName = path.basename(queryFilePath);

Expand All @@ -583,8 +583,21 @@ function buildRemoteQueryEntity(
return { owner: owner, name: repo };
});

// TODO: Get query text from query file and save it in a temporary .ql file.
const queryTextTmpFilePath = '';
// Get the query text from query file and save it in a temporary .ql file.
const queryTextTmpFilePath = path.join(tmpDir.name, `tmp-${queryName}`);
const queryText = await fs.readFile(queryFilePath, 'utf8');
await fs.writeFile(
queryTextTmpFilePath, `\
////////////////////////////////////////////////////////////////////////////////////
// This is the text of the entire query file when it was executed for this query //
// run. The text or dependent libraries may have changed since then. //
// //
// To make changes to the query and the dependent libraries, save this file in a //
// suitable, permanent location. //
////////////////////////////////////////////////////////////////////////////////////
${queryText}`
);

return {
queryName,
Expand Down

0 comments on commit dc72f5a

Please sign in to comment.