Skip to content

Commit 47fe20e

Browse files
websterclaude
andcommitted
Add validation.commitStatus setting to gate GitHub commit status posting
post-commit now skips silently unless validation.commitStatus is true in .chunk/config.json. Enable with: chunk config set validation.commitStatus true Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2893c21 commit 47fe20e

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

internal/cmd/config.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func newConfigSetCmd() *cobra.Command {
6262
return &cobra.Command{
6363
Use: "set <key> <value>",
6464
Short: "Set a config value",
65-
Long: "Set a config value. Use 'chunk auth set <provider>' to store credentials with validation.\n\nUser keys: model\nProject keys: orgID, validation.sidecarImage",
65+
Long: "Set a config value. Use 'chunk auth set <provider>' to store credentials with validation.\n\nUser keys: model\nProject keys: orgID, validation.sidecarImage, validation.commitStatus",
6666
Args: cobra.ExactArgs(2),
6767
RunE: func(cmd *cobra.Command, args []string) error {
6868
io := iostream.FromCmd(cmd)
@@ -85,6 +85,11 @@ func newConfigSetCmd() *cobra.Command {
8585
projCfg.Validation = &config.ValidationConfig{}
8686
}
8787
projCfg.Validation.SidecarImage = value
88+
case "validation.commitStatus":
89+
if projCfg.Validation == nil {
90+
projCfg.Validation = &config.ValidationConfig{}
91+
}
92+
projCfg.Validation.CommitStatus = value == "true"
8893
default:
8994
return fmt.Errorf("internal: unhandled project config key %q", key)
9095
}
@@ -98,7 +103,7 @@ func newConfigSetCmd() *cobra.Command {
98103
if !config.ValidConfigKeys[key] {
99104
return &userError{
100105
msg: fmt.Sprintf("Unknown config key: %q.", key),
101-
detail: "Supported keys: model, orgID, validation.sidecarImage.",
106+
detail: "Supported keys: model, orgID, validation.sidecarImage, validation.commitStatus.",
102107
errMsg: fmt.Sprintf("unknown config key %q", key),
103108
}
104109
}

internal/cmd/validate.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,7 @@ func newValidateCmd() *cobra.Command {
168168
}
169169

170170
results, execErr := runValidate(cmd.Context(), workDir, name, inlineCmd, save, sidecarID, identityFile, workdir, allRemote, cfg, statusFn, streams)
171-
172-
if results != nil {
173-
if treeSHA, treeErr := gitutil.ComputeTreeSHA(workDir); treeErr == nil {
174-
_ = validate.SaveResults(treeSHA, results)
175-
}
176-
}
171+
saveValidateResults(workDir, results)
177172

178173
if hook != nil {
179174
maxAttempts := cfg.StopHookMaxAttempts
@@ -343,6 +338,11 @@ func newPostCommitCmd() *cobra.Command {
343338
}
344339
}
345340

341+
projCfg, cfgErr := config.LoadProjectConfig(workDir)
342+
if cfgErr != nil || projCfg.Validation == nil || !projCfg.Validation.CommitStatus {
343+
return nil
344+
}
345+
346346
treeOut, err := exec.Command("git", "-C", workDir, "rev-parse", "HEAD^{tree}").Output()
347347
if err != nil {
348348
return fmt.Errorf("resolve HEAD tree: %w", err)
@@ -524,6 +524,15 @@ func resolveOrCreateSidecarID(ctx context.Context, sidecarID *string, orgID, ima
524524
return nil
525525
}
526526

527+
func saveValidateResults(workDir string, results []validate.CommandResult) {
528+
if len(results) == 0 {
529+
return
530+
}
531+
if treeSHA, err := gitutil.ComputeTreeSHA(workDir); err == nil {
532+
_ = validate.SaveResults(treeSHA, results)
533+
}
534+
}
535+
527536
func mapValidateError(err error) error {
528537
if errors.Is(err, validate.ErrNotConfigured) {
529538
return &userError{

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,5 @@ var ValidConfigKeys = map[string]bool{
268268
var ValidProjectConfigKeys = map[string]bool{
269269
"orgID": true,
270270
"validation.sidecarImage": true,
271+
"validation.commitStatus": true,
271272
}

internal/config/project.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type VCSConfig struct {
4848
// ValidationConfig holds project-level defaults for validation behaviour.
4949
type ValidationConfig struct {
5050
SidecarImage string `json:"sidecarImage,omitempty"`
51+
CommitStatus bool `json:"commitStatus,omitempty"`
5152
}
5253

5354
// ProjectConfig is the per-repo configuration stored in .chunk/config.json.

0 commit comments

Comments
 (0)