Skip to content

Commit e8bb14c

Browse files
committed
PatchSeries: 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 b291ab7 commit e8bb14c

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

lib/gitgitgadget.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export class GitGitGadget {
302302
options.rfc = pr.draft ?? false;
303303

304304
const series = await PatchSeries.getFromNotes(
305+
this.config,
305306
this.notes,
306307
pr.pullRequestURL,
307308
pr.title,

lib/patch-series.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { IMailMetadata } from "./mail-metadata.js";
88
import { md2text } from "./markdown-renderer.js";
99
import { IPatchSeriesMetadata } from "./patch-series-metadata.js";
1010
import { PatchSeriesOptions } from "./patch-series-options.js";
11-
import { IConfig, getConfig } from "./project-config.js";
11+
import { IConfig } from "./project-config.js";
1212
import { ProjectOptions } from "./project-options.js";
1313
import { getPullRequestKeyFromURL } from "./pullRequestKey.js";
1414

@@ -57,6 +57,7 @@ interface IRangeDiff {
5757

5858
export class PatchSeries {
5959
public static async getFromNotes(
60+
config: IConfig,
6061
notes: GitNotes,
6162
pullRequestURL: string,
6263
pullRequestTitle: string,
@@ -144,7 +145,17 @@ export class PatchSeries {
144145
options.rangeDiff = rangeDiff;
145146
}
146147

147-
return new PatchSeries(notes, options, project, metadata, rangeDiffRanges, patchCount, coverLetter, senderName);
148+
return new PatchSeries(
149+
config,
150+
notes,
151+
options,
152+
project,
153+
metadata,
154+
rangeDiffRanges,
155+
patchCount,
156+
coverLetter,
157+
senderName,
158+
);
148159
}
149160

150161
protected static async parsePullRequest(
@@ -513,7 +524,7 @@ export class PatchSeries {
513524
return results;
514525
}
515526

516-
public readonly config: IConfig = getConfig();
527+
public readonly config: IConfig;
517528
public readonly notes: GitNotes;
518529
public readonly options: PatchSeriesOptions;
519530
public readonly project: ProjectOptions;
@@ -524,6 +535,7 @@ export class PatchSeries {
524535
public readonly patchCount: number;
525536

526537
protected constructor(
538+
config: IConfig,
527539
notes: GitNotes,
528540
options: PatchSeriesOptions,
529541
project: ProjectOptions,
@@ -533,6 +545,7 @@ export class PatchSeries {
533545
coverLetter?: string,
534546
senderName?: string,
535547
) {
548+
this.config = config;
536549
this.notes = notes;
537550
this.options = options;
538551
this.project = project;

tests/gitgitgadget.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ test("generate tag/notes from a Pull Request", async () => {
210210
await git(["config", "user.email", "gitgitgadget@example.com"], repo.options);
211211

212212
const patches = await PatchSeries.getFromNotes(
213+
defaultConfig,
213214
notes,
214215
pullRequestURL,
215216
pullRequestTitle,
@@ -252,6 +253,7 @@ to have included in git.git [https://github.com/git/git].`);
252253

253254
const headCommit2 = await repo.revParse("HEAD");
254255
const patches2 = await PatchSeries.getFromNotes(
256+
defaultConfig,
255257
notes,
256258
pullRequestURL,
257259
pullRequestTitle,

tests/patch-series.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { GitNotes } from "../lib/git-notes.js";
66
import { PatchSeries } from "../lib/patch-series.js";
77
import { ProjectOptions } from "../lib/project-options.js";
88
import { testCreateRepo } from "./test-lib.js";
9+
import defaultConfig from "../lib/gitgitgadget-config.js";
910

1011
jest.setTimeout(60000);
1112
const sourceFileName = fileURLToPath(import.meta.url);
@@ -102,7 +103,15 @@ class PatchSeriesTest extends PatchSeries {
102103
}
103104
}
104105

105-
const x = new PatchSeriesTest(new GitNotes(), {}, new ProjectOptionsTest(), prMeta, undefined, 1);
106+
const x = new PatchSeriesTest(
107+
defaultConfig,
108+
new GitNotes(),
109+
{},
110+
new ProjectOptionsTest(),
111+
prMeta,
112+
undefined,
113+
1,
114+
);
106115

107116
x.insertCcAndFromLines(mails, thisAuthor, senderName);
108117

tests/project-options.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getConfig } from "../lib/gitgitgadget-config.js";
66
import { PatchSeries } from "../lib/patch-series.js";
77
import { ProjectOptions } from "../lib/project-options.js";
88
import { testCreateRepo } from "./test-lib.js";
9+
import defaultConfig from "../lib/gitgitgadget-config.js";
910

1011
// This test script might take quite a while to run
1112
jest.setTimeout(20000);
@@ -45,7 +46,7 @@ test("project options", async () => {
4546
headLabel: options2.branchName,
4647
iteration: 1,
4748
};
48-
const x = new X(new GitNotes(repo.workDir), {}, options2, prMeta, undefined, 1);
49+
const x = new X(defaultConfig, new GitNotes(repo.workDir), {}, options2, prMeta, undefined, 1);
4950
const mbox = await x.generateMBox();
5051
const needle = "=?UTF-8?Q?Nguy=E1=BB=85n_Th=C3=A1i_Ng=E1=BB=8Dc?= Duy";
5152
expect(mbox).toEqual(expect.stringContaining(needle));

0 commit comments

Comments
 (0)