Skip to content

Commit b291ab7

Browse files
committed
GitGitGadget: do not allow the config to be passed implicitly
Implicit configuration is a recipe for confusion when trying to allow for overriding said configuration. Let's require the config to be passed down explicitly. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 4b2da5c commit b291ab7

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

lib/ci-helper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@ export class CIHelper {
854854

855855
try {
856856
const gitGitGadget = await GitGitGadget.get(
857+
this.config,
857858
this.gggConfigDir,
858859
this.workDir,
859860
this.urlRepo,
@@ -1071,6 +1072,7 @@ export class CIHelper {
10711072
};
10721073

10731074
const gitGitGadget = await GitGitGadget.get(
1075+
this.config,
10741076
this.gggConfigDir,
10751077
this.workDir,
10761078
this.urlRepo,

lib/gitgitgadget.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IGitHubUser, IPullRequestInfo } from "./github-glue.js";
55
import { PatchSeries, SendFunction } from "./patch-series.js";
66
import { IPatchSeriesMetadata } from "./patch-series-metadata.js";
77
import { PatchSeriesOptions } from "./patch-series-options.js";
8-
import { IConfig, getConfig } from "./project-config.js";
8+
import { IConfig } from "./project-config.js";
99
import { ISMTPOptions, parseHeadersAndSendMail, parseMBox, sendMail } from "./send-mail.js";
1010

1111
export interface IGitGitGadgetOptions {
@@ -37,6 +37,7 @@ export class GitGitGadget {
3737
}
3838

3939
public static async get(
40+
config: IConfig,
4041
gitGitGadgetDir: string,
4142
workDir?: string,
4243
publishTagsAndNotesToRemote?: string,
@@ -90,7 +91,15 @@ export class GitGitGadget {
9091

9192
const [options, allowedUsers] = await GitGitGadget.readOptions(notes);
9293

93-
return new GitGitGadget(notes, options, allowedUsers, smtpOptions, publishTagsAndNotesToRemote, notesPushToken);
94+
return new GitGitGadget(
95+
config,
96+
notes,
97+
options,
98+
allowedUsers,
99+
smtpOptions,
100+
publishTagsAndNotesToRemote,
101+
notesPushToken,
102+
);
94103
}
95104

96105
protected static async readOptions(notes: GitNotes): Promise<[IGitGitGadgetOptions, Set<string>]> {
@@ -103,7 +112,7 @@ export class GitGitGadget {
103112
return [options, allowedUsers];
104113
}
105114

106-
public readonly config: IConfig = getConfig();
115+
public readonly config: IConfig;
107116
public readonly workDir: string;
108117
public readonly notes: GitNotes;
109118
protected options: IGitGitGadgetOptions;
@@ -115,6 +124,7 @@ export class GitGitGadget {
115124
private readonly publishToken: string | undefined;
116125

117126
protected constructor(
127+
config: IConfig,
118128
notes: GitNotes,
119129
options: IGitGitGadgetOptions,
120130
allowedUsers: Set<string>,
@@ -125,6 +135,7 @@ export class GitGitGadget {
125135
if (!notes.workDir) {
126136
throw new Error("Could not determine Git worktree");
127137
}
138+
this.config = config;
128139
this.workDir = notes.workDir;
129140
this.notes = notes;
130141
this.options = options;

tests/gitgitgadget.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getConfig } from "../lib/gitgitgadget-config.js";
77
import { PatchSeries } from "../lib/patch-series.js";
88
import { IPatchSeriesMetadata } from "../lib/patch-series-metadata.js";
99
import { testCreateRepo } from "./test-lib.js";
10+
import defaultConfig from "../lib/gitgitgadget-config.js";
1011

1112
// This test script might take quite a while to run
1213
jest.setTimeout(60000);
@@ -342,7 +343,7 @@ test("allow/disallow", async () => {
342343
const notes = new GitNotes(remote.workDir);
343344
await notes.set("", {} as IGitGitGadgetOptions);
344345

345-
const gitGitGadget = await GitGitGadget.get(workDir);
346+
const gitGitGadget = await GitGitGadget.get(defaultConfig, workDir);
346347

347348
// pretend that the notes ref had been changed in the meantime
348349
await notes.set("", { allowedUsers: ["first-one"] } as IGitGitGadgetOptions, true);
@@ -370,7 +371,7 @@ test("allow/disallow with env vars", async () => {
370371
const notes = new GitNotes(remote.workDir);
371372
await notes.set("", {} as IGitGitGadgetOptions);
372373

373-
const gitGitGadget = await GitGitGadget.get(workDir);
374+
const gitGitGadget = await GitGitGadget.get(defaultConfig, workDir);
374375

375376
// pretend that the notes ref had been changed in the meantime
376377
await notes.set("", { allowedUsers: ["first-one"] } as IGitGitGadgetOptions, true);

0 commit comments

Comments
 (0)