Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/cli/cmd/attestation_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
16 changes: 3 additions & 13 deletions app/cli/pkg/action/attestation_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
30 changes: 0 additions & 30 deletions app/cli/pkg/action/attestation_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading