From 142c10550050cf854ce2af5a6e178222be8a706d Mon Sep 17 00:00:00 2001 From: Haiyan Meng Date: Mon, 6 Jan 2020 11:53:27 -0800 Subject: [PATCH] SKip the empty resource/base item in a kustomization file and set the defaultBranch if needed --- api/internal/crawl/crawler/github/crawler.go | 11 +++++++++++ api/internal/crawl/doc/doc.go | 3 +++ 2 files changed, 14 insertions(+) diff --git a/api/internal/crawl/crawler/github/crawler.go b/api/internal/crawl/crawler/github/crawler.go index fec1628b0..1696a296a 100644 --- a/api/internal/crawl/crawler/github/crawler.go +++ b/api/internal/crawl/crawler/github/crawler.go @@ -97,6 +97,17 @@ func (gc githubCrawler) Crawl( // it will try to add each string in konfig.RecognizedKustomizationFileNames() to // d.FilePath, and try to fetch the document again. func (gc githubCrawler) FetchDocument(_ context.Context, d *doc.Document) error { + // set the default branch if it is empty + if d.DefaultBranch == "" { + url := gc.client.ReposRequest(d.RepositoryFullName()) + defaultBranch, err := gc.client.GetDefaultBranch(url) + if err != nil { + logger.Printf( + "(error: %v) setting default_branch to master\n", err) + defaultBranch = "master" + } + d.DefaultBranch = defaultBranch + } repoURL := d.RepositoryURL + "/" + d.FilePath + "?ref=" + d.DefaultBranch repoSpec, err := git.NewRepoSpecFromUrl(repoURL) if err != nil { diff --git a/api/internal/crawl/doc/doc.go b/api/internal/crawl/doc/doc.go index 953f8d4b4..ec2e031ba 100644 --- a/api/internal/crawl/doc/doc.go +++ b/api/internal/crawl/doc/doc.go @@ -78,6 +78,9 @@ func (doc *KustomizationDocument) GetResources() ([]*Document, error) { res := make([]*Document, 0, len(k.Resources)) for _, r := range k.Resources { + if strings.TrimSpace(r) == "" { + continue + } next, err := doc.Document.FromRelativePath(r) if err != nil { fmt.Printf("GetResources error: %v\n", err)