Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graph deprecation mermaid visualization update #1172

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
46 changes: 45 additions & 1 deletion alpha/declcfg/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ func (writer *MermaidWriter) WriteChannels(cfg DeclarativeConfig, out io.Writer)

minEdgePackage := writer.getMinEdgePackage(&cfg)

depByPackage := sets.Set[string]{}
depByChannel := sets.Set[string]{}
depByBundle := sets.Set[string]{}

for _, d := range cfg.Deprecations {
for _, e := range d.Entries {
switch e.Reference.Schema {
case SchemaPackage:
depByPackage.Insert(d.Package)
case SchemaChannel:
depByChannel.Insert(e.Reference.Name)
case SchemaBundle:
depByBundle.Insert(e.Reference.Name)
}
}
}

var deprecatedPackage string
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this PR is merged already, but the code here presumes that we will only ever have at most one deprecated package. If the scope of the declcfg includes multiple deprecated packages, does this work?

deprecatedChannels := []string{}

for _, c := range cfg.Channels {
filteredChannel := writer.filterChannel(&c, versionMap, minVersion, minEdgePackage)
if filteredChannel != nil {
Expand All @@ -119,10 +139,23 @@ func (writer *MermaidWriter) WriteChannels(cfg DeclarativeConfig, out io.Writer)
pkgBuilder.WriteString(fmt.Sprintf(" %%%% channel %q\n", filteredChannel.Name))
pkgBuilder.WriteString(fmt.Sprintf(" subgraph %s[%q]\n", channelID, filteredChannel.Name))

if depByPackage.Has(filteredChannel.Package) {
deprecatedPackage = filteredChannel.Package
}

if depByChannel.Has(filteredChannel.Name) {
deprecatedChannels = append(deprecatedChannels, channelID)
}

for _, ce := range filteredChannel.Entries {
if versionMap[ce.Name].GE(minVersion) {
bundleDeprecation := ""
if depByBundle.Has(ce.Name) {
bundleDeprecation = ":::deprecated"
}

entryId := fmt.Sprintf("%s-%s", channelID, ce.Name)
pkgBuilder.WriteString(fmt.Sprintf(" %s[%q]\n", entryId, ce.Name))
pkgBuilder.WriteString(fmt.Sprintf(" %s[%q]%s\n", entryId, ce.Name, bundleDeprecation))

if len(ce.Replaces) > 0 {
replacesId := fmt.Sprintf("%s-%s", channelID, ce.Replaces)
Expand Down Expand Up @@ -154,6 +187,7 @@ func (writer *MermaidWriter) WriteChannels(cfg DeclarativeConfig, out io.Writer)
}

out.Write([]byte("graph LR\n"))
out.Write([]byte(fmt.Sprintf(" classDef deprecated fill:#E8960F\n")))
pkgNames := []string{}
for pname := range pkgs {
pkgNames = append(pkgNames, pname)
Expand All @@ -168,6 +202,16 @@ func (writer *MermaidWriter) WriteChannels(cfg DeclarativeConfig, out io.Writer)
out.Write([]byte(" end\n"))
}

if deprecatedPackage != "" {
out.Write([]byte(fmt.Sprintf("style %s fill:#989695\n", deprecatedPackage)))
}

if len(deprecatedChannels) > 0 {
for _, deprecatedChannel := range deprecatedChannels {
out.Write([]byte(fmt.Sprintf("style %s fill:#DCD0FF\n", deprecatedChannel)))
}
}

return nil
}

Expand Down
11 changes: 9 additions & 2 deletions alpha/declcfg/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,12 @@ func TestWriteMermaidChannels(t *testing.T) {
startEdge: "",
packageFilter: "",
expected: `graph LR
classDef deprecated fill:#E8960F
%% package "anakin"
subgraph "anakin"
%% channel "dark"
subgraph anakin-dark["dark"]
anakin-dark-anakin.v0.0.1["anakin.v0.0.1"]
anakin-dark-anakin.v0.0.1["anakin.v0.0.1"]:::deprecated
anakin-dark-anakin.v0.1.0["anakin.v0.1.0"]
anakin-dark-anakin.v0.0.1["anakin.v0.0.1"]-- replace --> anakin-dark-anakin.v0.1.0["anakin.v0.1.0"]
anakin-dark-anakin.v0.1.1["anakin.v0.1.1"]
Expand All @@ -539,7 +540,7 @@ func TestWriteMermaidChannels(t *testing.T) {
end
%% channel "light"
subgraph anakin-light["light"]
anakin-light-anakin.v0.0.1["anakin.v0.0.1"]
anakin-light-anakin.v0.0.1["anakin.v0.0.1"]:::deprecated
anakin-light-anakin.v0.1.0["anakin.v0.1.0"]
anakin-light-anakin.v0.0.1["anakin.v0.0.1"]-- replace --> anakin-light-anakin.v0.1.0["anakin.v0.1.0"]
end
Expand All @@ -553,6 +554,8 @@ func TestWriteMermaidChannels(t *testing.T) {
boba-fett-mando-boba-fett.v1.0.0["boba-fett.v1.0.0"]-- replace --> boba-fett-mando-boba-fett.v2.0.0["boba-fett.v2.0.0"]
end
end
style anakin fill:#989695
style anakin-light fill:#DCD0FF
`,
},
{
Expand All @@ -561,6 +564,7 @@ func TestWriteMermaidChannels(t *testing.T) {
startEdge: "anakin.v0.1.0",
packageFilter: "",
expected: `graph LR
classDef deprecated fill:#E8960F
%% package "anakin"
subgraph "anakin"
%% channel "dark"
Expand All @@ -574,6 +578,8 @@ func TestWriteMermaidChannels(t *testing.T) {
anakin-light-anakin.v0.1.0["anakin.v0.1.0"]
end
end
style anakin fill:#989695
style anakin-light fill:#DCD0FF
`,
},
{
Expand All @@ -582,6 +588,7 @@ func TestWriteMermaidChannels(t *testing.T) {
startEdge: "",
packageFilter: "boba-fett",
expected: `graph LR
classDef deprecated fill:#E8960F
%% package "boba-fett"
subgraph "boba-fett"
%% channel "mando"
Expand Down
Loading