Skip to content
Open
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: 0 additions & 2 deletions cmd/kosli/attestCustom.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ func newAttestCustomCmd(out io.Writer) *cobra.Command {
},

RunE: func(cmd *cobra.Command, args []string) error {
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
o.repoNameExplicit = cmd.Flags().Changed("repository")
return o.run(args)
},
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/kosli/attestDecision.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ func newAttestDecisionCmd(out io.Writer) *cobra.Command {
},

RunE: func(cmd *cobra.Command, args []string) error {
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
o.repoNameExplicit = cmd.Flags().Changed("repository")
return o.run(args)
},
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/kosli/attestGeneric.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ func newAttestGenericCmd(out io.Writer) *cobra.Command {
},

RunE: func(cmd *cobra.Command, args []string) error {
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
o.repoNameExplicit = cmd.Flags().Changed("repository")
return o.run(args)
},
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/kosli/attestJira.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ func newAttestJiraCmd(out io.Writer) *cobra.Command {

},
RunE: func(cmd *cobra.Command, args []string) error {
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
o.repoNameExplicit = cmd.Flags().Changed("repository")
return o.run(args)
},
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/kosli/attestJunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ func newAttestJunitCmd(out io.Writer) *cobra.Command {

},
RunE: func(cmd *cobra.Command, args []string) error {
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
o.repoNameExplicit = cmd.Flags().Changed("repository")
return o.run(args)
},
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/kosli/attestOverride.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ func newAttestOverrideCmd(out io.Writer) *cobra.Command {
},

RunE: func(cmd *cobra.Command, args []string) error {
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
o.repoNameExplicit = cmd.Flags().Changed("repository")
return o.run(args)
},
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/kosli/attestPRAzure.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ func newAttestAzurePRCmd(out io.Writer) *cobra.Command {

},
RunE: func(cmd *cobra.Command, args []string) error {
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
o.repoNameExplicit = cmd.Flags().Changed("repository")
o.retriever = azUtils.NewAzureConfig(azureFlagsValues.Token,
azureFlagsValues.OrgUrl, azureFlagsValues.Project, o.repoName)
return o.run(args)
Expand Down
2 changes: 0 additions & 2 deletions cmd/kosli/attestPRBitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ func newAttestBitbucketPRCmd(out io.Writer) *cobra.Command {

},
RunE: func(cmd *cobra.Command, args []string) error {
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
o.repoNameExplicit = cmd.Flags().Changed("repository")
o.getRetriever().(*bbUtils.Config).Repository = o.repoName
return o.run(args)
},
Expand Down
2 changes: 0 additions & 2 deletions cmd/kosli/attestPRGithub.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ func newAttestGithubPRCmd(out io.Writer) *cobra.Command {

},
RunE: func(cmd *cobra.Command, args []string) error {
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
o.repoNameExplicit = cmd.Flags().Changed("repository")
o.retriever = ghUtils.NewGithubRetrieverFunc(githubFlagsValues.Token, githubFlagsValues.BaseURL,
githubFlagsValues.Org, o.repoName, global.Debug)
return o.run(args)
Expand Down
2 changes: 0 additions & 2 deletions cmd/kosli/attestPRGitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ func newAttestGitlabPRCmd(out io.Writer) *cobra.Command {

},
RunE: func(cmd *cobra.Command, args []string) error {
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
o.repoNameExplicit = cmd.Flags().Changed("repository")
// GitlabConfig.Repository is the short project name (CI_PROJECT_NAME);
// combined with Org (CI_PROJECT_NAMESPACE) it forms the API ProjectID.
// This is separate from repo_info.name, which uses the full CI_PROJECT_PATH.
Expand Down
2 changes: 0 additions & 2 deletions cmd/kosli/attestSbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ func newAttestSbomCmd(out io.Writer) *cobra.Command {
},

RunE: func(cmd *cobra.Command, args []string) error {
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
o.repoNameExplicit = cmd.Flags().Changed("repository")
return o.run(args)
},
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/kosli/attestSnyk.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ func newAttestSnykCmd(out io.Writer) *cobra.Command {

},
RunE: func(cmd *cobra.Command, args []string) error {
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
o.repoNameExplicit = cmd.Flags().Changed("repository")
return o.run(args)
},
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/kosli/attestSonar.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ func newAttestSonarCmd(out io.Writer) *cobra.Command {

},
RunE: func(cmd *cobra.Command, args []string) error {
o.repoURLExplicit = cmd.Flags().Changed("repo-url")
o.repoNameExplicit = cmd.Flags().Changed("repository")
o.revisionExplicit = cmd.Flags().Changed("sonar-revision")
return o.run(args)
},
Expand Down
6 changes: 2 additions & 4 deletions cmd/kosli/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ type CommonAttestationOptions struct {
repoName string
repoURL string
repoProvider string
repoURLExplicit bool
repoNameExplicit bool
noCommitInfo bool
// flags lets run tell a passed flag from a defaulted one.
flags *pflag.FlagSet
Expand Down Expand Up @@ -140,10 +138,10 @@ func (o *CommonAttestationOptions) run(args []string, payload *CommonAttestation
logger.Warn("failed to get git repo info. %s", err.Error())
}

if err := validateRepoFlags(o.repoURL, o.repoProvider, o.repoURLExplicit); err != nil {
if err := validateRepoFlags(o.repoURL, o.repoProvider, o.explicit("repo-url")); err != nil {
return err
}
payload.GitRepoInfo = mergeGitRepoInfo(payload.GitRepoInfo, o.repoID, o.repoName, o.repoURL, o.repoProvider, o.repoNameExplicit)
payload.GitRepoInfo = mergeGitRepoInfo(payload.GitRepoInfo, o.repoID, o.repoName, o.repoURL, o.repoProvider, o.explicit("repository"))

return o.loadUserDataURLsAndAnnotations(payload)
}
Expand Down
13 changes: 10 additions & 3 deletions cmd/kosli/repoInfoWiring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
// CI-detected name) can't be reproduced under KOSLI_TESTS, which zeroes flag
// defaults; that logic is covered directly by TestMergeGitRepoInfo. This suite
// instead guards the command wiring: an explicit --repository must reach
// repo_info.name. Because the CI base name here is non-empty, a missing
// `repoNameExplicit` assignment would leave the base name in place and fail the
// explicit-override cases.
// repo_info.name. Because the CI base name here is non-empty, a path that lost
// track of --repository being passed would leave the base name in place and
// fail the explicit-override cases. `begin trail` and `attest artifact` record
// that in a `repoNameExplicit` field their RunE has to set.
type RepoInfoWiringTestSuite struct {
suite.Suite
defaultKosliArguments string
Expand Down Expand Up @@ -85,6 +86,12 @@ func (suite *RepoInfoWiringTestSuite) TestRepoInfoNameWiring() {
cmd: "attest generic --fingerprint " + fingerprint + " --name foo --flow f --trail t --repository my/explicit-repo" + suite.defaultKosliArguments,
goldenRegex: `"name": "my/explicit-repo"`,
},
{
wantError: true,
name: "attest generic: an explicit --repo-url is validated (the guard that needs no server)",
cmd: "attest generic --fingerprint " + fingerprint + " --name foo --flow f --trail t --repo-url not-a-url" + suite.defaultKosliArguments,
goldenRegex: `--repo-url 'not-a-url' is not a valid URL`,
},
{
name: "begin trail: CI-detected full-path name is used by default",
cmd: "begin trail t --flow f" + suite.defaultKosliArguments,
Expand Down
Loading