Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/cli/internal/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func findChangelogEntry(changelog []*Entry, date, operationID, version, changeCo
}

for _, v := range path.Versions {
if v.Version != version {
if version != "" && v.Version != version {
continue
}

Expand Down
63 changes: 62 additions & 1 deletion tools/cli/internal/changelog/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,68 @@ func TestFindChangelogEntry(t *testing.T) {
changeCode string
expectedEntries *Change
}{

{
name: "find changelog entry no API Version",
entries: []*Entry{
{
Date: "2023-07-10",
Paths: []*Path{
{
URI: "/api/atlas/v2/groups/{id}/clusters",
HTTPMethod: "POST",
OperationID: "createCluster",
Tag: "Multi-Cloud Clusters",
Versions: []*Version{
{
Version: "2023-02-01",
StabilityLevel: "stable",
ChangeType: "remove",
Changes: []*Change{
{
Description: "endpoint removed",
Code: "endpoint-removed",
BackwardCompatible: true,
}},
},
},
},
},
},
{
Date: "2023-07-11",
Paths: []*Path{
{
URI: "/api/atlas/v2/groups/{id}/clusters",
HTTPMethod: "POST",
OperationID: "createCluster",
Tag: "Multi-Cloud Clusters",
Versions: []*Version{
{
Version: "2023-02-01",
StabilityLevel: "stable",
ChangeType: "remove",
Changes: []*Change{
{
Description: "endpoint removed",
Code: "endpoint-removed",
BackwardCompatible: true,
}},
},
},
},
},
},
},
operationID: "createCluster",
date: "2023-07-10",
version: "",
changeCode: "endpoint-removed",
expectedEntries: &Change{
Description: "endpoint removed",
Code: "endpoint-removed",
BackwardCompatible: true,
},
},
{
name: "find changelog entry",
entries: []*Entry{
Expand Down
22 changes: 11 additions & 11 deletions tools/cli/internal/changelog/outputfilter/squash.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,35 @@ func squashEntries(entries []*OasDiffEntry) ([]*OasDiffEntry, error) {
entriesByIDandOperationID, hiddenEntriesByIDandOperationID := newEntriesMapPerIDAndOperationID(entries)

squashHandlers := newSquashHandlers()
squashedEntries := []*OasDiffEntry{}
squashedEntriesOut := []*OasDiffEntry{}

for _, entry := range entries {
// if no squash handlers implemented for entry's code,
// just append the entry to the result
if _, ok := findHandler(entry.ID); !ok {
squashedEntries = append(squashedEntries, entry)
squashedEntriesOut = append(squashedEntriesOut, entry)
continue
}
}

squashedEntriesNotHidden, err := appplySquashHandlerToMap(squashHandlers, entriesByIDandOperationID)
squashedEntriesNotHidden, err := applySquashHandlerToMap(squashHandlers, entriesByIDandOperationID)
if err != nil {
return nil, err
}

squashedEntriesHidden, err := appplySquashHandlerToMap(squashHandlers, hiddenEntriesByIDandOperationID)
squashedEntriesHidden, err := applySquashHandlerToMap(squashHandlers, hiddenEntriesByIDandOperationID)
if err != nil {
return nil, err
}

squashedEntries = append(squashedEntries, squashedEntriesNotHidden...)
squashedEntries = append(squashedEntries, squashedEntriesHidden...)
squashedEntriesOut = append(squashedEntriesOut, squashedEntriesNotHidden...)
squashedEntriesOut = append(squashedEntriesOut, squashedEntriesHidden...)

return squashedEntries, nil
return squashedEntriesOut, nil
}

func appplySquashHandlerToMap(squashHandlers []handler, entriesMap map[string]map[string][]*OasDiffEntry) ([]*OasDiffEntry, error) {
squashedEntries := []*OasDiffEntry{}
func applySquashHandlerToMap(squashHandlers []handler, entriesMap map[string]map[string][]*OasDiffEntry) ([]*OasDiffEntry, error) {
squashedEntriesOut := []*OasDiffEntry{}
for _, handler := range squashHandlers {
entryMapPerOperationID, ok := entriesMap[handler.id]
if !ok {
Expand All @@ -187,9 +187,9 @@ func appplySquashHandlerToMap(squashHandlers []handler, entriesMap map[string]ma
return nil, err
}

squashedEntries = append(squashedEntries, sortEntriesByDescription(entries)...)
squashedEntriesOut = append(squashedEntriesOut, sortEntriesByDescription(entries)...)
}
return squashedEntries, nil
return squashedEntriesOut, nil
}

func sortEntriesByDescription(entries []*OasDiffEntry) []*OasDiffEntry {
Expand Down
8 changes: 5 additions & 3 deletions tools/cli/internal/changelog/sunset.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ func (m *Changelog) newOasDiffEntriesFromSunsetEndpoints(
continue
}

// Avoid adding duplicates in the changelog
if findChangelogEntry(m.BaseChangelog, config.Revision.Sunset, operationID, version, endpointRemovedCode) == nil {
// Avoid adding duplicates in the changelog.
// Passing version="" to findChangelogEntry since the sunset date of the endpoint with API version "version"
// is the same in all the specs.
if findChangelogEntry(m.BaseChangelog, config.Revision.Sunset, operationID, "", endpointRemovedCode) == nil {
changes = append(changes, &outputfilter.OasDiffEntry{
Date: config.Revision.Sunset,
ID: endpointRemovedCode,
Text: "endpoint removed",
Text: fmt.Sprintf("endpoint with API Version '%s' was removed as it has reached its sunset date '%s'", version, config.Revision.Sunset),
Level: int(checker.ERR),
Operation: config.Revision.HTTPMethod,
OperationID: operationID,
Expand Down
2 changes: 1 addition & 1 deletion tools/cli/internal/changelog/sunset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestNewOasDiffEntriesFromSunsetEndpoints(t *testing.T) {
Operation: "GET",
OperationID: "listStreamInstances",
Path: "/api/atlas/v2/groups/{id}/streams",
Text: "endpoint removed",
Text: "endpoint with API Version '2023-02-01' was removed as it has reached its sunset date '2023-07-12'",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think from CL pov this might be confused, we're saying "endpoint removed" from the current version in the changelog.

maybe "endpoint removed (sunset date x)" to make it simple?

Copy link
Collaborator Author

@andreaangiolillo andreaangiolillo Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what is the suggested message 🤔
do you mean from endpoint with API Version '2023-02-01' was removed as it has reached its sunset date '2023-07-12' to endpoint with API Version '2023-02-01' was removed (sunset date '2023-07-12)'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, only endpoint removed (sunset date '2023-07-12)'

Copy link
Collaborator Author

@andreaangiolillo andreaangiolillo Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think including the API version is important; otherwise, it may give the impression that the entire endpoint was removed, when in fact only a specific version was removed. Am I missing something?

},
}

Expand Down
Loading