Remove Payload.MessageHead error return and simplify implementations

---
type: change
description: |-
  Remove Payload.MessageHead error return and simplify implementations

  None of the new implementations of Payload.MessageHead can return an error, so
  don't do it. The new implementations place more reliance on the author field of
  the commit to describe the "who", so the commit heads have more room to describe
  the "what".
fingerprint: AIf/6pSXd2ao5vKa8Ju0HAKWwPC2xN2RDQtoUfuDZcnc
credentials:
- type: pgp_signature
  pub_key_id: 95C46FA6A41148AC
  body: iQIzBAABAgAdFiEEJ6tQKp6olvZKJ0lwlcRvpqQRSKwFAl66IV0ACgkQlcRvpqQRSKwuVxAAla713T+aeJwqg4PE5VYrcs29Wfmg2Zc/Otk5l9S8zm+csGV4esEHb1gybe1DfvMhSq3V25jMdu/tt0TRHJUiWskzdHAX4xqNv/pMmcMSB18hpyV3YB+kBYtn+9sSBf4y7tYUVIGtRiycAkazTkAHQZmaufxYCfbx/q5irpyQnIdUb+EXy5o4hJnA9ic0bchS6o8vvDNZpAF2ETi6oylt7MAgo4eeB3M+gpT75U7iGOCWn2qA0ofv4h25M9qcMTm+apRUwncueB19v60GpwRFcAMKvlJfsPEwlJpdvGONilZcA+p4tp7jjn5BP1FeE0UtUSDZHq3bVKcVYxm65kV7yABUDvTnhD7/JylsimB4bOabqbkAkIiu15Z1HFomufS7ozTngTI6AFRCvaQiHTmCvsoM8hSUs4NDUEZo8MzSQaAsAsMn3Pn0Vm1YdtOLJ4ELcBPTb02WnpoIRnHoMbUQuCLwHPHPJxU2aMYXs5WSDv6ZlAlGlkZwe63W2NKc80mChObwYH/Wt6lTLX0m/GrBRzl3Tv+DzlpfJ6le+TrF6HdG/D2DmLXl9Cp8hyw0ClNTszaCACy2rAiyqeoMV4acpi3cShdVXDz1dTC51k7V5IkfUtH/QDxJYqc8DJJrUbJqsROF9JUgZCN58RNRaUbjKLpcI/bIO92Yq0WTqMIagCo=
  account: mediocregopher
This commit is contained in:
mediocregopher 2020-05-11 22:09:01 -06:00
parent f52ea2a708
commit f085f13fa8
4 changed files with 8 additions and 24 deletions

View File

@ -26,7 +26,7 @@ type Payload interface {
// MessageHead returns the head of the commit message (i.e. the first line).
// The PayloadCommon of the outer PayloadUnion is passed in for added
// context, if necessary.
MessageHead(PayloadCommon) (string, error)
MessageHead(PayloadCommon) string
// Fingerprint returns the raw fingerprint which can be signed when
// accrediting this payload. The ChangedFile objects given describe the file
@ -126,11 +126,7 @@ func (p PayloadUnion) Type() string {
// MarshalText implements the encoding.TextMarshaler interface by returning the
// form the payload in the git commit message.
func (p PayloadUnion) MarshalText() ([]byte, error) {
msgHead, err := p.Payload().MessageHead(p.Common)
if err != nil {
return nil, fmt.Errorf("constructing message head: %w", err)
}
msgHead := abbrevCommitMessage(p.Payload().MessageHead(p.Common))
msgBodyB, err := yaml.Marshal(p)
if err != nil {
return nil, fmt.Errorf("marshaling payload %+v as yaml: %w", p, err)

View File

@ -58,8 +58,8 @@ func (proj *Project) NewPayloadChange(description string) (PayloadUnion, error)
}
// MessageHead implements the method for the Payload interface.
func (payCh PayloadChange) MessageHead(PayloadCommon) (string, error) {
return abbrevCommitMessage(payCh.Description), nil
func (payCh PayloadChange) MessageHead(PayloadCommon) string {
return payCh.Description
}
// Fingerprint implements the method for the Payload interface.

View File

@ -2,8 +2,6 @@ package dehub
import (
"errors"
"fmt"
"strings"
)
// PayloadComment describes the structure of a comment payload.
@ -28,10 +26,8 @@ func (proj *Project) NewPayloadComment(comment string) (PayloadUnion, error) {
}
// MessageHead implements the method for the Payload interface.
func (payCom PayloadComment) MessageHead(common PayloadCommon) (string, error) {
credIDs := strings.Join(common.credIDs(), ", ")
fullMsgHead := fmt.Sprintf("Comment by %s: %s", credIDs, payCom.Comment)
return abbrevCommitMessage(fullMsgHead), nil
func (payCom PayloadComment) MessageHead(common PayloadCommon) string {
return `"` + payCom.Comment + `"`
}
// Fingerprint implements the method for the Payload interface.

View File

@ -2,8 +2,6 @@ package dehub
import (
"errors"
"fmt"
"strings"
)
// PayloadCredential describes the structure of a credential payload.
@ -52,14 +50,8 @@ func (proj *Project) NewPayloadCredentialFromChanges(commits []Commit) (PayloadU
}
// MessageHead implements the method for the Payload interface.
func (payCred PayloadCredential) MessageHead(common PayloadCommon) (string, error) {
fingerprintStr := common.Fingerprint.String()
if len(fingerprintStr) > 9 {
fingerprintStr = fingerprintStr[:6] + "..."
}
credIDs := strings.Join(common.credIDs(), ", ")
fullMsgHead := fmt.Sprintf("Credential of hash %s by %s", fingerprintStr, credIDs)
return abbrevCommitMessage(fullMsgHead), nil
func (payCred PayloadCredential) MessageHead(common PayloadCommon) string {
return "Credential of " + common.Fingerprint.String()
}
// Fingerprint implements the method for the Payload interface.