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
main
mediocregopher 4 years ago
parent f52ea2a708
commit f085f13fa8
  1. 8
      payload.go
  2. 4
      payload_change.go
  3. 8
      payload_comment.go
  4. 12
      payload_credential.go

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

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

@ -2,8 +2,6 @@ package dehub
import ( import (
"errors" "errors"
"fmt"
"strings"
) )
// PayloadComment describes the structure of a comment payload. // 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. // MessageHead implements the method for the Payload interface.
func (payCom PayloadComment) MessageHead(common PayloadCommon) (string, error) { func (payCom PayloadComment) MessageHead(common PayloadCommon) string {
credIDs := strings.Join(common.credIDs(), ", ") return `"` + payCom.Comment + `"`
fullMsgHead := fmt.Sprintf("Comment by %s: %s", credIDs, payCom.Comment)
return abbrevCommitMessage(fullMsgHead), nil
} }
// Fingerprint implements the method for the Payload interface. // Fingerprint implements the method for the Payload interface.

@ -2,8 +2,6 @@ package dehub
import ( import (
"errors" "errors"
"fmt"
"strings"
) )
// PayloadCredential describes the structure of a credential payload. // 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. // MessageHead implements the method for the Payload interface.
func (payCred PayloadCredential) MessageHead(common PayloadCommon) (string, error) { func (payCred PayloadCredential) MessageHead(common PayloadCommon) string {
fingerprintStr := common.Fingerprint.String() return "Credential of " + 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
} }
// Fingerprint implements the method for the Payload interface. // Fingerprint implements the method for the Payload interface.

Loading…
Cancel
Save