package dehub import ( "errors" "fmt" "strings" ) // PayloadComment describes the structure of a comment payload. type PayloadComment struct { Comment string `yaml:"comment"` } var _ Payload = PayloadComment{} // NewPayloadComment constructs a PayloadUnion populated with a PayloadComment. // The Credentials of the returned PayloadUnion will _not_ be filled in. func (proj *Project) NewPayloadComment(comment string) (PayloadUnion, error) { payCom := PayloadComment{Comment: comment} fingerprint, err := payCom.Fingerprint(nil) if err != nil { return PayloadUnion{}, err } return PayloadUnion{ Comment: &payCom, Common: PayloadCommon{Fingerprint: fingerprint}, }, nil } // 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 } // Fingerprint implements the method for the Payload interface. func (payCom PayloadComment) Fingerprint(changes []ChangedFile) ([]byte, error) { if len(changes) > 0 { return nil, errors.New("PayloadComment cannot have any changed files") } return genCommentFingerprint(nil, payCom.Comment), nil }