Skip to content

Commit fc3fa34

Browse files
committed
Remove old feature gates from pre-4.0
1 parent 486b235 commit fc3fa34

File tree

18 files changed

+94
-360
lines changed

18 files changed

+94
-360
lines changed

cmd/src/batch_common.go

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -177,37 +177,17 @@ func batchDefaultCacheDir() string {
177177
if err != nil {
178178
return ""
179179
}
180-
181-
// Check if there's an old campaigns cache directory but not a new batch
182-
// directory: if so, we should rename the old directory and carry on.
183-
//
184-
// TODO(campaigns-deprecation): we can remove this migration shim after June
185-
// 2021.
186-
old := path.Join(uc, "sourcegraph", "campaigns")
187180
dir := path.Join(uc, "sourcegraph", "batch")
188-
if _, err := os.Stat(dir); os.IsNotExist(err) {
189-
if _, err := os.Stat(old); os.IsExist(err) {
190-
// We'll just try to do this without checking for an error: if it
191-
// fails, we'll carry on and let the normal cache directory handling
192-
// logic take care of it.
193-
os.Rename(old, dir)
194-
}
195-
}
196181

197182
return dir
198183
}
199184

200185
// batchDefaultTempDirPrefix returns the prefix to be passed to ioutil.TempFile.
201-
// If one of the environment variables SRC_BATCH_TMP_DIR or
202-
// SRC_CAMPAIGNS_TMP_DIR is set, that is used as the prefix. Otherwise we use
203-
// "/tmp".
186+
// If the environment variable SRC_BATCH_TMP_DIR is set, that is used as the prefix.
187+
// Otherwise we use "/tmp".
204188
func batchDefaultTempDirPrefix() string {
205-
// TODO(campaigns-deprecation): we can remove this migration shim in
206-
// Sourcegraph 4.0.
207-
for _, env := range []string{"SRC_BATCH_TMP_DIR", "SRC_CAMPAIGNS_TMP_DIR"} {
208-
if p := os.Getenv(env); p != "" {
209-
return p
210-
}
189+
if p := os.Getenv("SRC_BATCH_TMP_DIR"); p != "" {
190+
return p
211191
}
212192

213193
// On macOS, we use an explicit prefix for our temp directories, because
@@ -280,7 +260,7 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp
280260

281261
imageCache := docker.NewImageCache()
282262

283-
if err := svc.DetermineFeatureFlags(ctx); err != nil {
263+
if err := validateSourcegraphVersionConstraint(ctx, svc); err != nil {
284264
return err
285265
}
286266

@@ -399,7 +379,6 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp
399379
GlobalEnv: os.Environ(),
400380
IsRemote: false,
401381
},
402-
Features: svc.Features(),
403382
Logger: logManager,
404383
Cache: executor.NewDiskCache(opts.flags.cacheDir),
405384
GlobalEnv: os.Environ(),
@@ -604,3 +583,14 @@ func getBatchParallelism(ctx context.Context, flag int) (int, error) {
604583

605584
return docker.NCPU(ctx)
606585
}
586+
587+
func validateSourcegraphVersionConstraint(ctx context.Context, svc *service.Service) error {
588+
ffs, err := svc.DetermineFeatureFlags(ctx)
589+
if err != nil {
590+
return err
591+
}
592+
if ffs.Sourcegraph40 {
593+
return nil
594+
}
595+
return errors.Newf("\n\n * Warning:\n This version of src-cli requires Sourcegraph version 4.0 or newer. If you're not on Sourcegraph 4.0 or newer, please use any 3.x release of src-cli.\n\n")
596+
}

cmd/src/batch_new.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Examples:
4848
Client: cfg.apiClient(apiFlags, flagSet.Output()),
4949
})
5050

51-
if err := svc.DetermineFeatureFlags(ctx); err != nil {
51+
if err := validateSourcegraphVersionConstraint(ctx, svc); err != nil {
5252
return err
5353
}
5454

cmd/src/batch_remote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Examples:
5252
Client: cfg.apiClient(flags.api, flagSet.Output()),
5353
})
5454

55-
if err := svc.DetermineFeatureFlags(ctx); err != nil {
55+
if err := validateSourcegraphVersionConstraint(ctx, svc); err != nil {
5656
return err
5757
}
5858

cmd/src/batch_repositories.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Examples:
6464
Client: client,
6565
})
6666

67-
if err := svc.DetermineFeatureFlags(ctx); err != nil {
67+
if err := validateSourcegraphVersionConstraint(ctx, svc); err != nil {
6868
return err
6969
}
7070

cmd/src/batch_validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Examples:
6363
Client: cfg.apiClient(apiFlags, flagSet.Output()),
6464
})
6565

