Skip to content

Commit 04a85ac

Browse files
committed
CIHelper: allow specifying the information to send emails
One of the primary goals of GitGitGadget is to send emails. So far, the configuration for sending those is provided via environment variables or via the Git config. This is _implicit_, and I want to make this _explicit_ in preparation for the upcoming conversion to a set of GitHub Actions. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 5675a34 commit 04a85ac

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

lib/ci-helper.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { IMailMetadata } from "./mail-metadata.js";
1414
import { IPatchSeriesMetadata } from "./patch-series-metadata.js";
1515
import { IConfig, getExternalConfig, setConfig } from "./project-config.js";
1616
import { getPullRequestKeyFromURL, pullRequestKey } from "./pullRequestKey.js";
17+
import { ISMTPOptions } from "./send-mail.js";
1718

1819
const readFile = util.promisify(fs.readFile);
1920
type CommentFunction = (comment: string) => Promise<void>;
@@ -39,6 +40,7 @@ export class CIHelper {
3940
private gggNotesUpdated: boolean;
4041
private mail2CommitMapUpdated: boolean;
4142
private notesPushToken: string | undefined;
43+
private smtpOptions?: ISMTPOptions;
4244
protected maxCommitsExceptions: string[];
4345

4446
public static async getConfig(configFile?: string): Promise<IConfig> {
@@ -67,6 +69,10 @@ export class CIHelper {
6769
}
6870
}
6971

72+
public setSMTPOptions(smtpOptions: ISMTPOptions): void {
73+
this.smtpOptions = smtpOptions;
74+
}
75+
7076
/*
7177
* Given a commit that was contributed as a patch via GitGitGadget (i.e.
7278
* a commit with a Message-ID recorded in `refs/notes/gitgitgadget`),
@@ -587,6 +593,7 @@ export class CIHelper {
587593
this.workDir,
588594
this.urlRepo,
589595
this.notesPushToken,
596+
this.smtpOptions,
590597
);
591598
if (!gitGitGadget.isUserAllowed(comment.author)) {
592599
throw new Error(`User ${comment.author} is not yet permitted to use ${this.config.app.displayName}`);
@@ -793,7 +800,13 @@ export class CIHelper {
793800
await this.github.addPRComment(prKey, redacted);
794801
};
795802

796-
const gitGitGadget = await GitGitGadget.get(this.gggConfigDir, this.workDir, this.urlRepo, this.notesPushToken);
803+
const gitGitGadget = await GitGitGadget.get(
804+
this.gggConfigDir,
805+
this.workDir,
806+
this.urlRepo,
807+
this.notesPushToken,
808+
this.smtpOptions,
809+
);
797810
if (!pr.hasComments && !gitGitGadget.isUserAllowed(pr.author)) {
798811
const welcome = (await readFile("res/WELCOME.md")).toString().replace(/\${username}/g, pr.author);
799812
await this.github.addPRComment(prKey, welcome);

lib/gitgitgadget.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class GitGitGadget {
4141
workDir?: string,
4242
publishTagsAndNotesToRemote?: string,
4343
notesPushToken?: string,
44+
smtpOptions?: ISMTPOptions,
4445
): Promise<GitGitGadget> {
4546
if (!workDir) {
4647
workDir = await this.getWorkDir(gitGitGadgetDir);
@@ -64,25 +65,21 @@ export class GitGitGadget {
6465

6566
const notes = new GitNotes(workDir);
6667

67-
const smtpUser = await getVar("smtpUser", gitGitGadgetDir);
68-
const smtpHost = await getVar("smtpHost", gitGitGadgetDir);
69-
const smtpPass = await getVar("smtpPass", gitGitGadgetDir);
70-
const smtpOpts = await getVar("smtpOpts", gitGitGadgetDir);
68+
if (!smtpOptions) {
69+
const smtpUser = await getVar("smtpUser", gitGitGadgetDir);
70+
const smtpHost = await getVar("smtpHost", gitGitGadgetDir);
71+
const smtpPass = await getVar("smtpPass", gitGitGadgetDir);
72+
const smtpOpts = await getVar("smtpOpts", gitGitGadgetDir);
7173

72-
if (!smtpUser || !smtpHost || !smtpPass) {
73-
throw new Error("No SMTP settings configured");
74+
if (!smtpUser || !smtpHost || !smtpPass) {
75+
throw new Error("No SMTP settings configured");
76+
}
77+
smtpOptions = { smtpHost, smtpOpts, smtpPass, smtpUser };
7478
}
7579

7680
const [options, allowedUsers] = await GitGitGadget.readOptions(notes);
7781

78-
return new GitGitGadget(
79-
notes,
80-
options,
81-
allowedUsers,
82-
{ smtpHost, smtpOpts, smtpPass, smtpUser },
83-
publishTagsAndNotesToRemote,
84-
notesPushToken,
85-
);
82+
return new GitGitGadget(notes, options, allowedUsers, smtpOptions, publishTagsAndNotesToRemote, notesPushToken);
8683
}
8784

8885
protected static async readOptions(notes: GitNotes): Promise<[IGitGitGadgetOptions, Set<string>]> {

0 commit comments

Comments
 (0)