From 39eb0b68778a8519296fe3000274c4fece933633 Mon Sep 17 00:00:00 2001 From: Sven Sauleau Date: Mon, 3 Feb 2020 19:38:15 +0000 Subject: [PATCH] fix --- cmd/checker/main.go | 4 ++++ packages/packages.go | 36 +++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/cmd/checker/main.go b/cmd/checker/main.go index c46524eb..09477fda 100644 --- a/cmd/checker/main.go +++ b/cmd/checker/main.go @@ -76,6 +76,10 @@ func lintPackage(name string) { } else { warn(ctx, ".autoupdate should not be null. Package will never auto-update") } + + if pckg.Repository.Repotype != "git" { + err(ctx, "Unsupported .repository.type: "+pckg.Repository.Repotype) + } } func err(ctx context.Context, s string) { diff --git a/packages/packages.go b/packages/packages.go index 5b51f075..fda7cc88 100644 --- a/packages/packages.go +++ b/packages/packages.go @@ -193,23 +193,29 @@ func ReadPackageJSON(ctx context.Context, file string) (*Package, error) { case "autoupdate": { if valuemap, ok := value.(map[string]interface{}); ok { - p.Autoupdate = &Autoupdate{ - Source: valuemap["source"].(string), - Target: valuemap["target"].(string), - } - if fileMap, ok := valuemap["fileMap"].([]interface{}); ok { - p.Autoupdate.FileMap = new([]FileMap) - for _, rawvalue := range fileMap { - value := rawvalue.(map[string]interface{}) - autoupdateFileMap := FileMap{ - BasePath: stringInObject("basePath", value), - Files: make([]string, 0), - } - for _, file := range value["files"].([]interface{}) { - autoupdateFileMap.Files = append(autoupdateFileMap.Files, file.(string)) + source, sourceok := valuemap["source"].(string) + target, targetok := valuemap["target"].(string) + if sourceok && targetok { + p.Autoupdate = &Autoupdate{ + Source: source, + Target: target, + } + if fileMap, ok := valuemap["fileMap"].([]interface{}); ok { + p.Autoupdate.FileMap = new([]FileMap) + for _, rawvalue := range fileMap { + value := rawvalue.(map[string]interface{}) + autoupdateFileMap := FileMap{ + BasePath: stringInObject("basePath", value), + Files: make([]string, 0), + } + for _, file := range value["files"].([]interface{}) { + autoupdateFileMap.Files = append(autoupdateFileMap.Files, file.(string)) + } + *p.Autoupdate.FileMap = append(*p.Autoupdate.FileMap, autoupdateFileMap) } - *p.Autoupdate.FileMap = append(*p.Autoupdate.FileMap, autoupdateFileMap) } + } else { + return nil, errors.New(fmt.Sprintf("failed to parse %s: unsupported Autoupdate map", file)) } } else { return nil, errors.New(fmt.Sprintf("failed to parse %s: unsupported Autoupdate", file))