Skip to content

Commit

Permalink
more handling for include extinctions
Browse files Browse the repository at this point in the history
  • Loading branch information
jazanne committed Nov 13, 2023
1 parent 5469761 commit 8e1bc0f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
6 changes: 5 additions & 1 deletion comments/comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ func ProcessFlags(flagsRef refs.ReferenceSummary, flags []ldapi.FeatureFlag, con
for _, flagKey := range removedKeys {
flagAliases := flagsRef.FlagsRemoved[flagKey]
idx, _ := find(flags, flagKey)
_, extinct := flagsRef.ExtinctFlags[flagKey]
extinct := false
if flagsRef.ExtinctFlags != nil {
_, e := flagsRef.ExtinctFlags[flagKey]
extinct = e
}
removedComment, err := githubFlagComment(flags[idx], flagAliases, false, extinct, config)
buildComment.CommentsRemoved = append(buildComment.CommentsRemoved, removedComment)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func newProcessFlagAccEnv() *testProcessor {
flags := ldapi.FeatureFlags{}
flags.Items = append(flags.Items, flag)
flags.Items = append(flags.Items, flag2)
builder := refs.NewReferenceSummaryBuilder(5)
builder := refs.NewReferenceSummaryBuilder(5, false)
config := config.Config{
LdEnvironment: "production",
LdInstance: "https://example.com/",
Expand Down
33 changes: 20 additions & 13 deletions internal/references/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ import (
)

type ReferenceSummaryBuilder struct {
max int // maximum number of flags to find
flagsAdded map[string][]string
flagsRemoved map[string][]string
flagsFoundAtHead map[string]struct{}
foundFlags map[string]struct{}
max int // maximum number of flags to find
includeExtinctions bool // include extinctions in summary
flagsAdded map[string][]string
flagsRemoved map[string][]string
flagsFoundAtHead map[string]struct{}
foundFlags map[string]struct{}
}

func NewReferenceSummaryBuilder(max int) *ReferenceSummaryBuilder {
func NewReferenceSummaryBuilder(max int, includeExtinctions bool) *ReferenceSummaryBuilder {
return &ReferenceSummaryBuilder{
flagsAdded: make(map[string][]string),
flagsRemoved: make(map[string][]string),
foundFlags: make(map[string]struct{}),
flagsFoundAtHead: make(map[string]struct{}),
max: max,
flagsAdded: make(map[string][]string),
flagsRemoved: make(map[string][]string),
foundFlags: make(map[string]struct{}),
flagsFoundAtHead: make(map[string]struct{}),
max: max,
includeExtinctions: includeExtinctions,
}
}

Expand Down Expand Up @@ -107,11 +109,16 @@ func (b *ReferenceSummaryBuilder) Build() ReferenceSummary {
}
}

return ReferenceSummary{
summary := ReferenceSummary{
FlagsAdded: added,
FlagsRemoved: removed,
ExtinctFlags: extinctions,
}

if b.includeExtinctions {
summary.ExtinctFlags = extinctions
}

return summary
}

// get slice with unique, non-empty strings
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func main() {
matcher, err := search.GetMatcher(opts, flagKeys, diffMap)
failExit(err)

builder := references.NewReferenceSummaryBuilder(config.MaxFlags)
builder := references.NewReferenceSummaryBuilder(config.MaxFlags, config.CheckExtinctions)
for _, contents := range diffMap {
ldiff.ProcessDiffs(matcher, contents, builder)
}
Expand Down

0 comments on commit 8e1bc0f

Please sign in to comment.