From d7e3cedad14d402f01f82108c2183f6041af6b85 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Mon, 23 Aug 2021 16:14:55 +0200 Subject: [PATCH] Use correct ref when finding directories in repos --- internal/batches/service/service.go | 2 +- internal/batches/service/service_test.go | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/internal/batches/service/service.go b/internal/batches/service/service.go index 04ad873016..91babe2eef 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -648,7 +648,7 @@ func (svc *Service) FindDirectoriesInRepos(ctx context.Context, fileName string, a.WriteString("query DirectoriesContainingFile {\n") for _, repo := range batch { - query := fmt.Sprintf(`file:(^|/)%s$ repo:^%s$ type:path count:99999`, regexp.QuoteMeta(fileName), regexp.QuoteMeta(repo.Name)) + query := fmt.Sprintf(`file:(^|/)%s$ repo:^%s$@%s type:path count:99999`, regexp.QuoteMeta(fileName), repo.BaseRef(), regexp.QuoteMeta(repo.Name)) a.WriteString(fmt.Sprintf(searchQueryTmpl, queryIDByRepo[repo], query)) } diff --git a/internal/batches/service/service_test.go b/internal/batches/service/service_test.go index 8c6d08d3d6..5539a09815 100644 --- a/internal/batches/service/service_test.go +++ b/internal/batches/service/service_test.go @@ -327,8 +327,28 @@ func TestService_FindDirectoriesInRepos(t *testing.T) { fileName := "package.json" repos := []*graphql.Repository{ - {ID: "repo-id-0", Name: "github.com/sourcegraph/automation-testing", Branch: graphql.Branch{Name: "main"}}, - {ID: "repo-id-1", Name: "github.com/sourcegraph/sourcegraph", Branch: graphql.Branch{Name: "dev"}}, + { + ID: "repo-id-0", + Name: "github.com/sourcegraph/automation-testing", + Branch: graphql.Branch{Name: "dev"}, + DefaultBranch: &graphql.Branch{ + Name: "main", + Target: graphql.Target{ + OID: "d34db33f", + }, + }, + }, + { + ID: "repo-id-1", + Name: "github.com/sourcegraph/sourcegraph", + Branch: graphql.Branch{Name: "dev"}, + DefaultBranch: &graphql.Branch{ + Name: "main", + Target: graphql.Target{ + OID: "d34db33f", + }, + }, + }, } svc := &Service{client: client}