Skip to content

Commit f58f0d1

Browse files
authored
Merge pull request #3973 from github/mbg/repo-props/config-file-shorthands
Support shorthand forms for `getRemoteConfig`
2 parents 006d029 + 7dc37cb commit f58f0d1

14 files changed

Lines changed: 3899 additions & 3369 deletions

lib/entry-points.js

Lines changed: 3150 additions & 3080 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.test.ts

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
mockCodeQLVersion,
3737
createTestConfig,
3838
makeMacro,
39+
initAllState,
3940
} from "./testing-utils";
4041
import {
4142
GitHubVariant,
@@ -160,8 +161,9 @@ test.serial("load empty config", async (t) => {
160161
},
161162
});
162163

164+
const state = initAllState({ logger });
163165
const config = await configUtils.initConfig(
164-
createFeatures([]),
166+
state,
165167
createTestInitConfigInputs({
166168
languagesInput: languages,
167169
repository: { owner: "github", repo: "example" },
@@ -202,8 +204,9 @@ test.serial("load code quality config", async (t) => {
202204
},
203205
});
204206

207+
const state = initAllState({ logger });
205208
const config = await configUtils.initConfig(
206-
createFeatures([]),
209+
state,
207210
createTestInitConfigInputs({
208211
analysisKinds: [AnalysisKind.CodeQuality],
209212
languagesInput: languages,
@@ -280,9 +283,10 @@ test.serial(
280283
repositoryProperties,
281284
});
282285

286+
const state = initAllState({ logger });
283287
await t.notThrowsAsync(async () => {
284288
const config = await configUtils.initConfig(
285-
createFeatures([]),
289+
state,
286290
createTestInitConfigInputs({
287291
analysisKinds: [AnalysisKind.CodeQuality],
288292
languagesInput: languages,
@@ -321,8 +325,9 @@ test.serial("loading a saved config produces the same config", async (t) => {
321325
// Sanity check that getConfig returns undefined before we have called initConfig
322326
t.deepEqual(await configUtils.getConfig(tempDir, logger), undefined);
323327

328+
const state = initAllState({ logger });
324329
const config1 = await configUtils.initConfig(
325-
createFeatures([]),
330+
state,
326331
createTestInitConfigInputs({
327332
languagesInput: "javascript,python",
328333
tempDir,
@@ -373,8 +378,9 @@ test.serial("loading config with version mismatch throws", async (t) => {
373378
.stub(actionsUtil, "getActionVersion")
374379
.returns("does-not-exist");
375380

381+
const state = initAllState({ logger });
376382
const config = await configUtils.initConfig(
377-
createFeatures([]),
383+
state,
378384
createTestInitConfigInputs({
379385
languagesInput: "javascript,python",
380386
tempDir,
@@ -402,8 +408,9 @@ test.serial("loading config with version mismatch throws", async (t) => {
402408
test.serial("load input outside of workspace", async (t) => {
403409
return await withTmpDir(async (tempDir) => {
404410
try {
411+
const state = initAllState();
405412
await configUtils.initConfig(
406-
createFeatures([]),
413+
state,
407414
createTestInitConfigInputs({
408415
configFile: "../input",
409416
tempDir,
@@ -424,43 +431,16 @@ test.serial("load input outside of workspace", async (t) => {
424431
});
425432
});
426433

427-
test.serial("load non-local input with invalid repo syntax", async (t) => {
428-
return await withTmpDir(async (tempDir) => {
429-
// no filename given, just a repo
430-
const configFile = "octo-org/codeql-config@main";
431-
432-
try {
433-
await configUtils.initConfig(
434-
createFeatures([]),
435-
createTestInitConfigInputs({
436-
configFile,
437-
tempDir,
438-
workspacePath: tempDir,
439-
}),
440-
);
441-
throw new Error("initConfig did not throw error");
442-
} catch (err) {
443-
t.deepEqual(
444-
err,
445-
new ConfigurationError(
446-
errorMessages.getConfigFileRepoFormatInvalidMessage(
447-
"octo-org/codeql-config@main",
448-
),
449-
),
450-
);
451-
}
452-
});
453-
});
454-
455434
test.serial("load non-existent input", async (t) => {
456435
return await withTmpDir(async (tempDir) => {
457436
const languagesInput = "javascript";
458437
const configFile = "input";
459438
t.false(fs.existsSync(path.join(tempDir, configFile)));
460439

461440
try {
441+
const state = initAllState();
462442
await configUtils.initConfig(
463-
createFeatures([]),
443+
state,
464444
createTestInitConfigInputs({
465445
languagesInput,
466446
configFile,
@@ -536,8 +516,9 @@ test.serial("load non-empty input", async (t) => {
536516
const languagesInput = "javascript";
537517
const configFilePath = createConfigFile(inputFileContents, tempDir);
538518

519+
const state = initAllState();
539520
const actualConfig = await configUtils.initConfig(
540-
createFeatures([]),
521+
state,
541522
createTestInitConfigInputs({
542523
languagesInput,
543524
buildModeInput: "none",
@@ -595,8 +576,9 @@ test.serial(
595576
// Only JS, python packs will be ignored
596577
const languagesInput = "javascript";
597578

579+
const state = initAllState();
598580
const config = await configUtils.initConfig(
599-
createFeatures([]),
581+
state,
600582
createTestInitConfigInputs({
601583
languagesInput,
602584
configFile: configFilePath,
@@ -647,8 +629,9 @@ test.serial("API client used when reading remote config", async (t) => {
647629
const configFile = "octo-org/codeql-config/config.yaml@main";
648630
const languagesInput = "javascript";
649631

632+
const state = initAllState();
650633
await configUtils.initConfig(
651-
createFeatures([]),
634+
state,
652635
createTestInitConfigInputs({
653636
languagesInput,
654637
configFile,
@@ -669,9 +652,10 @@ test.serial(
669652
mockGetContents(dummyResponse);
670653

671654
const repoReference = "octo-org/codeql-config/config.yaml@main";
655+
const state = initAllState();
672656
try {
673657
await configUtils.initConfig(
674-
createFeatures([]),
658+
state,
675659
createTestInitConfigInputs({
676660
configFile: repoReference,
677661
tempDir,
@@ -699,9 +683,10 @@ test.serial("Invalid format of remote config handled correctly", async (t) => {
699683
mockGetContents(dummyResponse);
700684

701685
const repoReference = "octo-org/codeql-config/config.yaml@main";
686+
const state = initAllState();
702687
try {
703688
await configUtils.initConfig(
704-
createFeatures([]),
689+
state,
705690
createTestInitConfigInputs({
706691
configFile: repoReference,
707692
tempDir,
@@ -729,9 +714,10 @@ test.serial("No detected languages", async (t) => {
729714
},
730715
});
731716

717+
const state = initAllState();
732718
try {
733719
await configUtils.initConfig(
734-
createFeatures([]),
720+
state,
735721
createTestInitConfigInputs({
736722
tempDir,
737723
codeql,
@@ -752,9 +738,10 @@ test.serial("Unknown languages", async (t) => {
752738
return await withTmpDir(async (tempDir) => {
753739
const languagesInput = "rubbish,english";
754740

741+
const state = initAllState();
755742
try {
756743
await configUtils.initConfig(
757-
createFeatures([]),
744+
state,
758745
createTestInitConfigInputs({
759746
languagesInput,
760747
tempDir,

0 commit comments

Comments
 (0)