A read-only clone of the dehub project, for until dehub.dev can be brought back online.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dehub/commit_comment.go

47 lines
1.4 KiB

package dehub
import (
"dehub.dev/src/dehub.git/yamlutil"
"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
}