aboutsummaryrefslogtreecommitdiff
path: root/pkg/setting/setting.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-07-27 16:53:02 -0400
committerUnknwon <u@gogs.io>2017-07-27 16:53:02 -0400
commit6bc11c44504135b232605c932c519901a680d4e1 (patch)
treee12a8d108ef2d00347a2d1789d50f61a1617cfaf /pkg/setting/setting.go
parent643c85e9c8fd237912652d14a0535dfddf614d2b (diff)
hook: fix email not sent after push (#4430)
Turns out mail service was not initialized at all, also mail must be sent in sync in hook mode before program exits.
Diffstat (limited to 'pkg/setting/setting.go')
-rw-r--r--pkg/setting/setting.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go
index 039c29c6..f206592d 100644
--- a/pkg/setting/setting.go
+++ b/pkg/setting/setting.go
@@ -832,9 +832,10 @@ var (
MailService *Mailer
)
+// newMailService initializes mail service options from configuration.
+// No non-error log will be printed in hook mode.
func newMailService() {
sec := Cfg.Section("mailer")
- // Check mailer setting.
if !sec.Key("ENABLED").MustBool() {
return
}
@@ -863,6 +864,9 @@ func newMailService() {
MailService.FromEmail = parsed.Address
}
+ if HookMode {
+ return
+ }
log.Info("Mail Service Enabled")
}
@@ -877,6 +881,8 @@ func newRegisterMailService() {
log.Info("Register Mail Service Enabled")
}
+// newNotifyMailService initializes notification email service options from configuration.
+// No non-error log will be printed in hook mode.
func newNotifyMailService() {
if !Cfg.Section("service").Key("ENABLE_NOTIFY_MAIL").MustBool() {
return
@@ -885,6 +891,10 @@ func newNotifyMailService() {
return
}
Service.EnableNotifyMail = true
+
+ if HookMode {
+ return
+ }
log.Info("Notify Mail Service Enabled")
}
@@ -901,3 +911,15 @@ func NewServices() {
newRegisterMailService()
newNotifyMailService()
}
+
+// HookMode indicates whether program starts as Git server-side hook callback.
+var HookMode bool
+
+// NewPostReceiveHookServices initializes all services that are needed by
+// Git server-side post-receive hook callback.
+func NewPostReceiveHookServices() {
+ HookMode = true
+ newService()
+ newMailService()
+ newNotifyMailService()
+}