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

49 lines
1.5 KiB

package dehub
import (
"errors"
"fmt"
"strings"
"dehub.dev/src/dehub.git/yamlutil"
)
// 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.ExpectedHash(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)
credIDs := strings.Join(common.credIDs(), ", ")
return fmt.Sprintf("Comment by %s: %s", credIDs, msgAbbrev), nil
}
// ExpectedHash implements the method for the CommitInterface.
func (cc CommitComment) ExpectedHash(changes []ChangedFile) ([]byte, error) {
if len(changes) > 0 {
return nil, errors.New("CommitComment cannot have any changed files")
}
return genCommentHash(nil, cc.Message), nil
}
// StoredHash implements the method for the CommitInterface.
func (cc CommitComment) StoredHash() []byte {
return cc.MessageHash
}