66-
if err := svc.DetermineFeatureFlags(ctx); err != nil {
66+
if err := validateSourcegraphVersionConstraint(ctx, svc); err != nil {
6767
ui.ExecutionError(err)
6868
return err
6969
}

internal/api/api.go

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
ioaux "github.com/jig/teereadcloser"
1717
"github.com/kballard/go-shellquote"
1818
"github.com/mattn/go-isatty"
19+
1920
"github.com/sourcegraph/src-cli/internal/version"
2021
)
2122

@@ -25,16 +26,9 @@ type Client interface {
2526
// variables.
2627
NewQuery(query string) Request
2728

28-
// NewRequest creates a GraphQL request.
29+
// NewRequest creates a GraphQL request with gzip compression turned on.
2930
NewRequest(query string, vars map[string]interface{}) Request
3031

31-
// NewGzippedRequest creates a GraphQL request with gzip compression turned on.
32-
NewGzippedRequest(query string, vars map[string]interface{}) Request
33-
34-
// NewGzippedQuery is a convenience wrapper around NewQuery with gzip
35-
// compression turned on.
36-
NewGzippedQuery(query string) Request
37-
3832
// NewHTTPRequest creates an http.Request for the Sourcegraph API.
3933
//
4034
// path is joined against the API route. For example on Sourcegraph.com this
@@ -72,7 +66,6 @@ type request struct {
7266
client *client
7367
query string
7468
vars map[string]interface{}
75-
gzip bool
7669
}
7770

7871
// ClientOpts encapsulates the options given to NewClient.
@@ -132,19 +125,6 @@ func (c *client) NewRequest(query string, vars map[string]interface{}) Request {
132125
}
133126
}
134127

135-
func (c *client) NewGzippedRequest(query string, vars map[string]interface{}) Request {
136-
return &request{
137-
client: c,
138-
query: query,
139-
vars: vars,
140-
gzip: true,
141-
}
142-
}
143-
144-
func (c *client) NewGzippedQuery(query string) Request {
145-
return c.NewGzippedRequest(query, nil)
146-
}
147-
148128
func (c *client) Do(req *http.Request) (*http.Response, error) {
149129
return c.httpClient.Do(req)
150130
}
@@ -216,19 +196,16 @@ func (r *request) do(ctx context.Context, result interface{}) (bool, error) {
216196
}
217197

218198
var bufBody io.Reader = bytes.NewBuffer(reqBody)
219-
if r.gzip {
220-
bufBody = gzipReader(bufBody)
221-
}
199+
bufBody = gzipReader(bufBody)
222200

223201
// Create the HTTP request.
224202
req, err := r.client.NewHTTPRequest(ctx, "POST", ".api/graphql", bufBody)
225203
if err != nil {
226204
return false, err
227205
}
228206

229-
if r.gzip {
230-
req.Header.Set("Content-Encoding", "gzip")
231-
}
207+
// Use gzip compression.
208+
req.Header.Set("Content-Encoding", "gzip")
232209

233210
// Perform the request.
234211
resp, err := r.client.httpClient.Do(req)

internal/batches/executor/coordinator.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/sourcegraph/sourcegraph/lib/batches/execution"
1010
"github.com/sourcegraph/sourcegraph/lib/batches/execution/cache"
1111

12-
"github.com/sourcegraph/src-cli/internal/batches"
1312
"github.com/sourcegraph/src-cli/internal/batches/log"
1413
)
1514

@@ -34,8 +33,6 @@ type NewCoordinatorOpts struct {
3433
Logger log.LogManager
3534
GlobalEnv []string
3635

37-
// Used by batcheslib.BuildChangesetSpecs
38-
Features batches.FeatureFlags
3936
IsRemote bool
4037
}
4138

@@ -124,10 +121,7 @@ func (c Coordinator) buildChangesetSpecs(task *Task, batchSpec *batcheslib.Batch
124121
},
125122
}
126123

127-
return batcheslib.BuildChangesetSpecs(input, batcheslib.ChangesetSpecFeatureFlags{
128-
IncludeAutoAuthorDetails: c.opts.Features.IncludeAutoAuthorDetails,
129-
AllowOptionalPublished: c.opts.Features.AllowOptionalPublished,
130-
})
124+
return batcheslib.BuildChangesetSpecs(input)
131125
}
132126

133127
func (c *Coordinator) loadCachedStepResults(ctx context.Context, task *Task, globalEnv []string) error {

internal/batches/executor/coordinator_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestCoordinator_Execute(t *testing.T) {
8282
{task: sourcegraphTask, stepResults: []execution.AfterStepResult{{Diff: `dummydiff2`}}},
8383
},
8484
},
85-
opts: NewCoordinatorOpts{Features: featuresAllEnabled()},
85+
opts: NewCoordinatorOpts{},
8686

8787
wantCacheEntries: 2,
8888
wantSpecs: []*batcheslib.ChangesetSpec{
@@ -150,7 +150,7 @@ func TestCoordinator_Execute(t *testing.T) {
150150
},
151151
},
152152
},
153-
opts: NewCoordinatorOpts{Features: featuresAllEnabled()},
153+
opts: NewCoordinatorOpts{},
154154

