From 81f0d41b5196f0e2e016e7fd6f366aab0a8e657d Mon Sep 17 00:00:00 2001 From: Saurabh Prakash Date: Thu, 3 Mar 2022 15:22:14 +0530 Subject: [PATCH] Bug fix. Empty base-commit fix --- pkg/core/interfaces.go | 2 +- pkg/core/lifecycle.go | 13 +++++++++---- pkg/diffmanager/setup.go | 4 ---- pkg/testdiscoveryservice/testdiscovery.go | 5 +++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pkg/core/interfaces.go b/pkg/core/interfaces.go index 51ca06d..9d12c4e 100644 --- a/pkg/core/interfaces.go +++ b/pkg/core/interfaces.go @@ -33,7 +33,7 @@ type DiffManager interface { // TestDiscoveryService services discovery of tests type TestDiscoveryService interface { // Discover executes the test discovery scripts. - Discover(ctx context.Context, tasConfig *TASConfig, payload *Payload, secretData map[string]string, diff map[string]int) error + Discover(ctx context.Context, tasConfig *TASConfig, payload *Payload, secretData map[string]string, diff map[string]int, diffExists bool) error } // TestBlockListService is used for fetching blocklisted tests diff --git a/pkg/core/lifecycle.go b/pkg/core/lifecycle.go index 2ac3a4a..05fc3aa 100644 --- a/pkg/core/lifecycle.go +++ b/pkg/core/lifecycle.go @@ -247,15 +247,20 @@ func (pl *Pipeline) Start(ctx context.Context) (err error) { } pl.Logger.Infof("Identifying changed files ...") + diffExists := true diff, err := pl.DiffManager.GetChangedFiles(ctx, payload, oauth.Data.AccessToken) if err != nil { - pl.Logger.Errorf("Unable to identify changed files %s", err) - errRemark = "Error occurred in fetching diff from GitHub" - return err + if errors.Is(err, errs.ErrGitDiffNotFound) { + diffExists = false + } else { + pl.Logger.Errorf("Unable to identify changed files %s", err) + errRemark = "Error occurred in fetching diff from GitHub" + return err + } } // discover test cases - err = pl.TestDiscoveryService.Discover(ctx, tasConfig, pl.Payload, secretMap, diff) + err = pl.TestDiscoveryService.Discover(ctx, tasConfig, pl.Payload, secretMap, diff, diffExists) if err != nil { pl.Logger.Errorf("Unable to perform test discovery: %+v", err) errRemark = "Error occurred in discovering tests" diff --git a/pkg/diffmanager/setup.go b/pkg/diffmanager/setup.go index 0dcfb23..2f8c6b0 100644 --- a/pkg/diffmanager/setup.go +++ b/pkg/diffmanager/setup.go @@ -212,10 +212,6 @@ func (dm *diffManager) GetChangedFiles(ctx context.Context, payload *core.Payloa } else { diff, err = dm.getCommitDiff(payload.GitProvider, payload.RepoLink, cloneToken, payload.BaseCommit, payload.TargetCommit) if err != nil { - if errors.Is(err, errs.ErrGitDiffNotFound) { - dm.logger.Debugf("failed to get commit diff for gitprovider: %s error: %v", payload.GitProvider, err) - return nil, nil - } dm.logger.Errorf("failed to get commit diff for gitprovider: %s error: %v", payload.GitProvider, err) return nil, err } diff --git a/pkg/testdiscoveryservice/testdiscovery.go b/pkg/testdiscoveryservice/testdiscovery.go index 1298416..c0443f3 100644 --- a/pkg/testdiscoveryservice/testdiscovery.go +++ b/pkg/testdiscoveryservice/testdiscovery.go @@ -27,7 +27,8 @@ func (tds *testDiscoveryService) Discover(ctx context.Context, tasConfig *core.TASConfig, payload *core.Payload, secretData map[string]string, - diff map[string]int) error { + diff map[string]int, + diffExists bool) error { var target []string var envMap map[string]string if payload.EventType == core.EventPullRequest { @@ -51,7 +52,7 @@ func (tds *testDiscoveryService) Discover(ctx context.Context, args := []string{"--command", "discover"} if !discoverAll { - if len(diff) == 0 { + if len(diff) == 0 && diffExists { // empty diff; in PR, a commit added and then reverted to cause an overall empty PR diff args = append(args, "--diff") } else {