vault/tools/pipeline/internal/pkg/github/noop_commit.go
Vault Automation 0c6c13dd38
license: update headers to IBM Corp. (#10229) (#10233)
* license: update headers to IBM Corp.
* `make proto`
* update offset because source file changed

Signed-off-by: Ryan Cragun <me@ryan.ec>
Co-authored-by: Ryan Cragun <me@ryan.ec>
2025-10-21 15:20:20 -06:00

38 lines
976 B
Go

// Copyright IBM Corp. 2016, 2025
// SPDX-License-Identifier: BUSL-1.1
package github
import (
"context"
"fmt"
"log/slog"
libgit "github.com/hashicorp/vault/tools/pipeline/internal/pkg/git"
slogctx "github.com/veqryn/slog-context"
)
func resetAndCreateNOOPCommit(ctx context.Context, git *libgit.Client, baseRef string) error {
ctx = slogctx.Append(ctx, slog.String("base-ref", baseRef))
slog.Default().DebugContext(ctx, "hard resetting current checkout and creating no-op commit")
resetRes, err := git.Reset(ctx, &libgit.ResetOpts{
Mode: libgit.ResetModeHard,
Treeish: baseRef,
})
if err != nil {
return fmt.Errorf("resetting back to base reference: %s: %w", resetRes.String(), err)
}
commitRes, err := git.Commit(ctx, &libgit.CommitOpts{
AllowEmpty: true,
Message: "no-op commit",
NoVerify: true,
NoEdit: true,
})
if err != nil {
return fmt.Errorf("committing no-op commit: %s: %w", commitRes.String(), err)
}
return nil
}