-
Notifications
You must be signed in to change notification settings - Fork 199
refactor: use validator to validate fields #533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4a0e0f8
refactor: use validator to validate fields #511
iyear 713e43c
fix: `required_without` tag
iyear 18137f1
fix: docker nil
iyear 7de11da
fix: jiragithub options required `JiraBaseUrl` `JiraUserEmail` `JiraP…
iyear 9ec0591
chore: code format with pr533
daniel-hutao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,11 @@ | ||
package argocdapp | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/util/validation" | ||
"github.com/devstream-io/devstream/pkg/util/validator" | ||
) | ||
|
||
// validate validates the options provided by the core. | ||
|
||
func validate(opts *Options) []error { | ||
retErrors := make([]error, 0) | ||
|
||
if opts.App.Name == "" { | ||
retErrors = append(retErrors, fmt.Errorf("app.name is empty")) | ||
} | ||
if errs := validation.IsDNS1123Subdomain(opts.App.Name); len(errs) != 0 { | ||
for _, e := range errs { | ||
retErrors = append(retErrors, fmt.Errorf("app.name %s is invalid: %s", opts.App.Name, e)) | ||
} | ||
} | ||
|
||
if opts.Source.Path == "" { | ||
retErrors = append(retErrors, fmt.Errorf("source.path is empty")) | ||
} | ||
if opts.Source.RepoURL == "" { | ||
retErrors = append(retErrors, fmt.Errorf("source.repoURL is empty")) | ||
} | ||
|
||
return retErrors | ||
return validator.Struct(opts) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,26 @@ | ||
package reposcaffolding | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
|
||
"github.com/devstream-io/devstream/pkg/util/validator" | ||
) | ||
|
||
type Options struct { | ||
Owner string | ||
Org string | ||
Repo string | ||
Branch string | ||
Owner string `validate:"required_without=Org"` | ||
Org string `validate:"required_without=Owner"` | ||
Repo string `validate:"required"` | ||
Branch string `validate:"required"` | ||
PathWithNamespace string | ||
ImageRepo string `mapstructure:"image_repo"` | ||
} | ||
|
||
// Validate validates the options provided by the core. | ||
func Validate(opts *Options) []error { | ||
retErrors := make([]error, 0) | ||
|
||
// owner/org/repo/branch | ||
if opts.Owner == "" && opts.Org == "" { | ||
retErrors = append(retErrors, fmt.Errorf("owner and org are empty")) | ||
} | ||
if opts.Repo == "" { | ||
retErrors = append(retErrors, fmt.Errorf("repo is empty")) | ||
} | ||
|
||
retErrors = append(retErrors, validator.Struct(opts)...) | ||
// set PathWithNamespace for GitLab. GitHub won't need to use this | ||
opts.PathWithNamespace = fmt.Sprintf("%s/%s", opts.Owner, opts.Repo) | ||
if opts.Branch == "" { | ||
retErrors = append(retErrors, fmt.Errorf("branch is empty")) | ||
} | ||
|
||
return retErrors | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,9 @@ | ||
package nodejs | ||
|
||
import "fmt" | ||
import ( | ||
"github.com/devstream-io/devstream/pkg/util/validator" | ||
) | ||
|
||
func validate(opts *Options) []error { | ||
retErrors := make([]error, 0) | ||
|
||
// owner/org/repo/branch | ||
if opts.Owner == "" && opts.Org == "" { | ||
retErrors = append(retErrors, fmt.Errorf("owner and org are empty")) | ||
} | ||
if opts.Repo == "" { | ||
retErrors = append(retErrors, fmt.Errorf("repo is empty")) | ||
} | ||
if opts.Branch == "" { | ||
retErrors = append(retErrors, fmt.Errorf("branch is empty")) | ||
} | ||
|
||
// language | ||
if opts.Language == nil { | ||
retErrors = append(retErrors, fmt.Errorf("language is empty")) | ||
} | ||
if errs := opts.Language.Validate(); len(errs) != 0 { | ||
for _, e := range errs { | ||
retErrors = append(retErrors, fmt.Errorf("language is invalid: %s", e)) | ||
} | ||
} | ||
|
||
return retErrors | ||
return validator.Struct(opts) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.