feat(lint): provide dry-run, include-jobs and ref options

This commit is contained in:
Sebastian Gumprich 2023-12-21 05:42:00 +00:00 committed by Gary Holtz
parent b84ce07873
commit 8bace091b4
4 changed files with 32 additions and 3 deletions

View File

@ -389,14 +389,17 @@ var PipelineJobsWithSha = func(client *gitlab.Client, pid interface{}, sha strin
return PipelineJobsWithID(client, pid, pipelines[0].ID)
}
var ProjectNamespaceLint = func(client *gitlab.Client, projectID int, content string) (*gitlab.ProjectLintResult, error) {
var ProjectNamespaceLint = func(client *gitlab.Client, projectID int, content string, ref string, dryRun bool, includeJobs bool) (*gitlab.ProjectLintResult, error) {
if client == nil {
client = apiClient.Lab()
}
c, _, err := client.Validate.ProjectNamespaceLint(
projectID,
&gitlab.ProjectNamespaceLintOptions{
Content: &content,
Content: &content,
DryRun: &dryRun,
Ref: &ref,
IncludeJobs: &includeJobs,
},
)
if err != nil {

View File

@ -15,6 +15,12 @@ import (
"github.com/spf13/cobra"
)
var (
ref string
dryRun bool
includeJobs bool
)
func NewCmdLint(f *cmdutils.Factory) *cobra.Command {
pipelineCILintCmd := &cobra.Command{
Use: "lint",
@ -37,6 +43,10 @@ func NewCmdLint(f *cmdutils.Factory) *cobra.Command {
},
}
pipelineCILintCmd.Flags().BoolVarP(&dryRun, "dry-run", "", false, "Run pipeline creation simulation.")
pipelineCILintCmd.Flags().BoolVarP(&includeJobs, "include-jobs", "", false, "The response should include the list of jobs that would exist in a static check or pipeline simulation.")
pipelineCILintCmd.Flags().StringVar(&ref, "ref", "", "When dry-run is true, sets the branch or tag context for validating the CI/CD YAML configuration.")
return pipelineCILintCmd
}
@ -87,7 +97,7 @@ func lintRun(f *cmdutils.Factory, path string) error {
fmt.Fprintln(f.IO.StdOut, "Validating...")
lint, err := api.ProjectNamespaceLint(apiClient, projectID, string(content))
lint, err := api.ProjectNamespaceLint(apiClient, projectID, string(content), ref, dryRun, includeJobs)
if err != nil {
return err
}

View File

@ -29,6 +29,14 @@ $ glab ci lint path/to/.gitlab-ci.yml
```
## Options
```plaintext
--dry-run Run pipeline creation simulation.
--include-jobs The response should include the list of jobs that would exist in a static check or pipeline simulation.
--ref string When dry-run is true, sets the branch or tag context for validating the CI/CD YAML configuration.
```
## Options inherited from parent commands
```plaintext

View File

@ -29,6 +29,14 @@ $ glab ci lint path/to/.gitlab-ci.yml
```
## Options
```plaintext
--dry-run Run pipeline creation simulation.
--include-jobs The response should include the list of jobs that would exist in a static check or pipeline simulation.
--ref string When dry-run is true, sets the branch or tag context for validating the CI/CD YAML configuration.
```
## Options inherited from parent commands
```plaintext