diff --git a/app/cli/cmd/attestation_init.go b/app/cli/cmd/attestation_init.go index e70584e80..f46eb9967 100644 --- a/app/cli/cmd/attestation_init.go +++ b/app/cli/cmd/attestation_init.go @@ -201,7 +201,7 @@ func newAttestationInitCmd() *cobra.Command { cmd.Flags().BoolVar(&existingVersion, "existing-version", false, "return an error if the version doesn't exist in the project") cmd.Flags().StringSliceVar(&collectors, "collectors", nil, "comma-separated list of additional collectors to enable (e.g. aiconfig)") cmd.Flags().BoolVar(&markAsLatest, "mark-latest", true, "explicitly mark the project version as latest (default: automatic for new versions; use =false to skip promotion)") - cmd.Flags().BoolVar(&prMode, "pr", false, "mark this attestation as a pull/merge request build (skips latest promotion and sets the chainloop.dev/is-pull-request annotation; auto-detected from CI env if not set)") + cmd.Flags().BoolVar(&prMode, "pr", false, "mark this attestation as a pull/merge request build (sets the chainloop.dev/is-pull-request annotation; auto-detected from CI env if not set)") return cmd } diff --git a/app/cli/pkg/action/attestation_init.go b/app/cli/pkg/action/attestation_init.go index 492e75c15..f75c5bc82 100644 --- a/app/cli/pkg/action/attestation_init.go +++ b/app/cli/pkg/action/attestation_init.go @@ -194,16 +194,13 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun } // Resolve PR mode: explicit --pr flag wins, otherwise auto-detect from the - // CI runner environment. When in PR mode, default mark-latest=false unless - // the user explicitly passed --mark-latest=true. + // CI runner environment. PR mode only tags the attestation with the + // chainloop.dev/is-pull-request annotation; it does not alter latest + // promotion (use --mark-latest=false explicitly to skip promotion). isPR, err := action.resolvePRMode(ctx, discoveredRunner, opts.PRMode) if err != nil { action.Logger.Warn().Err(err).Msg("failed to detect PR context") } - if isPR && !explicitMarkAsLatestTrue(opts.MarkAsLatest) { - falseVal := false - opts.MarkAsLatest = &falseVal - } // Parse the raw contract to get V2 schema if available var schemaV2 *v1.CraftingSchemaV2 @@ -569,10 +566,3 @@ func (action *AttestationInit) resolvePRMode(ctx context.Context, runner crafter } return detected, nil } - -// explicitMarkAsLatestTrue returns true only when the user explicitly passed -// --mark-latest=true. A nil pointer (flag not set) or an explicit false do not -// count, so PR mode can safely override them to false. -func explicitMarkAsLatestTrue(v *bool) bool { - return v != nil && *v -} diff --git a/app/cli/pkg/action/attestation_init_test.go b/app/cli/pkg/action/attestation_init_test.go index a97ba0885..3452cba13 100644 --- a/app/cli/pkg/action/attestation_init_test.go +++ b/app/cli/pkg/action/attestation_init_test.go @@ -342,36 +342,6 @@ func TestParseContractV2(t *testing.T) { } } -func TestExplicitMarkAsLatestTrue(t *testing.T) { - cases := []struct { - name string - v *bool - want bool - }{ - { - name: "nil pointer (flag not set) is not explicit-true", - v: nil, - want: false, - }, - { - name: "explicit false is not explicit-true", - v: boolPtr(false), - want: false, - }, - { - name: "explicit true is explicit-true", - v: boolPtr(true), - want: true, - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - assert.Equal(t, tc.want, explicitMarkAsLatestTrue(tc.v)) - }) - } -} - func TestResolvePRMode(t *testing.T) { // resolvePRMode uses the override when provided (explicit --pr flag), // otherwise falls back to DetectPRContext from the runner environment.