2020-03-21 18:24:38 +00:00
|
|
|
package dehub
|
|
|
|
|
|
|
|
import (
|
2020-03-29 21:16:36 +00:00
|
|
|
"dehub.dev/src/dehub.git/yamlutil"
|
2020-03-21 18:24:38 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"gopkg.in/src-d/go-git.v4/plumbing/object"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CommitComment describes the structure of a comment commit message.
|
|
|
|
type CommitComment struct {
|
|
|
|
Message string `yaml:"message"`
|
|
|
|
MessageHash yamlutil.Blob `yaml:"message_hash"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ CommitInterface = CommitComment{}
|
|
|
|
|
|
|
|
// NewCommitComment constructs and returns a COmmit populated with a
|
|
|
|
// CommitComment encompassing the given message. The Credentials of the returned
|
|
|
|
// Commit will _not_ be filled in.
|
|
|
|
func (r *Repo) NewCommitComment(msg string) (Commit, error) {
|
|
|
|
cc := CommitComment{Message: msg}
|
|
|
|
var err error
|
|
|
|
if cc.MessageHash, err = cc.Hash(nil, nil); err != nil {
|
|
|
|
return Commit{}, fmt.Errorf("calculating comment hash: %w", err)
|
|
|
|
}
|
|
|
|
return Commit{Comment: &cc}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MessageHead implements the method for the CommitInterface interface.
|
|
|
|
func (cc CommitComment) MessageHead(common CommitCommon) (string, error) {
|
|
|
|
msgAbbrev := abbrevCommitMessage(cc.Message)
|
|
|
|
credAccounts := strings.Join(common.credAccountIDs(), ", ")
|
|
|
|
return fmt.Sprintf("Comment by %s: %s", credAccounts, msgAbbrev), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hash implements the method for the CommitInterface.
|
|
|
|
func (cc CommitComment) Hash(_, _ *object.Tree) ([]byte, error) {
|
|
|
|
return genCommentHash(nil, cc.Message), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetHash implements the method for the CommitInterface.
|
|
|
|
func (cc CommitComment) GetHash() []byte {
|
|
|
|
return cc.MessageHash
|
|
|
|
}
|