2020-04-26 20:23:03 +00:00
|
|
|
package dehub
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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.
|
2020-05-12 04:09:01 +00:00
|
|
|
func (payCom PayloadComment) MessageHead(common PayloadCommon) string {
|
|
|
|
return `"` + payCom.Comment + `"`
|
2020-04-26 20:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|