From 58667b5a4dce0f1a42cd040278f609f4a57c2a03 Mon Sep 17 00:00:00 2001 From: adeola Date: Thu, 26 Jan 2023 00:41:08 -0500 Subject: [PATCH 01/14] query max ulicensed changesets count --- DEVELOPMENT.md | 1 + cmd/src/batch_common.go | 4 ++-- cmd/src/batch_new.go | 2 +- cmd/src/batch_remote.go | 2 +- cmd/src/batch_repositories.go | 2 +- cmd/src/batch_validate.go | 2 +- internal/batches/license.go | 5 ++++ internal/batches/service/service.go | 36 ++++++++++++++++++++--------- internal/batches/ui/exec_ui.go | 2 +- internal/batches/ui/json_lines.go | 2 +- internal/batches/ui/tui.go | 10 ++++---- 11 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 internal/batches/license.go diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index bd8aa79ae3..3720bc11be 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -31,6 +31,7 @@ To help with that, you can compile your src binary (or run the tests) with the ` ``` go build -tags debug -o ~/src ./cmd/src ``` +//recompile changes and see logs. after saves This will cause the `./internal/batches/debug.go` file to be included in the build. In that file the `log` default package logger is setup to log to `~/.sourcegraph/src-cli.debug.log`. diff --git a/cmd/src/batch_common.go b/cmd/src/batch_common.go index 27b4ada60f..93f35298e0 100644 --- a/cmd/src/batch_common.go +++ b/cmd/src/batch_common.go @@ -290,7 +290,7 @@ func executeBatchSpec(ctx context.Context, opts executeBatchSpecOpts) (err error Client: opts.client, }) - ffs, err := svc.DetermineFeatureFlags(ctx) + lr, ffs, err := svc.DetermineFeatureFlagsAndLicense(ctx) if err != nil { return err } @@ -521,7 +521,7 @@ func executeBatchSpec(ctx context.Context, opts executeBatchSpecOpts) (err error execUI.CreatingBatchSpec() id, url, err := svc.CreateBatchSpec(ctx, namespace.ID, rawSpec, ids) if err != nil { - return execUI.CreatingBatchSpecError(err) + return execUI.CreatingBatchSpecError(lr.MaxUnlicensedChangesets, err) } previewURL := cfg.Endpoint + url execUI.CreatingBatchSpecSuccess(previewURL) diff --git a/cmd/src/batch_new.go b/cmd/src/batch_new.go index 75fe9a8891..d9663ae988 100644 --- a/cmd/src/batch_new.go +++ b/cmd/src/batch_new.go @@ -48,7 +48,7 @@ Examples: Client: cfg.apiClient(apiFlags, flagSet.Output()), }) - ffs, err := svc.DetermineFeatureFlags(ctx) + _, ffs, err := svc.DetermineFeatureFlagsAndLicense(ctx) if err != nil { return err } diff --git a/cmd/src/batch_remote.go b/cmd/src/batch_remote.go index dbdcf1c264..6b1ea1064e 100644 --- a/cmd/src/batch_remote.go +++ b/cmd/src/batch_remote.go @@ -52,7 +52,7 @@ Examples: Client: cfg.apiClient(flags.api, flagSet.Output()), }) - ffs, err := svc.DetermineFeatureFlags(ctx) + _, ffs, err := svc.DetermineFeatureFlagsAndLicense(ctx) if err != nil { return err } diff --git a/cmd/src/batch_repositories.go b/cmd/src/batch_repositories.go index f4b3280823..de5a593619 100644 --- a/cmd/src/batch_repositories.go +++ b/cmd/src/batch_repositories.go @@ -69,7 +69,7 @@ Examples: Client: client, }) - ffs, err := svc.DetermineFeatureFlags(ctx) + _, ffs, err := svc.DetermineFeatureFlagsAndLicense(ctx) if err != nil { return err } diff --git a/cmd/src/batch_validate.go b/cmd/src/batch_validate.go index b3268ea758..9344238549 100644 --- a/cmd/src/batch_validate.go +++ b/cmd/src/batch_validate.go @@ -63,7 +63,7 @@ Examples: Client: cfg.apiClient(apiFlags, flagSet.Output()), }) - ffs, err := svc.DetermineFeatureFlags(ctx) + _, ffs, err := svc.DetermineFeatureFlagsAndLicense(ctx) if err != nil { return err } diff --git a/internal/batches/license.go b/internal/batches/license.go new file mode 100644 index 0000000000..2a614ae719 --- /dev/null +++ b/internal/batches/license.go @@ -0,0 +1,5 @@ +package batches + +type LicenseRestrictions struct { + MaxUnlicensedChangesets int +} diff --git a/internal/batches/service/service.go b/internal/batches/service/service.go index 4231b945dd..1d12e7fcf2 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -43,10 +43,12 @@ 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 { + +const getInstanceInfo = `query SourcegraphVersion { site { productVersion } + maxUnlicensedChangesets batchChanges(first: 1) { nodes { id @@ -57,30 +59,41 @@ const sourcegraphVersionQuery = `query SourcegraphVersion { // getSourcegraphVersion queries the Sourcegraph GraphQL API to get the // current version of the Sourcegraph instance. -func (svc *Service) getSourcegraphVersion(ctx context.Context) (string, error) { + +func (svc *Service) getSourcegraphVersionAndMaxChangesetsCount(ctx context.Context) (string, int, error) { var result struct { - Site struct { + maxUnlicensedChangesets int + Site struct { ProductVersion string } } - ok, err := svc.client.NewQuery(sourcegraphVersionQuery).Do(ctx, &result) + ok, err := svc.client.NewQuery(getInstanceInfo).Do(ctx, &result) if err != nil || !ok { - return "", err + return "", 0, err } - return result.Site.ProductVersion, err + //add to return + return result.Site.ProductVersion, result.maxUnlicensedChangesets, err } -// DetermineFeatureFlags fetches the version of the configured Sourcegraph and +// DetermineFeatureFlagsAndLicense fetches the version of the configured Sourcegraph and // returns the enabled features. -func (svc *Service) DetermineFeatureFlags(ctx context.Context) (*batches.FeatureFlags, error) { - version, err := svc.getSourcegraphVersion(ctx) + +func (svc *Service) DetermineFeatureFlagsAndLicense(ctx context.Context) (*batches.LicenseRestrictions, *batches.FeatureFlags, error) { + version, mc, err := svc.getSourcegraphVersionAndMaxChangesetsCount(ctx) if err != nil { - return nil, errors.Wrap(err, "failed to query Sourcegraph version to check for available features") + return nil, nil, errors.Wrap(err, "failed to query Sourcegraph version and license info for instance capabilities") + } + + lr := &batches.LicenseRestrictions{ + MaxUnlicensedChangesets: mc, } + ffs := &batches.FeatureFlags{} - return ffs, ffs.SetFromVersion(version) + + return lr, ffs, ffs.SetFromVersion(version) + } const applyBatchChangeMutation = ` @@ -120,6 +133,7 @@ mutation CreateBatchSpec( ) { id applyURL + } } ` diff --git a/internal/batches/ui/exec_ui.go b/internal/batches/ui/exec_ui.go index e9944c17bc..2b385b67e7 100644 --- a/internal/batches/ui/exec_ui.go +++ b/internal/batches/ui/exec_ui.go @@ -40,7 +40,7 @@ type ExecUI interface { CreatingBatchSpec() CreatingBatchSpecSuccess(previewURL string) - CreatingBatchSpecError(err error) error + CreatingBatchSpecError(lr int, err error) error PreviewBatchSpec(previewURL string) diff --git a/internal/batches/ui/json_lines.go b/internal/batches/ui/json_lines.go index 45475b137e..8fb6c81cc3 100644 --- a/internal/batches/ui/json_lines.go +++ b/internal/batches/ui/json_lines.go @@ -149,7 +149,7 @@ func (ui *JSONLines) CreatingBatchSpecSuccess(batchSpecURL string) { }) } -func (ui *JSONLines) CreatingBatchSpecError(err error) error { +func (ui *JSONLines) CreatingBatchSpecError(lr int, err error) error { logOperationFailure(batcheslib.LogEventOperationCreatingBatchSpec, &batcheslib.CreatingBatchSpecMetadata{}) return err } diff --git a/internal/batches/ui/tui.go b/internal/batches/ui/tui.go index af49e98bde..00b082fd67 100644 --- a/internal/batches/ui/tui.go +++ b/internal/batches/ui/tui.go @@ -217,8 +217,8 @@ func (ui *TUI) CreatingBatchSpecSuccess(previewURL string) { batchCompletePending(ui.pending, "Creating batch spec on Sourcegraph") } -func (ui *TUI) CreatingBatchSpecError(err error) error { - return prettyPrintBatchUnlicensedError(ui.Out, err) +func (ui *TUI) CreatingBatchSpecError(lr int, err error) error { + return prettyPrintBatchUnlicensedError(ui.Out, lr, err) } func (ui *TUI) DockerWatchDogWarning(err error) { @@ -307,7 +307,7 @@ func (ui *TUI) RemoteSuccess(url string) { // is, then a better message is output. Regardless, the return value of this // function should be used to replace the original error passed in to ensure // that the displayed output is sensible. -func prettyPrintBatchUnlicensedError(out *output.Output, err error) error { +func prettyPrintBatchUnlicensedError(out *output.Output, lr int, err error) error { // Pull apart the error to see if it's a licensing error: if so, we should // display a friendlier and more actionable message than the usual GraphQL // error output. @@ -321,14 +321,14 @@ func prettyPrintBatchUnlicensedError(out *output.Output, err error) error { // verbose mode, but let the original error bubble up rather // than this one. out.Verbosef("Unexpected error parsing the GraphQL error: %v", cerr) - } else if code == "ErrBatchChangesUnlicensed" { + } else if code == "ErrBatchChangesUnlicensed" || code == "ErrBatchChangesOverLimit" { // OK, let's print a better message, then return an // exitCodeError to suppress the normal automatic error block. // Note that we have hand wrapped the output at 80 (printable) // characters: having automatic wrapping some day would be nice, // but this should be sufficient for now. block := out.Block(output.Line("🪙", output.StyleWarning, "Batch Changes is a paid feature of Sourcegraph. All users can create sample")) - block.WriteLine(output.Linef("", output.StyleWarning, "batch changes with up to 10 changesets without a license. Contact Sourcegraph")) + block.WriteLine(output.Linef("", output.StyleWarning, "batch changes with up to %s changesets without a license. Contact Sourcegraph", lr)) block.WriteLine(output.Linef("", output.StyleWarning, "sales at %shttps://about.sourcegraph.com/contact/sales/%s to obtain a trial", output.StyleSearchLink, output.StyleWarning)) block.WriteLine(output.Linef("", output.StyleWarning, "license.")) block.Write("") From 3330beeef879547e448dc0e5947ca7c62c76b324 Mon Sep 17 00:00:00 2001 From: adeola Date: Thu, 26 Jan 2023 01:00:33 -0500 Subject: [PATCH 02/14] remove comment --- DEVELOPMENT.md | 1 - internal/batches/ui/tui.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 3720bc11be..bd8aa79ae3 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -31,7 +31,6 @@ To help with that, you can compile your src binary (or run the tests) with the ` ``` go build -tags debug -o ~/src ./cmd/src ``` -//recompile changes and see logs. after saves This will cause the `./internal/batches/debug.go` file to be included in the build. In that file the `log` default package logger is setup to log to `~/.sourcegraph/src-cli.debug.log`. diff --git a/internal/batches/ui/tui.go b/internal/batches/ui/tui.go index 00b082fd67..45ffc1d58c 100644 --- a/internal/batches/ui/tui.go +++ b/internal/batches/ui/tui.go @@ -328,7 +328,7 @@ func prettyPrintBatchUnlicensedError(out *output.Output, lr int, err error) erro // characters: having automatic wrapping some day would be nice, // but this should be sufficient for now. block := out.Block(output.Line("🪙", output.StyleWarning, "Batch Changes is a paid feature of Sourcegraph. All users can create sample")) - block.WriteLine(output.Linef("", output.StyleWarning, "batch changes with up to %s changesets without a license. Contact Sourcegraph", lr)) + block.WriteLine(output.Linef("", output.StyleWarning, "batch changes with up to %s !!!!!changesets without a license. Contact Sourcegraph", lr)) block.WriteLine(output.Linef("", output.StyleWarning, "sales at %shttps://about.sourcegraph.com/contact/sales/%s to obtain a trial", output.StyleSearchLink, output.StyleWarning)) block.WriteLine(output.Linef("", output.StyleWarning, "license.")) block.Write("") From 7209cb7329e3c3f540503ee4ebff85b523fbc6ee Mon Sep 17 00:00:00 2001 From: adeola Date: Thu, 26 Jan 2023 01:02:46 -0500 Subject: [PATCH 03/14] remove text --- internal/batches/ui/tui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/batches/ui/tui.go b/internal/batches/ui/tui.go index 45ffc1d58c..00b082fd67 100644 --- a/internal/batches/ui/tui.go +++ b/internal/batches/ui/tui.go @@ -328,7 +328,7 @@ func prettyPrintBatchUnlicensedError(out *output.Output, lr int, err error) erro // characters: having automatic wrapping some day would be nice, // but this should be sufficient for now. block := out.Block(output.Line("🪙", output.StyleWarning, "Batch Changes is a paid feature of Sourcegraph. All users can create sample")) - block.WriteLine(output.Linef("", output.StyleWarning, "batch changes with up to %s !!!!!changesets without a license. Contact Sourcegraph", lr)) + block.WriteLine(output.Linef("", output.StyleWarning, "batch changes with up to %s changesets without a license. Contact Sourcegraph", lr)) block.WriteLine(output.Linef("", output.StyleWarning, "sales at %shttps://about.sourcegraph.com/contact/sales/%s to obtain a trial", output.StyleSearchLink, output.StyleWarning)) block.WriteLine(output.Linef("", output.StyleWarning, "license.")) block.Write("") From 861cbaf0b96b9f20c9cdef7a186d76f88e1b8566 Mon Sep 17 00:00:00 2001 From: adeola Date: Thu, 26 Jan 2023 01:09:38 -0500 Subject: [PATCH 04/14] insert integer more --- internal/batches/ui/tui.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/batches/ui/tui.go b/internal/batches/ui/tui.go index 00b082fd67..c5d72e762d 100644 --- a/internal/batches/ui/tui.go +++ b/internal/batches/ui/tui.go @@ -332,8 +332,8 @@ func prettyPrintBatchUnlicensedError(out *output.Output, lr int, err error) erro block.WriteLine(output.Linef("", output.StyleWarning, "sales at %shttps://about.sourcegraph.com/contact/sales/%s to obtain a trial", output.StyleSearchLink, output.StyleWarning)) block.WriteLine(output.Linef("", output.StyleWarning, "license.")) block.Write("") - block.WriteLine(output.Linef("", output.StyleWarning, "To proceed with this batch change, you will need to create 5 or fewer")) - block.WriteLine(output.Linef("", output.StyleWarning, "changesets. To do so, you could try adding %scount:5%s to your", output.StyleSearchAlertProposedQuery, output.StyleWarning)) + block.WriteLine(output.Linef("", output.StyleWarning, "To proceed with this batch change, you will need to create %s or fewer", lr)) + block.WriteLine(output.Linef("", output.StyleWarning, "changesets. To do so, you could try adding %scount:%s%s to your", output.StyleSearchAlertProposedQuery, lr, output.StyleWarning)) block.WriteLine(output.Linef("", output.StyleWarning, "%srepositoriesMatchingQuery%s search, or reduce the number of changesets in", output.StyleReset, output.StyleWarning)) block.WriteLine(output.Linef("", output.StyleWarning, "%simportChangesets%s.", output.StyleReset, output.StyleWarning)) block.Close() From 657729959321d8ae4b1b860642dab959c699fb78 Mon Sep 17 00:00:00 2001 From: adeola <67931373+adeola-ak@users.noreply.github.com> Date: Thu, 26 Jan 2023 09:38:07 -0500 Subject: [PATCH 05/14] Update internal/batches/service/service.go Co-authored-by: Kelli Rockwell --- 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 1d12e7fcf2..4560a6161d 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -48,7 +48,7 @@ const getInstanceInfo = `query SourcegraphVersion { site { productVersion } - maxUnlicensedChangesets + maxUnlicensedChangesets batchChanges(first: 1) { nodes { id From 925c26f58929f21ed86b0fc1f9a8ead3ddd93847 Mon Sep 17 00:00:00 2001 From: adeola <67931373+adeola-ak@users.noreply.github.com> Date: Thu, 26 Jan 2023 09:38:32 -0500 Subject: [PATCH 06/14] Update internal/batches/service/service.go Co-authored-by: Kelli Rockwell --- 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 4560a6161d..cb2b1f0ca5 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -44,7 +44,7 @@ func New(opts *Opts) *Service { // changes in an unsupported environment sooner, since the version check is typically the // first thing we do. -const getInstanceInfo = `query SourcegraphVersion { +const getInstanceInfo = `query InstanceInfo { site { productVersion } From 5bd17cf361620530efef7ad9ed049285f7bea829 Mon Sep 17 00:00:00 2001 From: adeola Date: Thu, 26 Jan 2023 09:52:17 -0500 Subject: [PATCH 07/14] fix variables --- internal/batches/service/service.go | 15 ++++++--------- internal/batches/ui/exec_ui.go | 2 +- internal/batches/ui/json_lines.go | 2 +- internal/batches/ui/tui.go | 12 ++++++------ 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/internal/batches/service/service.go b/internal/batches/service/service.go index cb2b1f0ca5..67acb4885c 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -57,12 +57,12 @@ const getInstanceInfo = `query InstanceInfo { } ` -// getSourcegraphVersion queries the Sourcegraph GraphQL API to get the -// current version of the Sourcegraph instance. +// getSourcegraphVersionAndMaxChangesetsCount queries the Sourcegraph GraphQL API to get the +// current version and max unlicensed changesets count for the Sourcegraph instance. func (svc *Service) getSourcegraphVersionAndMaxChangesetsCount(ctx context.Context) (string, int, error) { var result struct { - maxUnlicensedChangesets int + MaxUnlicensedChangesets int Site struct { ProductVersion string } @@ -73,12 +73,11 @@ func (svc *Service) getSourcegraphVersionAndMaxChangesetsCount(ctx context.Conte return "", 0, err } - //add to return - return result.Site.ProductVersion, result.maxUnlicensedChangesets, err + return result.Site.ProductVersion, result.MaxUnlicensedChangesets, err } -// DetermineFeatureFlagsAndLicense fetches the version of the configured Sourcegraph and -// returns the enabled features. +// DetermineFeatureFlagsAndLicense returns the enabled features and license restrictions +// configured for the Sourcegraph instance. func (svc *Service) DetermineFeatureFlagsAndLicense(ctx context.Context) (*batches.LicenseRestrictions, *batches.FeatureFlags, error) { version, mc, err := svc.getSourcegraphVersionAndMaxChangesetsCount(ctx) @@ -91,7 +90,6 @@ func (svc *Service) DetermineFeatureFlagsAndLicense(ctx context.Context) (*batch } ffs := &batches.FeatureFlags{} - return lr, ffs, ffs.SetFromVersion(version) } @@ -133,7 +131,6 @@ mutation CreateBatchSpec( ) { id applyURL - } } ` diff --git a/internal/batches/ui/exec_ui.go b/internal/batches/ui/exec_ui.go index 2b385b67e7..fd12b84173 100644 --- a/internal/batches/ui/exec_ui.go +++ b/internal/batches/ui/exec_ui.go @@ -40,7 +40,7 @@ type ExecUI interface { CreatingBatchSpec() CreatingBatchSpecSuccess(previewURL string) - CreatingBatchSpecError(lr int, err error) error + CreatingBatchSpecError(maxUnlicensedCS int, err error) error PreviewBatchSpec(previewURL string) diff --git a/internal/batches/ui/json_lines.go b/internal/batches/ui/json_lines.go index 8fb6c81cc3..f1761769d2 100644 --- a/internal/batches/ui/json_lines.go +++ b/internal/batches/ui/json_lines.go @@ -149,7 +149,7 @@ func (ui *JSONLines) CreatingBatchSpecSuccess(batchSpecURL string) { }) } -func (ui *JSONLines) CreatingBatchSpecError(lr int, err error) error { +func (ui *JSONLines) CreatingBatchSpecError(maxUnlicensedCS int, err error) error { logOperationFailure(batcheslib.LogEventOperationCreatingBatchSpec, &batcheslib.CreatingBatchSpecMetadata{}) return err } diff --git a/internal/batches/ui/tui.go b/internal/batches/ui/tui.go index c5d72e762d..ed2c5848de 100644 --- a/internal/batches/ui/tui.go +++ b/internal/batches/ui/tui.go @@ -217,8 +217,8 @@ func (ui *TUI) CreatingBatchSpecSuccess(previewURL string) { batchCompletePending(ui.pending, "Creating batch spec on Sourcegraph") } -func (ui *TUI) CreatingBatchSpecError(lr int, err error) error { - return prettyPrintBatchUnlicensedError(ui.Out, lr, err) +func (ui *TUI) CreatingBatchSpecError(maxUnlicensedCS int, err error) error { + return prettyPrintBatchUnlicensedError(ui.Out, maxUnlicensedCS, err) } func (ui *TUI) DockerWatchDogWarning(err error) { @@ -307,7 +307,7 @@ func (ui *TUI) RemoteSuccess(url string) { // is, then a better message is output. Regardless, the return value of this // function should be used to replace the original error passed in to ensure // that the displayed output is sensible. -func prettyPrintBatchUnlicensedError(out *output.Output, lr int, err error) error { +func prettyPrintBatchUnlicensedError(out *output.Output, maxUnlicensedCS int, err error) error { // Pull apart the error to see if it's a licensing error: if so, we should // display a friendlier and more actionable message than the usual GraphQL // error output. @@ -328,12 +328,12 @@ func prettyPrintBatchUnlicensedError(out *output.Output, lr int, err error) erro // characters: having automatic wrapping some day would be nice, // but this should be sufficient for now. block := out.Block(output.Line("🪙", output.StyleWarning, "Batch Changes is a paid feature of Sourcegraph. All users can create sample")) - block.WriteLine(output.Linef("", output.StyleWarning, "batch changes with up to %s changesets without a license. Contact Sourcegraph", lr)) + block.WriteLine(output.Linef("", output.StyleWarning, "batch changes with up to %s changesets without a license. Contact Sourcegraph", maxUnlicensedCS)) block.WriteLine(output.Linef("", output.StyleWarning, "sales at %shttps://about.sourcegraph.com/contact/sales/%s to obtain a trial", output.StyleSearchLink, output.StyleWarning)) block.WriteLine(output.Linef("", output.StyleWarning, "license.")) block.Write("") - block.WriteLine(output.Linef("", output.StyleWarning, "To proceed with this batch change, you will need to create %s or fewer", lr)) - block.WriteLine(output.Linef("", output.StyleWarning, "changesets. To do so, you could try adding %scount:%s%s to your", output.StyleSearchAlertProposedQuery, lr, output.StyleWarning)) + block.WriteLine(output.Linef("", output.StyleWarning, "To proceed with this batch change, you will need to create %s or fewer", maxUnlicensedCS)) + block.WriteLine(output.Linef("", output.StyleWarning, "changesets. To do so, you could try adding %scount:%s%s to your", output.StyleSearchAlertProposedQuery, maxUnlicensedCS, output.StyleWarning)) block.WriteLine(output.Linef("", output.StyleWarning, "%srepositoriesMatchingQuery%s search, or reduce the number of changesets in", output.StyleReset, output.StyleWarning)) block.WriteLine(output.Linef("", output.StyleWarning, "%simportChangesets%s.", output.StyleReset, output.StyleWarning)) block.Close() From 4dd1aae59496da08c1f75c6525b35531c3dde570 Mon Sep 17 00:00:00 2001 From: adeola Date: Thu, 26 Jan 2023 19:45:27 -0500 Subject: [PATCH 08/14] update verbs --- internal/batches/ui/tui.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/batches/ui/tui.go b/internal/batches/ui/tui.go index ed2c5848de..94724909b1 100644 --- a/internal/batches/ui/tui.go +++ b/internal/batches/ui/tui.go @@ -328,12 +328,12 @@ func prettyPrintBatchUnlicensedError(out *output.Output, maxUnlicensedCS int, er // characters: having automatic wrapping some day would be nice, // but this should be sufficient for now. block := out.Block(output.Line("🪙", output.StyleWarning, "Batch Changes is a paid feature of Sourcegraph. All users can create sample")) - block.WriteLine(output.Linef("", output.StyleWarning, "batch changes with up to %s changesets without a license. Contact Sourcegraph", maxUnlicensedCS)) + block.WriteLine(output.Linef("", output.StyleWarning, "batch changes with up to %v changesets without a license. Contact Sourcegraph", maxUnlicensedCS)) block.WriteLine(output.Linef("", output.StyleWarning, "sales at %shttps://about.sourcegraph.com/contact/sales/%s to obtain a trial", output.StyleSearchLink, output.StyleWarning)) block.WriteLine(output.Linef("", output.StyleWarning, "license.")) block.Write("") - block.WriteLine(output.Linef("", output.StyleWarning, "To proceed with this batch change, you will need to create %s or fewer", maxUnlicensedCS)) - block.WriteLine(output.Linef("", output.StyleWarning, "changesets. To do so, you could try adding %scount:%s%s to your", output.StyleSearchAlertProposedQuery, maxUnlicensedCS, output.StyleWarning)) + block.WriteLine(output.Linef("", output.StyleWarning, "To proceed with this batch change, you will need to create %v or fewer", maxUnlicensedCS)) + block.WriteLine(output.Linef("", output.StyleWarning, "changesets. To do so, you could try adding %scount:%v%s to your", output.StyleSearchAlertProposedQuery, maxUnlicensedCS, output.StyleWarning)) block.WriteLine(output.Linef("", output.StyleWarning, "%srepositoriesMatchingQuery%s search, or reduce the number of changesets in", output.StyleReset, output.StyleWarning)) block.WriteLine(output.Linef("", output.StyleWarning, "%simportChangesets%s.", output.StyleReset, output.StyleWarning)) block.Close() From c53411dc0244f79f1d3830962c9daa1401742330 Mon Sep 17 00:00:00 2001 From: adeola <67931373+adeola-ak@users.noreply.github.com> Date: Fri, 27 Jan 2023 09:08:58 -0500 Subject: [PATCH 09/14] Update internal/batches/service/service.go Co-authored-by: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com> --- 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 67acb4885c..a0abfb6ed9 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -82,7 +82,7 @@ func (svc *Service) getSourcegraphVersionAndMaxChangesetsCount(ctx context.Conte func (svc *Service) DetermineFeatureFlagsAndLicense(ctx context.Context) (*batches.LicenseRestrictions, *batches.FeatureFlags, error) { version, mc, err := svc.getSourcegraphVersionAndMaxChangesetsCount(ctx) if err != nil { - return nil, nil, errors.Wrap(err, "failed to query Sourcegraph version and license info for instance capabilities") + return nil, nil, errors.Wrap(err, "failed to query Sourcegraph version and license info for instance") } lr := &batches.LicenseRestrictions{ From 2d6ea98c4d692515345789004c81f9d7150045eb Mon Sep 17 00:00:00 2001 From: adeola <67931373+adeola-ak@users.noreply.github.com> Date: Fri, 27 Jan 2023 09:09:06 -0500 Subject: [PATCH 10/14] Update internal/batches/ui/json_lines.go Co-authored-by: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com> --- internal/batches/ui/json_lines.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/batches/ui/json_lines.go b/internal/batches/ui/json_lines.go index f1761769d2..36ae989570 100644 --- a/internal/batches/ui/json_lines.go +++ b/internal/batches/ui/json_lines.go @@ -149,7 +149,7 @@ func (ui *JSONLines) CreatingBatchSpecSuccess(batchSpecURL string) { }) } -func (ui *JSONLines) CreatingBatchSpecError(maxUnlicensedCS int, err error) error { +func (ui *JSONLines) CreatingBatchSpecError(_ int, err error) error { logOperationFailure(batcheslib.LogEventOperationCreatingBatchSpec, &batcheslib.CreatingBatchSpecMetadata{}) return err } From 839e00128f2e452388433f13609d5777d01beed7 Mon Sep 17 00:00:00 2001 From: adeola <67931373+adeola-ak@users.noreply.github.com> Date: Sun, 29 Jan 2023 02:29:43 -0500 Subject: [PATCH 11/14] Update internal/batches/service/service.go Co-authored-by: Kelli Rockwell --- internal/batches/service/service.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/batches/service/service.go b/internal/batches/service/service.go index a0abfb6ed9..3c06f204c6 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -78,7 +78,6 @@ func (svc *Service) getSourcegraphVersionAndMaxChangesetsCount(ctx context.Conte // DetermineFeatureFlagsAndLicense returns the enabled features and license restrictions // configured for the Sourcegraph instance. - func (svc *Service) DetermineFeatureFlagsAndLicense(ctx context.Context) (*batches.LicenseRestrictions, *batches.FeatureFlags, error) { version, mc, err := svc.getSourcegraphVersionAndMaxChangesetsCount(ctx) if err != nil { From 3700c63571158b6ed6a718335deed4842f47c13e Mon Sep 17 00:00:00 2001 From: adeola <67931373+adeola-ak@users.noreply.github.com> Date: Sun, 29 Jan 2023 02:29:49 -0500 Subject: [PATCH 12/14] Update internal/batches/service/service.go Co-authored-by: Kelli Rockwell --- internal/batches/service/service.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/batches/service/service.go b/internal/batches/service/service.go index 3c06f204c6..833cf738e8 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -59,7 +59,6 @@ const getInstanceInfo = `query InstanceInfo { // getSourcegraphVersionAndMaxChangesetsCount queries the Sourcegraph GraphQL API to get the // current version and max unlicensed changesets count for the Sourcegraph instance. - func (svc *Service) getSourcegraphVersionAndMaxChangesetsCount(ctx context.Context) (string, int, error) { var result struct { MaxUnlicensedChangesets int From a23ac3fa604975557512b6fbec77eb9edad9b199 Mon Sep 17 00:00:00 2001 From: adeola <67931373+adeola-ak@users.noreply.github.com> Date: Sun, 29 Jan 2023 02:29:57 -0500 Subject: [PATCH 13/14] Update internal/batches/service/service.go Co-authored-by: Kelli Rockwell --- internal/batches/service/service.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/batches/service/service.go b/internal/batches/service/service.go index 833cf738e8..28ff25b669 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -43,7 +43,6 @@ 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 getInstanceInfo = `query InstanceInfo { site { productVersion From a601a9b0a79048a81c0b2204ab8c898db062a627 Mon Sep 17 00:00:00 2001 From: adeola Date: Sun, 29 Jan 2023 02:39:48 -0500 Subject: [PATCH 14/14] rename DetermineFeatureFlagsAndLicense --- cmd/src/batch_common.go | 2 +- cmd/src/batch_new.go | 2 +- cmd/src/batch_remote.go | 2 +- cmd/src/batch_repositories.go | 2 +- cmd/src/batch_validate.go | 2 +- internal/batches/service/service.go | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/src/batch_common.go b/cmd/src/batch_common.go index 93f35298e0..e16aa38fcb 100644 --- a/cmd/src/batch_common.go +++ b/cmd/src/batch_common.go @@ -290,7 +290,7 @@ func executeBatchSpec(ctx context.Context, opts executeBatchSpecOpts) (err error Client: opts.client, }) - lr, ffs, err := svc.DetermineFeatureFlagsAndLicense(ctx) + lr, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx) if err != nil { return err } diff --git a/cmd/src/batch_new.go b/cmd/src/batch_new.go index d9663ae988..349b590eff 100644 --- a/cmd/src/batch_new.go +++ b/cmd/src/batch_new.go @@ -48,7 +48,7 @@ Examples: Client: cfg.apiClient(apiFlags, flagSet.Output()), }) - _, ffs, err := svc.DetermineFeatureFlagsAndLicense(ctx) + _, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx) if err != nil { return err } diff --git a/cmd/src/batch_remote.go b/cmd/src/batch_remote.go index 6b1ea1064e..7817421ab3 100644 --- a/cmd/src/batch_remote.go +++ b/cmd/src/batch_remote.go @@ -52,7 +52,7 @@ Examples: Client: cfg.apiClient(flags.api, flagSet.Output()), }) - _, ffs, err := svc.DetermineFeatureFlagsAndLicense(ctx) + _, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx) if err != nil { return err } diff --git a/cmd/src/batch_repositories.go b/cmd/src/batch_repositories.go index de5a593619..092ae637d2 100644 --- a/cmd/src/batch_repositories.go +++ b/cmd/src/batch_repositories.go @@ -69,7 +69,7 @@ Examples: Client: client, }) - _, ffs, err := svc.DetermineFeatureFlagsAndLicense(ctx) + _, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx) if err != nil { return err } diff --git a/cmd/src/batch_validate.go b/cmd/src/batch_validate.go index 9344238549..e2c77c29bc 100644 --- a/cmd/src/batch_validate.go +++ b/cmd/src/batch_validate.go @@ -63,7 +63,7 @@ Examples: Client: cfg.apiClient(apiFlags, flagSet.Output()), }) - _, ffs, err := svc.DetermineFeatureFlagsAndLicense(ctx) + _, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx) if err != nil { return err } diff --git a/internal/batches/service/service.go b/internal/batches/service/service.go index 28ff25b669..99d49a9c21 100644 --- a/internal/batches/service/service.go +++ b/internal/batches/service/service.go @@ -74,9 +74,9 @@ func (svc *Service) getSourcegraphVersionAndMaxChangesetsCount(ctx context.Conte return result.Site.ProductVersion, result.MaxUnlicensedChangesets, err } -// DetermineFeatureFlagsAndLicense returns the enabled features and license restrictions +// DetermineLicenseAndFeatureFlags returns the enabled features and license restrictions // configured for the Sourcegraph instance. -func (svc *Service) DetermineFeatureFlagsAndLicense(ctx context.Context) (*batches.LicenseRestrictions, *batches.FeatureFlags, error) { +func (svc *Service) DetermineLicenseAndFeatureFlags(ctx context.Context) (*batches.LicenseRestrictions, *batches.FeatureFlags, error) { version, mc, err := svc.getSourcegraphVersionAndMaxChangesetsCount(ctx) if err != nil { return nil, nil, errors.Wrap(err, "failed to query Sourcegraph version and license info for instance")