-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3163 from github/koesie10/queries-panel-no-cli-se…
…rver Do not use the CLI server to determine query pack language
- Loading branch information
Showing
15 changed files
with
418 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { QueryLanguage } from "./query-language"; | ||
import { loadQlpackFile } from "../packaging/qlpack-file-loader"; | ||
|
||
/** | ||
* @param qlpackPath The path to the `qlpack.yml` or `codeql-pack.yml` file. | ||
* @return the language of the given qlpack file, or undefined if the file is | ||
* not a valid qlpack file or does not contain exactly one language. | ||
*/ | ||
export async function getQlPackLanguage( | ||
qlpackPath: string, | ||
): Promise<QueryLanguage | undefined> { | ||
const qlPack = await loadQlpackFile(qlpackPath); | ||
const dependencies = qlPack?.dependencies; | ||
if (!dependencies) { | ||
return; | ||
} | ||
|
||
const matchingLanguages = Object.values(QueryLanguage).filter( | ||
(language) => `codeql/${language}-all` in dependencies, | ||
); | ||
if (matchingLanguages.length !== 1) { | ||
return undefined; | ||
} | ||
|
||
return matchingLanguages[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
extensions/ql-vscode/src/model-editor/extension-pack-metadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { QlPackFile } from "../packaging/qlpack-file"; | ||
|
||
export type ExtensionPackMetadata = QlPackFile & { | ||
// Make both extensionTargets and dataExtensions required | ||
// Make name, version, extensionTargets, and dataExtensions required | ||
name: string; | ||
version: string; | ||
extensionTargets: Record<string, string>; | ||
dataExtensions: string[] | string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Ajv from "ajv"; | ||
import * as qlpackFileSchemaJson from "./qlpack-file.schema.json"; | ||
import { QlPackFile } from "./qlpack-file"; | ||
import { load } from "js-yaml"; | ||
import { readFile } from "fs-extra"; | ||
|
||
const ajv = new Ajv({ allErrors: true }); | ||
const qlpackFileValidate = ajv.compile(qlpackFileSchemaJson); | ||
|
||
export async function loadQlpackFile(path: string): Promise<QlPackFile> { | ||
const qlpackFileText = await readFile(path, "utf8"); | ||
|
||
let qlPack = load(qlpackFileText) as QlPackFile | undefined; | ||
|
||
if (qlPack === undefined || qlPack === null) { | ||
// An empty file is not valid according to the schema since it's not an object, | ||
// but it is equivalent to an empty object. | ||
qlPack = {}; | ||
} | ||
|
||
qlpackFileValidate(qlPack); | ||
|
||
if (qlpackFileValidate.errors) { | ||
throw new Error( | ||
`Invalid extension pack YAML: ${qlpackFileValidate.errors | ||
.map((error) => `${error.instancePath} ${error.message}`) | ||
.join(", ")}`, | ||
); | ||
} | ||
|
||
return qlPack; | ||
} |
Oops, something went wrong.