eeb74ea22b
--- type: change message: |- Implement comment commits This ended up requiring a little refactoring here and there, as well as a fix for typeobj after running into a bug. Also made the commit message unmarshaling a bit more durable, after running into a case where the error message that gets produced for an invalid commit is not very helpful. Currently comment commits are not very well tested. The tests for commit objects in general need to be rethought completely, so they better test the hashes as well as message head parsing. change_hash: AO7Cnfcgbuusch969HHVuo8OJCKh+uuiof+qhnmiD5xo credentials: - type: pgp_signature pub_key_id: 95C46FA6A41148AC body: iQIzBAABAgAdFiEEJ6tQKp6olvZKJ0lwlcRvpqQRSKwFAl52W+EACgkQlcRvpqQRSKzFVhAAj3cscGnlSHc9oP20ddKsro1lnJ53Ha22JKKJ3aO8Z33mIX4aXdVTheLFy8gvmtzeVThBzfshCGt3REHD9rYaSfUEUpd3iDwDBYu907h7fDfx9OhxsZhCcbn3k2si9xe2ESDWE4nFuzKq0W9C8HYBhtTDYV6pW3AmJTlLfLeSoH86nemDAsZ/JlwoIXqYbT63h2Y7FZbnPXHzPTo6ZCbf3u6gdOUDG8vifWTXCbxuueSutTYTJ5vHKejhz/WB21GJhvuZnCVrim0T0mVyyE2evCci7SP249tGj2bmSDF/vVD4aurKsyyd8l6Q38MSGYnsNmAMgZPmSzFTrqmY9bjJ8sir8mv0Pn85/ixWNGHVkZ/A9i515YYGNXQfRaHbHU72Yb5mlPWJQhywffhWLxP7HoGn27P2UJ6hh4f6KMiV26nH/4meV6Y2o0623fZzoETHVVp6oks6dMCcYRb5FF54Ogg/uBPeBOvtiIfy8hTwBqGVrzg7Dm2Sl0ystBuN8ZKrxqa24Wl+MukA5bLH/J9himDwl9XQtL+BYyb4vJkJcNqaGkfKyGU4q3Ggt38X71wGMCmYtWMZ9CIx5VC+OJC5B7C1fUOxG67wKG2X9ShY9MVfCtjrdAtnnECjalyPKXwSkbqB1xsdujxmnXhazYJ3Bf//QXc7tJuSuiG6jMjS24I= account: mediocregopher
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package dehub
|
|
|
|
import (
|
|
"dehub/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
|
|
}
|