From 6215a99028e61a257502631e020be5ef9e3592c2 Mon Sep 17 00:00:00 2001 From: courier-new Date: Mon, 31 Jan 2022 18:19:14 -0800 Subject: [PATCH 1/6] Ask for a batch changes feature with version request to validate environment supports BC --- internal/batches/service/service.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/batches/service/service.go b/internal/batches/service/service.go index 49c9adba91..fe26b72a69 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -56,7 +56,12 @@ const sourcegraphVersionQuery = `query SourcegraphVersion { site { productVersion } + batchChanges(first: 1) { + nodes { + id + } } +} ` // getSourcegraphVersion queries the Sourcegraph GraphQL API to get the From a69618916dd5f6936dcb4e360f349c6ca8432c86 Mon Sep 17 00:00:00 2001 From: courier-new Date: Mon, 31 Jan 2022 18:19:22 -0800 Subject: [PATCH 2/6] Use a slightly more reasonable default count --- internal/batches/service/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/batches/service/service.go b/internal/batches/service/service.go index fe26b72a69..48b4badf8b 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -760,7 +760,7 @@ func (svc *Service) FindDirectoriesInRepos(ctx context.Context, fileName string, var defaultQueryCountRegex = regexp.MustCompile(`\bcount:(\d+|all)\b`) -const hardCodedCount = " count:999999" +const hardCodedCount = " count:99999" func setDefaultQueryCount(query string) string { if defaultQueryCountRegex.MatchString(query) { From ab3615b75940be4b64a592aed475ffae7b82a0e4 Mon Sep 17 00:00:00 2001 From: courier-new Date: Mon, 31 Jan 2022 22:30:03 -0800 Subject: [PATCH 3/6] Add comment --- internal/batches/service/service.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/batches/service/service.go b/internal/batches/service/service.go index 48b4badf8b..162365ea5a 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -52,6 +52,9 @@ func New(opts *Opts) *Service { } } +// The reason we ask for batchChanges here is to surface errors about trying to use batch +// changes in an unsupported environment sooner, since the version check is typically the +// first thing we do. const sourcegraphVersionQuery = `query SourcegraphVersion { site { productVersion From 836a42cd40e6d7d622b62b02a887766c118f2e80 Mon Sep 17 00:00:00 2001 From: courier-new Date: Tue, 1 Feb 2022 17:48:20 -0800 Subject: [PATCH 4/6] =?UTF-8?q?Use=20consistent=20query=20spaces=20?= =?UTF-8?q?=F0=9F=98=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/batches/service/service.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/batches/service/service.go b/internal/batches/service/service.go index 162365ea5a..79dcb2474d 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -57,15 +57,15 @@ func New(opts *Opts) *Service { // first thing we do. const sourcegraphVersionQuery = `query SourcegraphVersion { site { - productVersion + productVersion } batchChanges(first: 1) { - nodes { - id - } - } + nodes { + id + } + } } - ` +` // getSourcegraphVersion queries the Sourcegraph GraphQL API to get the // current version of the Sourcegraph instance. From 9972dc37641ac37d08cead363f80fc3478b029b8 Mon Sep 17 00:00:00 2001 From: courier-new Date: Tue, 1 Feb 2022 18:02:47 -0800 Subject: [PATCH 5/6] Add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dcbf6c1ef..5a211eebed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ All notable changes to `src-cli` are documented in this file. ### Fixed +- `src batch [preview|apply]` will now check that the target Sourcegraph instance supports batch changes before doing any other work and exit early in the case that it does not. + ### Removed ## 3.36.2 From a47202bece1b2e84790680e7af1ec2b910a798d6 Mon Sep 17 00:00:00 2001 From: courier-new Date: Wed, 2 Feb 2022 18:26:40 -0800 Subject: [PATCH 6/6] Restore original count --- internal/batches/service/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/batches/service/service.go b/internal/batches/service/service.go index 79dcb2474d..057b25da4f 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -763,7 +763,7 @@ func (svc *Service) FindDirectoriesInRepos(ctx context.Context, fileName string, var defaultQueryCountRegex = regexp.MustCompile(`\bcount:(\d+|all)\b`) -const hardCodedCount = " count:99999" +const hardCodedCount = " count:999999" func setDefaultQueryCount(query string) string { if defaultQueryCountRegex.MatchString(query) {