github.phpd.cn/goreleaser/goreleaser@v0.92.0/internal/pipe/release/body.go (about)

     1  package release
     2  
     3  import (
     4  	"bytes"
     5  	"text/template"
     6  
     7  	"github.com/goreleaser/goreleaser/internal/artifact"
     8  	"github.com/goreleaser/goreleaser/pkg/context"
     9  )
    10  
    11  const bodyTemplateText = `{{ .ReleaseNotes }}
    12  
    13  {{- with .DockerImages }}
    14  
    15  ## Docker images
    16  {{ range $element := . }}
    17  - ` + "`docker pull {{ . -}}`" + `
    18  {{- end -}}
    19  {{- end }}
    20  `
    21  
    22  var bodyTemplate *template.Template
    23  
    24  func init() {
    25  	bodyTemplate = template.Must(template.New("release").Parse(bodyTemplateText))
    26  }
    27  
    28  func describeBody(ctx *context.Context) (bytes.Buffer, error) {
    29  	var out bytes.Buffer
    30  	// nolint:prealloc
    31  	var dockers []string
    32  	for _, a := range ctx.Artifacts.Filter(artifact.ByType(artifact.DockerImage)).List() {
    33  		dockers = append(dockers, a.Name)
    34  	}
    35  	err := bodyTemplate.Execute(&out, struct {
    36  		ReleaseNotes string
    37  		DockerImages []string
    38  	}{
    39  		ReleaseNotes: ctx.ReleaseNotes,
    40  		DockerImages: dockers,
    41  	})
    42  	return out, err
    43  }