From f7de8f3ee4cdd31a5bf2020fce2f707896d04ccb Mon Sep 17 00:00:00 2001 From: Jason Rudolph Date: Tue, 19 Jan 2021 16:00:38 -0500 Subject: [PATCH] Revert "Promote git metadata functionality from experimental to stable" This reverts commit 2bcee536e144533c6c7a9175dc00c131df8ef91d. --- cmd/submit.go | 5 +++-- cmd/submit_test.go | 1 + metadata/metadata.go | 31 ++++++++++++++++++++++--------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/cmd/submit.go b/cmd/submit.go index d9440a27..0f8c2a8d 100644 --- a/cmd/submit.go +++ b/cmd/submit.go @@ -101,11 +101,12 @@ func (s *Submit) Init(args []string, envs map[string]string) error { info, err = os.Stat(s.repositoryPath) if err != nil || !info.IsDir() { - return fmt.Errorf("invalid value for flag -repository-dir: %s is not a directory", s.repositoryPath) + return fmt.Errorf("[experimental] invalid value for flag -repository-dir: %s is not a directory", s.repositoryPath) } s.commitResolver, err = metadata.NewCommitResolver(s.repositoryPath) if err != nil { - return fmt.Errorf("invalid value for flag -repository-dir: %v", err) + // Git metadata functionality is experimental. While it's experimental, don't let an invalid repository prevent the test-reporter from continuing normal operation. + fmt.Fprintf(os.Stderr, "[experimental] invalid value for flag -repository-dir: %v\n", err) } s.envs = envs diff --git a/cmd/submit_test.go b/cmd/submit_test.go index efa92e73..8f53d4c4 100644 --- a/cmd/submit_test.go +++ b/cmd/submit_test.go @@ -176,6 +176,7 @@ func TestSubmit_Init_invalidPath(t *testing.T) { func TestSubmit_Init_invalidRepoPath(t *testing.T) { t.Run("NonRepoPath", func(t *testing.T) { + t.Skip("skipping while git metadata functionality is experimental") s := NewSubmit(&metadata.Version{}) err := s.Init([]string{ ".", diff --git a/metadata/metadata.go b/metadata/metadata.go index 7244da50..fb35986f 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -2,6 +2,7 @@ package metadata import ( "fmt" + "os" "regexp" "strconv" "strings" @@ -25,29 +26,41 @@ type Metadata interface { // AbstractMetadata provides the fields that are common across all Metadata // instances, regardless of the specific CI provider. type AbstractMetadata struct { - AuthoredAt time.Time `yaml:":authored_at"` - AuthorEmail string `yaml:":author_email"` - AuthorName string `yaml:":author_name"` + AuthoredAt time.Time `yaml:":authored_at,omitempty"` + AuthorEmail string `yaml:":author_email,omitempty"` + AuthorName string `yaml:":author_name,omitempty"` Branch string `yaml:":branch"` BuildURL string `yaml:":build_url"` Check string `yaml:":check" env:"BUILDPULSE_CHECK_NAME"` CIProvider string `yaml:":ci_provider"` - CommitMessage string `yaml:":commit_message"` + CommitMessage string `yaml:":commit_message,omitempty"` CommitSHA string `yaml:":commit"` - CommittedAt time.Time `yaml:":committed_at"` - CommitterEmail string `yaml:":committer_email"` - CommitterName string `yaml:":committer_name"` + CommittedAt time.Time `yaml:":committed_at,omitempty"` + CommitterEmail string `yaml:":committer_email,omitempty"` + CommitterName string `yaml:":committer_name,omitempty"` RepoNameWithOwner string `yaml:":repo_name_with_owner"` ReporterOS string `yaml:":reporter_os"` ReporterVersion string `yaml:":reporter_version"` Timestamp time.Time `yaml:":timestamp"` - TreeSHA string `yaml:":tree"` + TreeSHA string `yaml:":tree,omitempty"` } func (a *AbstractMetadata) initCommitData(cr CommitResolver, sha string) error { + // Git metadata functionality is experimental. While it's experimental, detect a nil CommitResolver and allow the commit metadata fields to be uploaded with empty values. + if cr == nil { + fmt.Fprintf(os.Stderr, "[experimental] no commit resolver available; falling back to commit data from environment\n") + + a.CommitSHA = sha + return nil + } + + // Git metadata functionality is experimental. While it's experimental, don't let this error prevent the test-reporter from continuing normal operation. Allow the commit metadata fields to be uploaded with empty values. c, err := cr.Lookup(sha) if err != nil { - return err + fmt.Fprintf(os.Stderr, "[experimental] git-based commit lookup unsuccessful; falling back to commit data from environment: %v\n", err) + + a.CommitSHA = sha + return nil } a.AuthoredAt = c.AuthoredAt