|
1 | 1 | package batches |
2 | 2 |
|
3 | | -import ( |
4 | | - "fmt" |
5 | | - "log" |
| 3 | +import "github.com/sourcegraph/src-cli/internal/features" |
6 | 4 |
|
7 | | - "github.com/sourcegraph/sourcegraph/lib/api" |
8 | | - "github.com/sourcegraph/sourcegraph/lib/errors" |
9 | | -) |
10 | | - |
11 | | -// FeatureFlags represent features that are only available on certain |
12 | | -// Sourcegraph versions and we therefore have to detect at runtime. |
13 | | -type FeatureFlags struct { |
14 | | - Sourcegraph40 bool |
15 | | - BinaryDiffs bool |
16 | | -} |
17 | | - |
18 | | -func (ff *FeatureFlags) SetFromVersion(version string, skipErrors bool) error { |
19 | | - for _, feature := range []struct { |
20 | | - flag *bool |
21 | | - constraint string |
22 | | - minDate string |
23 | | - }{ |
24 | | - // NOTE: It's necessary to include a "-0" prerelease suffix on each constraint so that |
25 | | - // prereleases of future versions are still considered to satisfy the constraint. |
26 | | - // |
27 | | - // For example, the version "3.35.1-rc.3" is not considered to satisfy the constraint |
28 | | - // ">= 3.23.0". However, the same version IS considered to satisfy the constraint |
29 | | - // "3.23.0-0". See |
30 | | - // https://github.com/Masterminds/semver#working-with-prerelease-versions for more. |
31 | | - // Example usage: |
32 | | - // {&ff.FlagName, ">= 3.23.0-0", "2020-11-24"}, |
33 | | - {&ff.Sourcegraph40, ">= 4.0.0-0", "2022-08-24"}, |
34 | | - {&ff.BinaryDiffs, ">= 4.3.0-0", "2022-11-29"}, |
35 | | - } { |
36 | | - value, err := api.CheckSourcegraphVersion(version, feature.constraint, feature.minDate) |
37 | | - if err != nil { |
38 | | - if skipErrors { |
39 | | - log.Printf("failed to check version returned by Sourcegraph: %s. Assuming no feature flags.", version) |
40 | | - } else { |
41 | | - return errors.Wrap(err, fmt.Sprintf("failed to check version returned by Sourcegraph: %s", version)) |
42 | | - } |
43 | | - } |
44 | | - *feature.flag = value |
45 | | - } |
46 | | - |
47 | | - return nil |
48 | | -} |
| 5 | +// FeatureFlags is an alias for features.FeatureFlags for backwards compatibility. |
| 6 | +type FeatureFlags = features.FeatureFlags |
0 commit comments