From 6bc11c44504135b232605c932c519901a680d4e1 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 27 Jul 2017 16:53:02 -0400 Subject: 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. --- cmd/hook.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'cmd') diff --git a/cmd/hook.go b/cmd/hook.go index 0ff4a1c6..f8b96970 100644 --- a/cmd/hook.go +++ b/cmd/hook.go @@ -11,6 +11,7 @@ import ( "fmt" "os" "os/exec" + "path" "path/filepath" "strings" @@ -22,7 +23,9 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/pkg/httplib" + "github.com/gogits/gogs/pkg/mailer" "github.com/gogits/gogs/pkg/setting" + "github.com/gogits/gogs/pkg/template" http "github.com/gogits/gogs/routes/repo" ) @@ -184,6 +187,13 @@ func runHookPostReceive(c *cli.Context) error { } setup(c, "hooks/post-receive.log", true) + // Post-receive hook does more than just gather Git information, + // so we need to setup additional services for email notifications. + setting.NewPostReceiveHookServices() + mailer.NewContext() + mailer.InitMailRender(path.Join(setting.StaticRootPath, "templates/mail"), + path.Join(setting.CustomPath, "templates/mail"), template.NewFuncMap()) + isWiki := strings.Contains(os.Getenv(http.ENV_REPO_CUSTOM_HOOKS_PATH), ".wiki.git/") buf := bytes.NewBuffer(nil) -- cgit v1.2.3