@@ -36,12 +36,18 @@ export class GitGitGadget {
3636 return workDir ;
3737 }
3838
39- public static async get ( gitGitGadgetDir : string , workDir ?: string , notesPushToken ?: string ) : Promise < GitGitGadget > {
39+ public static async get (
40+ gitGitGadgetDir : string ,
41+ workDir ?: string ,
42+ publishTagsAndNotesToRemote ?: string ,
43+ notesPushToken ?: string ,
44+ smtpOptions ?: ISMTPOptions ,
45+ ) : Promise < GitGitGadget > {
4046 if ( ! workDir ) {
4147 workDir = await this . getWorkDir ( gitGitGadgetDir ) ;
4248 }
4349
44- const publishTagsAndNotesToRemote = await getVar ( "publishRemote" , gitGitGadgetDir ) ;
50+ if ( ! publishTagsAndNotesToRemote ) publishTagsAndNotesToRemote = await getVar ( "publishRemote" , gitGitGadgetDir ) ;
4551 if ( ! publishTagsAndNotesToRemote ) {
4652 throw new Error ( "No remote to which to push configured" ) ;
4753 }
@@ -59,25 +65,26 @@ export class GitGitGadget {
5965
6066 const notes = new GitNotes ( workDir ) ;
6167
62- const smtpUser = await getVar ( "smtpUser" , gitGitGadgetDir ) ;
63- const smtpHost = await getVar ( "smtpHost" , gitGitGadgetDir ) ;
64- const smtpPass = await getVar ( "smtpPass" , gitGitGadgetDir ) ;
65- const smtpOpts = await getVar ( "smtpOpts" , gitGitGadgetDir ) ;
66-
67- if ( ! smtpUser || ! smtpHost || ! smtpPass ) {
68- throw new Error ( "No SMTP settings configured" ) ;
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 ) ;
73+
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)` ) ;
82+ }
6983 }
7084
7185 const [ options , allowedUsers ] = await GitGitGadget . readOptions ( notes ) ;
7286
73- return new GitGitGadget (
74- notes ,
75- options ,
76- allowedUsers ,
77- { smtpHost, smtpOpts, smtpPass, smtpUser } ,
78- publishTagsAndNotesToRemote ,
79- notesPushToken ,
80- ) ;
87+ return new GitGitGadget ( notes , options , allowedUsers , smtpOptions , publishTagsAndNotesToRemote , notesPushToken ) ;
8188 }
8289
8390 protected static async readOptions ( notes : GitNotes ) : Promise < [ IGitGitGadgetOptions , Set < string > ] > {
@@ -96,7 +103,7 @@ export class GitGitGadget {
96103 protected options : IGitGitGadgetOptions ;
97104 protected allowedUsers : Set < string > ;
98105
99- protected readonly smtpOptions : ISMTPOptions ;
106+ protected readonly smtpOptions ? : ISMTPOptions ;
100107
101108 protected readonly publishTagsAndNotesToRemote : string ;
102109 private readonly publishToken : string | undefined ;
@@ -105,7 +112,7 @@ export class GitGitGadget {
105112 notes : GitNotes ,
106113 options : IGitGitGadgetOptions ,
107114 allowedUsers : Set < string > ,
108- smtpOptions : ISMTPOptions ,
115+ smtpOptions : ISMTPOptions | undefined ,
109116 publishTagsAndNotesToRemote : string ,
110117 publishToken ?: string ,
111118 ) {
@@ -166,6 +173,10 @@ export class GitGitGadget {
166173
167174 // Send emails only to the user
168175 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+ }
169180 if ( ! userInfo . email ) {
170181 throw new Error ( `No email in user info for ${ userInfo . login } ` ) ;
171182 }
@@ -176,16 +187,20 @@ export class GitGitGadget {
176187 mbox . cc = [ ] ;
177188 mbox . to = email ;
178189 console . log ( mbox ) ;
179- return await sendMail ( mbox , this . smtpOptions ) ;
190+ return await sendMail ( mbox , smtpOptions ) ;
180191 } ;
181192
182193 return await this . genAndSend ( pr , userInfo , { noUpdate : true } , send ) ;
183194 }
184195
185196 // Send emails out for review
186197 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+ }
187202 const send = async ( mail : string ) : Promise < string > => {
188- return await parseHeadersAndSendMail ( mail , this . smtpOptions ) ;
203+ return await parseHeadersAndSendMail ( mail , smtpOptions ) ;
189204 } ;
190205
191206 return await this . genAndSend ( pr , userInfo , { } , send ) ;
0 commit comments