Skip to content

Commit b499ce9

Browse files
Merge pull request #983 from github/robertbrignull/reduce_metadata
Reduce the number of calls to "codeql resolve metadata"
2 parents 4844f56 + 9e0380b commit b499ce9

File tree

7 files changed

+166
-74
lines changed

7 files changed

+166
-74
lines changed

dist/query.js

+35-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/codeql.test.ts

+52-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
getSarifOutputType,
1818
QueryMetadata,
1919
getBqrsResultCount,
20+
getQueryPackInfo,
2021
} from "./codeql";
2122

2223
const test = anyTest as TestFn<{ db: string; tmpDir: string }>;
@@ -50,8 +51,49 @@ test.after(async (t) => {
5051
}
5152
});
5253

54+
test("getting query pack info", async (t) => {
55+
const queryPackInfo = await getQueryPackInfo("codeql", "testdata/test_pack");
56+
57+
const queries = {};
58+
queries[path.resolve("testdata/test_pack/x/query.ql")] = {
59+
name: "Test query",
60+
description: "Test query description",
61+
kind: "table",
62+
id: "test/query/id",
63+
};
64+
t.deepEqual(queryPackInfo, {
65+
path: path.resolve("testdata/test_pack"),
66+
name: "codeql/queries",
67+
queries,
68+
});
69+
});
70+
71+
test("getting query pack info with multiple queries", async (t) => {
72+
const queryPackInfo = await getQueryPackInfo(
73+
"codeql",
74+
"testdata/test_pack_multiple_queries",
75+
);
76+
77+
const queries = {};
78+
queries[path.resolve("testdata/test_pack_multiple_queries/x/query.ql")] = {
79+
name: "Test query 1",
80+
kind: "table",
81+
id: "test/query/one",
82+
};
83+
queries[path.resolve("testdata/test_pack_multiple_queries/z/query.ql")] = {
84+
name: "Test query 2",
85+
kind: "table",
86+
id: "test/query/two",
87+
};
88+
t.deepEqual(queryPackInfo, {
89+
path: path.resolve("testdata/test_pack_multiple_queries"),
90+
name: "codeql/queries",
91+
queries,
92+
});
93+
});
94+
5395
test("running a query in a pack", async (t) => {
54-
const queryPack = path.resolve("testdata/test_pack");
96+
const queryPack = await getQueryPackInfo("codeql", "testdata/test_pack");
5597
const tmpDir = fs.mkdtempSync("tmp");
5698
const cwd = process.cwd();
5799
process.chdir(tmpDir);
@@ -75,7 +117,10 @@ test("running a query in a pack", async (t) => {
75117
});
76118

77119
test("running multiple queries in a pack", async (t) => {
78-
const queryPack = path.resolve("testdata/test_pack_multiple_queries");
120+
const queryPack = await getQueryPackInfo(
121+
"codeql",
122+
"testdata/test_pack_multiple_queries",
123+
);
79124
const tmpDir = fs.mkdtempSync("tmp");
80125
const cwd = process.cwd();
81126
process.chdir(tmpDir);
@@ -175,10 +220,11 @@ test("getting the commit SHA when the codeql-database.yml does not exist", async
175220
}
176221
});
177222

178-
test("getting the default query from a pack", async (t) => {
179-
t.deepEqual(await getQueryPackQueries("codeql", "testdata/test_pack"), [
180-
path.resolve("testdata/test_pack/x/query.ql"),
181-
]);
223+
test("getting the queries from a pack", async (t) => {
224+
t.deepEqual(
225+
await getQueryPackQueries("codeql", "testdata/test_pack", "codeql/queries"),
226+
[path.resolve("testdata/test_pack/x/query.ql")],
227+
);
182228
});
183229

184230
test("populating the SARIF versionControlProvenance property", (t) => {

0 commit comments

Comments
 (0)