include commit hashes as part of credential commit when accrediting change commi...
--- type: change message: include commit hashes as part of credential commit when accrediting change commits change_hash: AF5g6f2/qrEn0z3JA2PJ9wec71TwWGuMYfrsPPlRTxla credentials: - type: pgp_signature pub_key_id: 95C46FA6A41148AC body: iQIzBAABAgAdFiEEJ6tQKp6olvZKJ0lwlcRvpqQRSKwFAl578NwACgkQlcRvpqQRSKzoVRAAmWfVIA//2yVHJ8VgJyhnfVY/zqFk4dmX+ynxuyBrH2Bp7HVgZBscxLSdrBLBPB68NHinAbK6kPXw2U/NIGcUdHoHfo4Oh6crCtfsMhHb6k4afJKshVKCWDsIws/4gWo4/usvJZEKAjLXys+wmXz6HEsXj1DOP1Z+WjrApuDoOKDxKXVvSmwqKKpfJPhLJJOxKLlfJtwa5a4EuLNvXDL99eOPlvIIaxtl5hj499torpin6Wra6WJikFxEk6jECxz9K7xiVNmKCJ/eT0YQc42misi3kEV5HkIlHpl3IJ6g40dAr92kKVTy2xbgAa2KJYfbU5eF2YoAlByuX6g1upKFSPQBzAuCRLqxIwSDHApSkLG+S56Z8vuxOjrUo868VzXyu2z6VJRvcLJeTpMzm35u1B8WffEqyNnnI+v4m4z7ge7g01HakT1kJuyxBtR3INl3vYT3uXD8yXs0oxexyT12ZRA0l9rKlqdkp7DcxNAkm8SJUUkuG2nArWfqYYtagWKk26espGh1tiBTsTqkbwfdu1mxl1qBwU6n80eUT5oAo0LccjH3sKSPObNKwMLiKn6O9kvSX9yO9a1XiuqdfcTxcvBkqR9hHKdQtmbN2R5HvUv1jNQz/jsqh48u9h01GN6zCDt3AaCEAn6cB/DxCvYbDZwdAVJX3ulONnVs4c6k1UI= account: mediocregopher
This commit is contained in:
parent
aa1a4969f3
commit
a8c7f92328
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
func cmdCommit(ctx context.Context, cmd *dcmd.Cmd) {
|
func cmdCommit(ctx context.Context, cmd *dcmd.Cmd) {
|
||||||
flag := cmd.FlagSet()
|
flag := cmd.FlagSet()
|
||||||
accountID := flag.String("account-id", "", "Account to sign commit as")
|
accountID := flag.String("account-id", "", "Account to accredit commit with")
|
||||||
|
|
||||||
repo := ctxRepo(ctx)
|
repo := ctxRepo(ctx)
|
||||||
accreditAndCommit := func(commit dehub.Commit) error {
|
accreditAndCommit := func(commit dehub.Commit) error {
|
||||||
@ -99,7 +99,7 @@ func cmdCommit(ctx context.Context, cmd *dcmd.Cmd) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
cmd.SubCmd("credential", "Commit credential of a different commit",
|
cmd.SubCmd("credential", "Commit credential of one or more change commits",
|
||||||
func(ctx context.Context, cmd *dcmd.Cmd) {
|
func(ctx context.Context, cmd *dcmd.Cmd) {
|
||||||
flag := cmd.FlagSet()
|
flag := cmd.FlagSet()
|
||||||
startRev := flag.String("start", "", "Revision of the starting commit to accredit (when accrediting a range of changes)")
|
startRev := flag.String("start", "", "Revision of the starting commit to accredit (when accrediting a range of changes)")
|
||||||
@ -117,7 +117,10 @@ func cmdCommit(ctx context.Context, cmd *dcmd.Cmd) {
|
|||||||
gitCommit, err := repo.GetGitRevision(plumbing.Revision(*rev))
|
gitCommit, err := repo.GetGitRevision(plumbing.Revision(*rev))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("resolving revision %q: %w", *rev, err)
|
return nil, fmt.Errorf("resolving revision %q: %w", *rev, err)
|
||||||
} else if credCommit, err = repo.NewCommitCredential(gitCommit.Interface.GetHash()); err != nil {
|
}
|
||||||
|
|
||||||
|
gitCommits := []dehub.GitCommit{gitCommit}
|
||||||
|
if credCommit, err = repo.NewCommitCredentialFromChanges(gitCommits); err != nil {
|
||||||
return nil, fmt.Errorf("constructing credential commit: %w", err)
|
return nil, fmt.Errorf("constructing credential commit: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
13
commit.go
13
commit.go
@ -441,7 +441,7 @@ func (r *Repo) verifyCommit(branch plumbing.ReferenceName, gitCommit GitCommit,
|
|||||||
}
|
}
|
||||||
|
|
||||||
type changeRangeInfo struct {
|
type changeRangeInfo struct {
|
||||||
lastChangeCommit GitCommit
|
changeCommits []GitCommit
|
||||||
authors map[string]struct{}
|
authors map[string]struct{}
|
||||||
msg string
|
msg string
|
||||||
startTree, endTree *object.Tree
|
startTree, endTree *object.Tree
|
||||||
@ -455,17 +455,15 @@ func (r *Repo) changeRangeInfo(commits []GitCommit) (changeRangeInfo, error) {
|
|||||||
authors: map[string]struct{}{},
|
authors: map[string]struct{}{},
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastChangeCommitOk bool
|
|
||||||
for _, commit := range commits {
|
for _, commit := range commits {
|
||||||
if _, ok := commit.Interface.(*CommitChange); ok {
|
if _, ok := commit.Interface.(*CommitChange); ok {
|
||||||
info.lastChangeCommit = commit
|
info.changeCommits = append(info.changeCommits, commit)
|
||||||
lastChangeCommitOk = true
|
|
||||||
for _, cred := range commit.Commit.Common.Credentials {
|
for _, cred := range commit.Commit.Common.Credentials {
|
||||||
info.authors[cred.AccountID] = struct{}{}
|
info.authors[cred.AccountID] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !lastChangeCommitOk {
|
if len(info.changeCommits) == 0 {
|
||||||
return changeRangeInfo{}, errors.New("no change commits found")
|
return changeRangeInfo{}, errors.New("no change commits found")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -477,8 +475,9 @@ func (r *Repo) changeRangeInfo(commits []GitCommit) (changeRangeInfo, error) {
|
|||||||
commits[0].GitCommit.Hash, err)
|
commits[0].GitCommit.Hash, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
info.msg = info.lastChangeCommit.Commit.Change.Message
|
lastChangeCommit := info.changeCommits[len(info.changeCommits)-1]
|
||||||
info.endTree = info.lastChangeCommit.GitTree
|
info.msg = lastChangeCommit.Commit.Change.Message
|
||||||
|
info.endTree = lastChangeCommit.GitTree
|
||||||
info.changeHash = genChangeHash(nil, info.msg, info.startTree, info.endTree)
|
info.changeHash = genChangeHash(nil, info.msg, info.startTree, info.endTree)
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,11 @@ import (
|
|||||||
// CommitCredential describes the structure of a credential commit message.
|
// CommitCredential describes the structure of a credential commit message.
|
||||||
type CommitCredential struct {
|
type CommitCredential struct {
|
||||||
CredentialedHash yamlutil.Blob `yaml:"credentialed_hash"`
|
CredentialedHash yamlutil.Blob `yaml:"credentialed_hash"`
|
||||||
|
|
||||||
|
// CommitHashes represents the commits which this credential is accrediting.
|
||||||
|
// It is only present for informational purposes, as commits don't not have
|
||||||
|
// any bearing on the CredentialedHash itself.
|
||||||
|
CommitHashes []string `yaml:"commits,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ CommitInterface = CommitCredential{}
|
var _ CommitInterface = CommitCredential{}
|
||||||
@ -36,7 +41,19 @@ func (r *Repo) NewCommitCredentialFromChanges(commits []GitCommit) (Commit, erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return Commit{}, err
|
return Commit{}, err
|
||||||
}
|
}
|
||||||
return r.NewCommitCredential(info.changeHash)
|
|
||||||
|
commitCred, err := r.NewCommitCredential(info.changeHash)
|
||||||
|
if err != nil {
|
||||||
|
return Commit{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, commit := range info.changeCommits {
|
||||||
|
commitCred.Credential.CommitHashes = append(
|
||||||
|
commitCred.Credential.CommitHashes,
|
||||||
|
commit.GitCommit.Hash.String(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return commitCred, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessageHead implements the method for the CommitInterface interface.
|
// MessageHead implements the method for the CommitInterface interface.
|
||||||
|
Loading…
Reference in New Issue
Block a user