From f085f13fa839ece122476601d970460ac249dc69 Mon Sep 17 00:00:00 2001 From: mediocregopher <> Date: Mon, 11 May 2020 22:09:01 -0600 Subject: [PATCH] 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 --- payload.go | 8 ++------ payload_change.go | 4 ++-- payload_comment.go | 8 ++------ payload_credential.go | 12 ++---------- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/payload.go b/payload.go index 74c39aa..15d722f 100644 --- a/payload.go +++ b/payload.go @@ -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) diff --git a/payload_change.go b/payload_change.go index 034ce31..c252e3d 100644 --- a/payload_change.go +++ b/payload_change.go @@ -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. diff --git a/payload_comment.go b/payload_comment.go index a4c1eb4..83970d8 100644 --- a/payload_comment.go +++ b/payload_comment.go @@ -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. diff --git a/payload_credential.go b/payload_credential.go index 1800944..9b114d0 100644 --- a/payload_credential.go +++ b/payload_credential.go @@ -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.