package server import ( "context" "fmt" "html" "strconv" "strings" "time" "gitlab.com/Timfa/bluegit/internal/ci" "gitlab.com/Timfa/bluegit/internal/i18n" "gitlab.com/Timfa/bluegit/internal/store" "gitlab.com/Timfa/bluegit/internal/webhook" ) func (s *Server) queueFailureMail(repo store.Repo, ev webhook.Event) { if s.Mail == nil || ev.Type != webhook.EventPipelineFailure { return } go func() { ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() if err := s.sendFailureMail(ctx, repo, ev); err != nil && s.Log != nil { s.Log.Error("pipeline-mail", "err", err) } }() } // sendFailureMail mailt de veroorzaker in diens taal. Een fout hier stopt de pipeline niet. func (s *Server) sendFailureMail(ctx context.Context, repo store.Repo, ev webhook.Event) error { if s.Mail == nil { return nil } id, err := strconv.ParseInt(ev.PipelineID, 10, 64) if err != nil || id <= 0 { return nil } p, err := s.Store.PipelineByID(ctx, repo.ID, id) if err != nil { return err } actor := strings.TrimSpace(p.Actor) if actor == "" { return nil } lang := i18n.EN if u, err := s.Store.UserByUsername(ctx, actor); err == nil { lang = i18n.Parse(u.Language) } jobs, err := s.Store.JobsByPipeline(ctx, p.ID) if err != nil { return err } refName, _ := ci.SplitRef(p.Ref) if refName == "" { refName = p.Ref } pipeURL := strings.TrimRight(s.Cfg.BaseURL, "/") + "/" + repo.FullPath() + "/-/pipelines/" + strconv.FormatInt(p.ID, 10) subject := clipRunes(i18n.T(lang, "mail.fail.subject", p.ID, repo.FullPath()), 200) var b strings.Builder fmt.Fprintf(&b, "
%s
", html.EscapeString(i18n.T(lang, "mail.fail.intro", p.ID, repo.FullPath(), refName))) var hard []store.Job for _, j := range jobs { if j.Status == "failed" && !j.AllowFailure { hard = append(hard, j) } } if len(hard) > 0 { fmt.Fprintf(&b, "%s