Skip to content

Commit dd4a1f4

Browse files
author
Mohd Uzair
authored
Merge pull request #462 from MUzairS15/MUzairS15/add-utils
Add nil check and string utility function.
2 parents 3658ddb + 4cfac00 commit dd4a1f4

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

generators/generator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/layer5io/meshkit/generators/artifacthub"
77
"github.com/layer5io/meshkit/generators/github"
88
"github.com/layer5io/meshkit/models"
9+
"github.com/layer5io/meshkit/utils"
910
)
1011

1112
const (
@@ -14,6 +15,7 @@ const (
1415
)
1516

1617
func NewGenerator(registrant, url, packageName string) (models.PackageManager, error) {
18+
registrant = utils.ReplaceSpacesAndConvertToLowercase(registrant)
1719
switch registrant {
1820
case artifactHub:
1921
return artifacthub.ArtifactHubPackageManager{

generators/github/git_repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (gr GitRepo) extractRepoDetailsFromSourceURL() (owner, repo, branch, root s
8585
root = parts[3]
8686

8787
} else {
88-
err = ErrInvalidGitHubSourceURL(fmt.Errorf("specify owner, repo, branch and filepath in the url according to the specified source url format"))
88+
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()))
8989
}
9090
return
9191
}

generators/github/package_manager.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ func (ghpm GitHubPackageManager) GetPackage() (models.Package, error) {
2121
protocol := url.Scheme
2222

2323
downloader := NewDownloaderForScheme(protocol, url, ghpm.PackageName)
24+
if downloader == nil {
25+
return nil, ErrGenerateGitHubPackage(err, ghpm.PackageName)
26+
}
2427
ghPackage, err := downloader.GetContent()
2528
if err != nil {
2629
return nil, ErrGenerateGitHubPackage(err, ghpm.PackageName)

utils/csv/csv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (c *CSV[E]) Parse(ch chan E, errorChan chan error) error {
7272
}
7373

7474
if err != nil {
75-
return err
75+
return utils.ErrReadFile(err, c.filePath)
7676
}
7777

7878
if c.predicateFunc != nil && c.predicateFunc(columnNames, values) {

utils/utils.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,8 @@ func CreateDirectory(path string) error{
365365
return err
366366
}
367367
return nil
368-
}
368+
}
369+
370+
func ReplaceSpacesAndConvertToLowercase(s string) string {
371+
return strings.ToLower(strings.ReplaceAll(s, " ", ""))
372+
}

0 commit comments

Comments
 (0)