155155
wantCacheEntries: 1,
156156
wantSpecs: []*batcheslib.ChangesetSpec{
@@ -201,7 +201,7 @@ func TestCoordinator_Execute(t *testing.T) {
201201
{task: sourcegraphTask, stepResults: []execution.AfterStepResult{{Diff: nestedChangesDiff}}},
202202
},
203203
},
204-
opts: NewCoordinatorOpts{Features: featuresAllEnabled()},
204+
opts: NewCoordinatorOpts{},
205205

206206
// TODO: Fix comment.
207207
// We have 4 ChangesetSpecs, but we only want 2 cache entries,
@@ -249,7 +249,7 @@ func TestCoordinator_Execute(t *testing.T) {
249249
{task: sourcegraphTask, stepResults: []execution.AfterStepResult{{Diff: `dummydiff2`, StepIndex: 0}}},
250250
},
251251
},
252-
opts: NewCoordinatorOpts{Features: featuresAllEnabled()},
252+
opts: NewCoordinatorOpts{},
253253

254254
wantCacheEntries: 2,
255255
wantSpecs: []*batcheslib.ChangesetSpec{

internal/batches/executor/executor_test.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/sourcegraph/sourcegraph/lib/batches/template"
2626

2727
"github.com/sourcegraph/src-cli/internal/api"
28-
"github.com/sourcegraph/src-cli/internal/batches"
2928
"github.com/sourcegraph/src-cli/internal/batches/docker"
3029
"github.com/sourcegraph/src-cli/internal/batches/mock"
3130
"github.com/sourcegraph/src-cli/internal/batches/repozip"
@@ -510,18 +509,6 @@ func addToPath(t *testing.T, relPath string) {
510509
os.Setenv("PATH", fmt.Sprintf("%s%c%s", dummyDockerPath, os.PathListSeparator, os.Getenv("PATH")))
511510
}
512511

513-
func featuresAllEnabled() batches.FeatureFlags {
514-
return batches.FeatureFlags{
515-
AllowArrayEnvironments: true,
516-
IncludeAutoAuthorDetails: true,
517-
UseGzipCompression: true,
518-
AllowTransformChanges: true,
519-
AllowWorkspaces: true,
520-
AllowConditionalExec: true,
521-
AllowOptionalPublished: true,
522-
}
523-
}
524-
525512
func TestExecutor_CachedStepResults(t *testing.T) {
526513
t.Run("single step cached", func(t *testing.T) {
527514
archive := mock.RepoArchive{

internal/batches/features.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,7 @@ import (
99
// FeatureFlags represent features that are only available on certain
1010
// Sourcegraph versions and we therefore have to detect at runtime.
1111
type FeatureFlags struct {
12-
AllowArrayEnvironments bool
13-
IncludeAutoAuthorDetails bool
14-
UseGzipCompression bool
15-
AllowTransformChanges bool
16-
AllowWorkspaces bool
17-
BatchChanges bool
18-
AllowConditionalExec bool
19-
AllowOptionalPublished bool
20-
ServerSideBatchChanges bool
21-
BitbucketCloud bool
12+
Sourcegraph40 bool
2213
}
2314

2415
func (ff *FeatureFlags) SetFromVersion(version string) error {
@@ -34,16 +25,9 @@ func (ff *FeatureFlags) SetFromVersion(version string) error {
3425
// ">= 3.23.0". However, the same version IS considered to satisfy the constraint
3526
// "3.23.0-0". See
3627
// https://github.com/Masterminds/semver#working-with-prerelease-versions for more.
37-
{&ff.AllowArrayEnvironments, ">= 3.23.0-0", "2020-11-24"},
38-
{&ff.IncludeAutoAuthorDetails, ">= 3.20.0-0", "2020-09-10"},
39-
{&ff.UseGzipCompression, ">= 3.21.0-0", "2020-10-12"},
40-
{&ff.AllowTransformChanges, ">= 3.23.0-0", "2020-12-11"},
41-
{&ff.AllowWorkspaces, ">= 3.25.0-0", "2021-01-29"},
42-
{&ff.BatchChanges, ">= 3.26.0-0", "2021-03-07"},
43-
{&ff.AllowConditionalExec, ">= 3.28.0-0", "2021-05-05"},
44-
{&ff.AllowOptionalPublished, ">= 3.30.0-0", "2021-06-21"},
45-
{&ff.ServerSideBatchChanges, ">= 3.37.0-0", "2022-02-08"},
46-
{&ff.BitbucketCloud, ">= 3.40.0-0", "2022-04-20"},
28+
// Example usage:
29+
// {&ff.FlagName, ">= 3.23.0-0", "2020-11-24"},
30+
{&ff.Sourcegraph40, ">= 4.0.0-0", "2022-08-17"},
4731
} {
4832
value, err := api.CheckSourcegraphVersion(version, feature.constraint, feature.minDate)
4933
if err != nil {

0 commit comments

Comments
 (0)