Skip to content

Commit a52831f

Browse files
committed
Only demand that SMTP is configured when it is actually needed
The future of GitGitGadget is that it comes in the form of a set of GitHub Actions; Most won't send emails and therefore do not need the SMTP configuration, so let's not require it in those instances. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 04a85ac commit a52831f

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

lib/gitgitgadget.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,15 @@ export class GitGitGadget {
7171
const smtpPass = await getVar("smtpPass", gitGitGadgetDir);
7272
const smtpOpts = await getVar("smtpOpts", gitGitGadgetDir);
7373

74-
if (!smtpUser || !smtpHost || !smtpPass) {
75-
throw new Error("No SMTP settings configured");
74+
if (smtpUser && smtpHost && smtpPass) smtpOptions = { smtpHost, smtpOpts, smtpPass, smtpUser };
75+
else if (smtpUser || smtpHost || smtpPass) {
76+
const missing: string[] = [
77+
smtpUser ? "" : "smtpUser",
78+
smtpHost ? "" : "smtpHost",
79+
smtpPass ? "" : "smtpPass",
80+
].filter((e) => e);
81+
throw new Error(`Partial SMTP configuration detected (${missing.join(", ")} missing)`);
7682
}
77-
smtpOptions = { smtpHost, smtpOpts, smtpPass, smtpUser };
7883
}
7984

8085
const [options, allowedUsers] = await GitGitGadget.readOptions(notes);
@@ -98,7 +103,7 @@ export class GitGitGadget {
98103
protected options: IGitGitGadgetOptions;
99104
protected allowedUsers: Set<string>;
100105

101-
protected readonly smtpOptions: ISMTPOptions;
106+
protected readonly smtpOptions?: ISMTPOptions;
102107

103108
protected readonly publishTagsAndNotesToRemote: string;
104109
private readonly publishToken: string | undefined;
@@ -107,7 +112,7 @@ export class GitGitGadget {
107112
notes: GitNotes,
108113
options: IGitGitGadgetOptions,
109114
allowedUsers: Set<string>,
110-
smtpOptions: ISMTPOptions,
115+
smtpOptions: ISMTPOptions | undefined,
111116
publishTagsAndNotesToRemote: string,
112117
publishToken?: string,
113118
) {
@@ -168,6 +173,10 @@ export class GitGitGadget {
168173

169174
// Send emails only to the user
170175
public async preview(pr: IPullRequestInfo, userInfo: IGitHubUser): Promise<IPatchSeriesMetadata | undefined> {
176+
const smtpOptions = this.smtpOptions;
177+
if (!smtpOptions) {
178+
throw new Error("No SMTP options configured");
179+
}
171180
if (!userInfo.email) {
172181
throw new Error(`No email in user info for ${userInfo.login}`);
173182
}
@@ -178,16 +187,20 @@ export class GitGitGadget {
178187
mbox.cc = [];
179188
mbox.to = email;
180189
console.log(mbox);
181-
return await sendMail(mbox, this.smtpOptions);
190+
return await sendMail(mbox, smtpOptions);
182191
};
183192

184193
return await this.genAndSend(pr, userInfo, { noUpdate: true }, send);
185194
}
186195

187196
// Send emails out for review
188197
public async submit(pr: IPullRequestInfo, userInfo: IGitHubUser): Promise<IPatchSeriesMetadata | undefined> {
198+
const smtpOptions = this.smtpOptions;
199+
if (!smtpOptions) {
200+
throw new Error("No SMTP options configured");
201+
}
189202
const send = async (mail: string): Promise<string> => {
190-
return await parseHeadersAndSendMail(mail, this.smtpOptions);
203+
return await parseHeadersAndSendMail(mail, smtpOptions);
191204
};
192205

193206
return await this.genAndSend(pr, userInfo, {}, send);

0 commit comments

Comments
 (0)