Skip to content

Commit 3105d8f

Browse files
committed
Move the getExternalConfig() function to a better home
It really needs to be reusable instead of being stuck in the script. In particular since we're about to modify GitGitGadget such that it can be run as a GitHub Action instead. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 6b6f802 commit 3105d8f

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

lib/project-config.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,25 @@ export function getConfig(): IConfig {
6464
return config;
6565
}
6666

67+
export async function getExternalConfig(file: string): Promise<IConfig> {
68+
const filePath = path.resolve(file);
69+
const newConfig = await loadConfig(filePath);
70+
71+
if (!Object.prototype.hasOwnProperty.call(newConfig, "project")) {
72+
throw new Error(`User configurations must have a 'project:'. Not found in ${filePath}`);
73+
}
74+
75+
if (!newConfig.repo.owner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) {
76+
throw new Error(`Invalid 'owner' ${newConfig.repo.owner} in ${filePath}`);
77+
}
78+
79+
if (!newConfig.repo.baseOwner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) {
80+
throw new Error(`Invalid 'baseOwner' ${newConfig.repo.baseOwner} in ${filePath}`);
81+
}
82+
83+
return newConfig;
84+
}
85+
6786
type importedConfig = { default: IConfig };
6887

6988
/**

script/misc-helper.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { GitHubGlue } from "../lib/github-glue.js";
1010
import { toPrettyJSON } from "../lib/json-util.js";
1111
import { IGitMailingListMirrorState, stateKey } from "../lib/mail-archive-helper.js";
1212
import { IPatchSeriesMetadata } from "../lib/patch-series-metadata.js";
13-
import { IConfig, loadConfig, setConfig } from "../lib/project-config.js";
14-
import path from "path";
13+
import { IConfig, getExternalConfig, setConfig } from "../lib/project-config.js";
1514

1615
let commander = new Command();
1716
const publishRemoteKey = "publishRemote";
@@ -488,22 +487,3 @@ const commandOptions = commander.opts<ICommanderOptions>();
488487
process.stderr.write(`Caught error ${reason}:\n${reason.stack}\n`);
489488
process.exit(1);
490489
});
491-
492-
async function getExternalConfig(file: string): Promise<IConfig> {
493-
const filePath = path.resolve(file);
494-
const newConfig = await loadConfig(filePath);
495-
496-
if (!Object.prototype.hasOwnProperty.call(newConfig, "project")) {
497-
throw new Error(`User configurations must have a 'project:'. Not found in ${filePath}`);
498-
}
499-
500-
if (!newConfig.repo.owner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) {
501-
throw new Error(`Invalid 'owner' ${newConfig.repo.owner} in ${filePath}`);
502-
}
503-
504-
if (!newConfig.repo.baseOwner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) {
505-
throw new Error(`Invalid 'baseOwner' ${newConfig.repo.baseOwner} in ${filePath}`);
506-
}
507-
508-
return newConfig;
509-
}

0 commit comments

Comments
 (0)