Skip to content

Commit

Permalink
Allow deprecation without Sunset (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenharrison authored Jun 18, 2024
1 parent b8f74b5 commit 498be3a
Show file tree
Hide file tree
Showing 38 changed files with 916 additions and 471 deletions.
38 changes: 38 additions & 0 deletions checker/changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,41 @@ func TestChanges_Count(t *testing.T) {
require.Equal(t, 0, lc[checker.WARN])
require.Equal(t, 1, lc[checker.ERR])
}

func TestIsEmpty_EmptyIncludeWarns(t *testing.T) {
bcErrors := checker.Changes{}
require.False(t, bcErrors.HasLevelOrHigher(checker.WARN))
}

func TestIsEmpty_EmptyExcludeWarns(t *testing.T) {
bcErrors := checker.Changes{}
require.False(t, bcErrors.HasLevelOrHigher(checker.ERR))
}

func TestIsEmpty_OneErrIncludeWarns(t *testing.T) {
bcErrors := checker.Changes{
checker.ApiChange{Level: checker.ERR},
}
require.True(t, bcErrors.HasLevelOrHigher(checker.WARN))
}

func TestIsEmpty_OneErrExcludeWarns(t *testing.T) {
bcErrors := checker.Changes{
checker.ApiChange{Level: checker.ERR},
}
require.True(t, bcErrors.HasLevelOrHigher(checker.ERR))
}

func TestIsEmpty_OneWarnIncludeWarns(t *testing.T) {
bcErrors := checker.Changes{
checker.ApiChange{Level: checker.WARN},
}
require.True(t, bcErrors.HasLevelOrHigher(checker.WARN))
}

func TestIsEmpty_OneWarnExcludeWarns(t *testing.T) {
bcErrors := checker.Changes{
checker.ApiChange{Level: checker.WARN},
}
require.False(t, bcErrors.HasLevelOrHigher(checker.ERR))
}
44 changes: 23 additions & 21 deletions checker/check_api_deprecation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
)

const (
EndpointReactivatedId = "endpoint-reactivated"
APIDeprecatedSunsetParseId = "api-deprecated-sunset-parse"
ParseErrorId = "parsing-error"
APISunsetDateTooSmallId = "api-sunset-date-too-small"
EndpointDeprecatedId = "endpoint-deprecated"
EndpointReactivatedId = "endpoint-reactivated"
APIDeprecatedSunsetParseId = "api-deprecated-sunset-parse"
APIDeprecatedSunsetMissingId = "api-deprecated-sunset-missing"
APIInvalidStabilityLevelId = "api-invalid-stability-level"
APISunsetDateTooSmallId = "api-sunset-date-too-small"
EndpointDeprecatedId = "endpoint-deprecated"
)

func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config *Config) Changes {
Expand Down Expand Up @@ -47,28 +48,29 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio
continue
}

rawDate, date, err := getSunsetDate(op.Extensions)
stability, err := getStabilityLevel(op.Extensions)
if err != nil {
result = append(result, ApiChange{
Id: APIDeprecatedSunsetParseId,
Level: ERR,
Args: []any{rawDate, err},
Operation: operation,
OperationId: op.OperationID,
Path: path,
Source: load.NewSource(source),
})
// handled in CheckBackwardCompatibility
continue
}

days := date.DaysSince(civil.DateOf(time.Now()))
deprecationDays := getDeprecationDays(config, stability)

stability, err := getStabilityLevel(op.Extensions)
sunset, ok := getSunset(op.Extensions)
if !ok {
// if deprecation policy is defined and sunset is missing, it's a breaking change
if deprecationDays > 0 {
result = append(result, getAPIDeprecatedSunsetMissing(op, operationsSources, path, operation))
}
continue
}

date, err := getSunsetDate(sunset)
if err != nil {
result = append(result, ApiChange{
Id: ParseErrorId,
Id: APIDeprecatedSunsetParseId,
Level: ERR,
Args: []any{err.Error()},
Args: []any{err},
Operation: operation,
OperationId: op.OperationID,
Path: path,
Expand All @@ -77,9 +79,9 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio
continue
}

deprecationDays := getDeprecationDays(config, stability)
days := date.DaysSince(civil.DateOf(time.Now()))

if days < deprecationDays {
if days < int(deprecationDays) {
result = append(result, ApiChange{
Id: APISunsetDateTooSmallId,
Level: ERR,
Expand Down
Loading

0 comments on commit 498be3a

Please sign in to comment.