Skip to content

Commit

Permalink
Merge pull request #381 from snyk/fix/map-stability-to-x-api-stability
Browse files Browse the repository at this point in the history
fix: map x-stability value to a parsable value
  • Loading branch information
tinygrasshopper authored Sep 30, 2024
2 parents cf4ae80 + 8f26374 commit 5ffe392
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/simplebuild/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (vs VersionSet) Annotate() {
op.Operation.Extensions[vervet.ExtSnykApiVersion] = op.Version.String()
op.Operation.Extensions[vervet.ExtSnykApiReleases] = releases
op.Operation.Extensions[vervet.ExtSnykApiLifecycle] = op.Version.LifecycleAt(time.Time{}).String()
op.Operation.Extensions[vervet.ExtApiStabilityLevel] = op.Version.Stability.String()
op.Operation.Extensions[vervet.ExtApiStabilityLevel] = MapStabilityLevel(op.Version.Stability)
op.Operation.Extensions[vervet.ExtSnykApiStability] = op.Version.Stability.String()

if idx < (count - 1) {
Expand All @@ -355,6 +355,18 @@ func (vs VersionSet) Annotate() {
}
}

// MapStabilityLevel maps the vervet stability level to the x-API stability level header.
func MapStabilityLevel(s vervet.Stability) string {
switch s {
case vervet.StabilityGA:
return "stable"
case vervet.StabilityBeta:
return "beta"
default:
return ""
}
}

func CheckBreakingChanges(docs DocSet) error {
for i := 1; i < len(docs); i++ {
prevDoc := docs[i-1]
Expand Down
31 changes: 31 additions & 0 deletions internal/simplebuild/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,3 +700,34 @@ func compareDocs(a, b simplebuild.VersionedDoc) int {
func compareDates(a, b time.Time) int {
return a.Compare(b)
}

func TestMapStabilityLevel(t *testing.T) {
tests := []struct {
name string
args vervet.Stability
want string
}{
{
name: "stable",
args: vervet.StabilityGA,
want: "stable",
},
{
name: "beta",
args: vervet.StabilityBeta,
want: "beta",
},
{
name: "defaults to blank",
args: vervet.StabilityExperimental,
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := simplebuild.MapStabilityLevel(tt.args); got != tt.want {
t.Errorf("MapStabilityLevel() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 5ffe392

Please sign in to comment.