go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/luci_notify/mailtmpl/templates.go (about)

     1  // Copyright 2019 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package mailtmpl implements email template bundling and execution.
    16  package mailtmpl
    17  
    18  import (
    19  	html "html/template"
    20  	"strings"
    21  )
    22  
    23  // errorBodyTemplate is used when a user-defined email template fails.
    24  var errorBodyTemplate = html.Must(html.New("error").
    25  	Funcs(Funcs).
    26  	Parse(strings.TrimSpace(`
    27  <p>A <a href="https://{{.BuildbucketHostname}}/build/{{.Build.Id}}">build</a>
    28  	on builder <code>{{ .Build.Builder | formatBuilderID }}</code>
    29  	completed with status <code>{{.Build.Status}}</code>.</p>
    30  
    31  <p>This email is so spartan because the actual
    32  <a href="{{.TemplateURL}}">email template <code>{{.TemplateName}}</code></a>
    33  has failed on this build:
    34  <pre>{{.Error}}</pre>
    35  </p>
    36  `)))
    37  
    38  var defaultTemplate = &Template{
    39  	Name:                DefaultTemplateName,
    40  	SubjectTextTemplate: `[Build Status] Builder "{{ .Build.Builder | formatBuilderID }}"`,
    41  	BodyHTMLTemplate: strings.TrimSpace(`
    42  luci-notify detected a status change for builder "{{ .Build.Builder | formatBuilderID }}"
    43  at {{ .Build.EndTime | time }}.
    44  
    45  <table>
    46    <tr>
    47      <td>New status:</td>
    48      <td><b>{{ .Build.Status }}</b></td>
    49    </tr>
    50    <tr>
    51      <td>Previous status:</td>
    52      <td>{{ .OldStatus }}</td>
    53    </tr>
    54    <tr>
    55      <td>Builder:</td>
    56      <td>{{ .Build.Builder | formatBuilderID }}</td>
    57    </tr>
    58    <tr>
    59      <td>Created by:</td>
    60      <td>{{ .Build.CreatedBy }}</td>
    61    </tr>
    62    <tr>
    63      <td>Created at:</td>
    64      <td>{{ .Build.CreateTime | time }}</td>
    65    </tr>
    66    <tr>
    67      <td>Finished at:</td>
    68      <td>{{ .Build.EndTime | time }}</td>
    69    </tr>
    70  </table>
    71  
    72  Full details are available
    73  <a href="https://{{.BuildbucketHostname}}/build/{{.Build.Id}}">here</a>.
    74  <br/><br/>
    75  
    76  You are receiving the default template as no template was provided or a template
    77  name did not match the one provided.
    78  `),
    79  }