Skip to content

Commit

Permalink
Merge pull request #462 from MUzairS15/MUzairS15/add-utils
Browse files Browse the repository at this point in the history
Add nil check and string utility function.
  • Loading branch information
Mohd Uzair authored Feb 22, 2024
2 parents 3658ddb + 4cfac00 commit dd4a1f4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions generators/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/layer5io/meshkit/generators/artifacthub"
"github.com/layer5io/meshkit/generators/github"
"github.com/layer5io/meshkit/models"
"github.com/layer5io/meshkit/utils"
)

const (
Expand All @@ -14,6 +15,7 @@ const (
)

func NewGenerator(registrant, url, packageName string) (models.PackageManager, error) {
registrant = utils.ReplaceSpacesAndConvertToLowercase(registrant)
switch registrant {
case artifactHub:
return artifacthub.ArtifactHubPackageManager{
Expand Down
2 changes: 1 addition & 1 deletion generators/github/git_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (gr GitRepo) extractRepoDetailsFromSourceURL() (owner, repo, branch, root s
root = parts[3]

} else {
err = ErrInvalidGitHubSourceURL(fmt.Errorf("specify owner, repo, branch and filepath in the url according to the specified source url format"))
err = ErrInvalidGitHubSourceURL(fmt.Errorf("Source URL $s is invalid, specify owner, repo, branch and filepath in the url according to the specified source url format", gr.URL.String()))

Check failure on line 88 in generators/github/git_repo.go

View workflow job for this annotation

GitHub Actions / lint

printf: fmt.Errorf call has arguments but no formatting directives (govet)
}
return
}
Expand Down
3 changes: 3 additions & 0 deletions generators/github/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ func (ghpm GitHubPackageManager) GetPackage() (models.Package, error) {
protocol := url.Scheme

downloader := NewDownloaderForScheme(protocol, url, ghpm.PackageName)
if downloader == nil {
return nil, ErrGenerateGitHubPackage(err, ghpm.PackageName)
}
ghPackage, err := downloader.GetContent()
if err != nil {
return nil, ErrGenerateGitHubPackage(err, ghpm.PackageName)
Expand Down
2 changes: 1 addition & 1 deletion utils/csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *CSV[E]) Parse(ch chan E, errorChan chan error) error {
}

if err != nil {
return err
return utils.ErrReadFile(err, c.filePath)
}

if c.predicateFunc != nil && c.predicateFunc(columnNames, values) {
Expand Down
6 changes: 5 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,8 @@ func CreateDirectory(path string) error{
return err
}
return nil
}
}

func ReplaceSpacesAndConvertToLowercase(s string) string {
return strings.ToLower(strings.ReplaceAll(s, " ", ""))
}

0 comments on commit dd4a1f4

Please sign in to comment.