Skip to content

Commit 5368980

Browse files
committed
Retire getConfig(), setConfig() and friends
Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c6d4567 commit 5368980

8 files changed

+8
-103
lines changed

lib/ci-helper.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ILintError, LintCommit } from "./commit-lint.js";
1010
import { commitExists, git, emptyTreeName, revParse } from "./git.js";
1111
import { GitNotes } from "./git-notes.js";
1212
import { GitGitGadget, IGitGitGadgetOptions } from "./gitgitgadget.js";
13-
import { getConfig } from "./gitgitgadget-config.js";
1413
import {
1514
ConclusionType,
1615
GitHubGlue,
@@ -25,7 +24,7 @@ import { MailArchiveGitHelper, stateKey as mailArchiveStateKey } from "./mail-ar
2524
import { MailCommitMapping } from "./mail-commit-mapping.js";
2625
import { IMailMetadata } from "./mail-metadata.js";
2726
import { IPatchSeriesMetadata } from "./patch-series-metadata.js";
28-
import { IConfig, getExternalConfig, setConfig } from "./project-config.js";
27+
import { IConfig } from "./project-config.js";
2928
import {
3029
getPullRequestCommentKeyFromURL,
3130
getPullRequestKeyFromURL,
@@ -34,6 +33,7 @@ import {
3433
} from "./pullRequestKey.js";
3534
import { ISMTPOptions } from "./send-mail.js";
3635
import { fileURLToPath } from "url";
36+
import defaultConfig from "./gitgitgadget-config.js";
3737

3838
const readFile = util.promisify(fs.readFile);
3939
type CommentFunction = (comment: string) => Promise<void>;
@@ -63,10 +63,6 @@ export class CIHelper {
6363
protected maxCommitsExceptions: string[];
6464
protected mailingListMirror: string | undefined;
6565

66-
public static async getConfig(configFile?: string): Promise<IConfig> {
67-
return configFile ? await getExternalConfig(configFile) : getConfig();
68-
}
69-
7066
public static validateConfig = typia.createValidate<IConfig>();
7167

7268
public static getConfigAsGitHubActionInput(): IConfig | undefined {
@@ -84,7 +80,7 @@ export class CIHelper {
8480
}
8581

8682
public constructor(workDir: string = "pr-repo.git", config?: IConfig, skipUpdate?: boolean, gggConfigDir = ".") {
87-
this.config = config !== undefined ? setConfig(config) : CIHelper.getConfigAsGitHubActionInput() || getConfig();
83+
this.config = config || CIHelper.getConfigAsGitHubActionInput() || defaultConfig;
8884
this.gggConfigDir = gggConfigDir;
8985
this.workDir = workDir;
9086
this.notes = new GitNotes(workDir);

lib/gitgitgadget-config.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IConfig, setConfig } from "./project-config.js";
1+
import { IConfig } from "./project-config.js";
22

33
const defaultConfig: IConfig = {
44
repo: {
@@ -59,9 +59,3 @@ const defaultConfig: IConfig = {
5959
};
6060

6161
export default defaultConfig;
62-
63-
setConfig(defaultConfig);
64-
65-
export function getConfig(): IConfig {
66-
return setConfig(defaultConfig);
67-
}

lib/project-config.ts

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import * as fs from "fs";
2-
import path from "path";
3-
41
export type projectInfo = {
52
to: string; // email to send patches to
63
branch: string; // upstream branch a PR must be based on
@@ -73,76 +70,3 @@ export interface IConfig {
7370
user: IUserConfig;
7471
syncUpstreamBranches: ISyncUpstreamBranchesConfig[]; // branches to sync from upstream to our repo
7572
}
76-
77-
let config: IConfig; // singleton
78-
79-
/**
80-
* Query to get the current configuration.
81-
*
82-
* @returns IConfig interface
83-
*/
84-
export function getConfig(): IConfig {
85-
if (config === undefined) {
86-
throw new Error("project-config not set");
87-
}
88-
89-
return config;
90-
}
91-
92-
export async function getExternalConfig(file: string): Promise<IConfig> {
93-
const filePath = path.resolve(file);
94-
const newConfig = await loadConfig(filePath);
95-
96-
if (!Object.prototype.hasOwnProperty.call(newConfig, "project")) {
97-
throw new Error(`User configurations must have a 'project:'. Not found in ${filePath}`);
98-
}
99-
100-
if (!newConfig.repo.owner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) {
101-
throw new Error(`Invalid 'owner' ${newConfig.repo.owner} in ${filePath}`);
102-
}
103-
104-
if (!newConfig.repo.upstreamOwner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) {
105-
throw new Error(`Invalid 'baseOwner' ${newConfig.repo.upstreamOwner} in ${filePath}`);
106-
}
107-
108-
return newConfig;
109-
}
110-
111-
type importedConfig = { default: IConfig };
112-
113-
/**
114-
* Load a config. The config may be a javascript file (plain or generated
115-
* from typescript) or a json file (with a .json extension).
116-
*
117-
* @param file fully qualified filename and path
118-
* @returns IConfig interface
119-
*/
120-
export async function loadConfig(file: string): Promise<IConfig> {
121-
let loadedConfig: IConfig;
122-
123-
if (path.extname(file) === ".js") {
124-
const { default: newConfig } = (await import(file)) as importedConfig;
125-
loadedConfig = newConfig;
126-
} else {
127-
// eslint-disable-next-line security/detect-non-literal-fs-filename
128-
const fileText = fs.readFileSync(file, { encoding: "utf-8" });
129-
loadedConfig = JSON.parse(fileText) as IConfig;
130-
}
131-
132-
if (loadedConfig === undefined) {
133-
throw new Error("project-config not set");
134-
}
135-
136-
return loadedConfig;
137-
}
138-
139-
/**
140-
* Set/update the configuration.
141-
*
142-
* @param newConfig configuration to be set
143-
* @returns current IConfig interface
144-
*/
145-
export function setConfig(newConfig: IConfig): IConfig {
146-
config = newConfig;
147-
return config;
148-
}

tests/ci-helper.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { afterAll, beforeAll, expect, jest, test } from "@jest/globals";
22
import { fileURLToPath } from "url";
33
import { CIHelper } from "../lib/ci-helper.js";
44
import { GitNotes } from "../lib/git-notes.js";
5-
import { getConfig } from "../lib/gitgitgadget-config.js";
65
import { GitHubGlue, IGitHubUser, IPRComment, IPRCommit, IPullRequestInfo } from "../lib/github-glue.js";
76
import { IMailMetadata } from "../lib/mail-metadata.js";
87
import { testSmtpServer } from "test-smtp-server";
98
import { testCreateRepo, TestRepo } from "./test-lib.js";
9+
import defaultConfig from "../lib/gitgitgadget-config.js";
1010

1111
const sourceFileName = fileURLToPath(import.meta.url);
1212

@@ -32,7 +32,7 @@ function testQ(label: string, fn: AsyncFn) {
3232
});
3333
}
3434

35-
const config = getConfig();
35+
const config = defaultConfig;
3636

3737
const eMailOptions = {
3838
smtpserver: new testSmtpServer(),

tests/gitgitgadget.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { fileURLToPath } from "url";
33
import { git, gitCommandExists } from "../lib/git.js";
44
import { GitNotes } from "../lib/git-notes.js";
55
import { GitGitGadget, IGitGitGadgetOptions } from "../lib/gitgitgadget.js";
6-
import { getConfig } from "../lib/gitgitgadget-config.js";
76
import { PatchSeries } from "../lib/patch-series.js";
87
import { IPatchSeriesMetadata } from "../lib/patch-series-metadata.js";
98
import { testCreateRepo } from "./test-lib.js";
@@ -13,8 +12,6 @@ import defaultConfig from "../lib/gitgitgadget-config.js";
1312
jest.setTimeout(60000);
1413
const sourceFileName = fileURLToPath(import.meta.url);
1514

16-
getConfig();
17-
1815
const expectedMails = [
1916
`From 91fba7811291c1064b2603765a2297c34fc843c0 Mon Sep 17 00:00:00 2001
2017
Message-Id: <pull.<Message-ID>>

tests/misc-helper.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { expect, jest, test } from "@jest/globals";
22
import { fileURLToPath } from "url";
33
import { git } from "../lib/git.js";
4-
import { getConfig } from "../lib/gitgitgadget-config.js";
54
import { testCreateRepo, TestRepo } from "./test-lib.js";
65
import { execFile } from "child_process";
76
import * as util from "util";
7+
import defaultConfig from "../lib/gitgitgadget-config.js";
88

99
const execChild = util.promisify(execFile);
1010

1111
jest.setTimeout(180000);
1212
const sourceFileName = fileURLToPath(import.meta.url);
1313

14-
const config = getConfig();
14+
const config = defaultConfig;
1515

1616
// Create three repos.
1717
// worktree is a local copy for doing updates and has the config

tests/patch-series.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect, jest, test } from "@jest/globals";
22
import { fileURLToPath } from "url";
3-
import { getConfig } from "../lib/gitgitgadget-config.js";
43
import { git } from "../lib/git.js";
54
import { GitNotes } from "../lib/git-notes.js";
65
import { PatchSeries } from "../lib/patch-series.js";
@@ -11,8 +10,6 @@ import defaultConfig from "../lib/gitgitgadget-config.js";
1110
jest.setTimeout(60000);
1211
const sourceFileName = fileURLToPath(import.meta.url);
1312

14-
getConfig();
15-
1613
const mbox1 = `From 38d1082511bb02a709f203481c2787adc6e67c02 Mon Sep 17 00:00:00 2001
1714
Message-Id: <[email protected]>
1815
From: A U Thor

tests/project-options.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { expect, jest, test } from "@jest/globals";
22
import { fileURLToPath } from "url";
33
import { isDirectory } from "../lib/fs-util.js";
44
import { GitNotes } from "../lib/git-notes.js";
5-
import { getConfig } from "../lib/gitgitgadget-config.js";
65
import { PatchSeries } from "../lib/patch-series.js";
76
import { ProjectOptions } from "../lib/project-options.js";
87
import { testCreateRepo } from "./test-lib.js";
@@ -12,8 +11,6 @@ import defaultConfig from "../lib/gitgitgadget-config.js";
1211
jest.setTimeout(20000);
1312
const sourceFileName = fileURLToPath(import.meta.url);
1413

15-
getConfig();
16-
1714
test("project options", async () => {
1815
const repo = await testCreateRepo(sourceFileName);
1916
expect(await isDirectory(`${repo.workDir}/.git`)).toBeTruthy();

0 commit comments

Comments
 (0)