Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jazanne committed Nov 13, 2023
1 parent 8e1bc0f commit abc98c0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
21 changes: 6 additions & 15 deletions comments/comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,18 @@ func BuildFlagComment(buildComment FlagComments, flagsRef refs.ReferenceSummary,

func ProcessFlags(flagsRef refs.ReferenceSummary, flags []ldapi.FeatureFlag, config *lcr.Config) FlagComments {
buildComment := FlagComments{}
addedKeys := make([]string, 0, len(flagsRef.FlagsAdded))
for key := range flagsRef.FlagsAdded {
addedKeys = append(addedKeys, key)
}
// sort keys so hashing can work for checking if comment already exists
sort.Strings(addedKeys)
for _, flagKey := range addedKeys {

for _, flagKey := range flagsRef.AddedKeys() {
flagAliases := flagsRef.FlagsAdded[flagKey]
idx, _ := find(flags, flagKey)
createComment, err := githubFlagComment(flags[idx], flagAliases, true, false, config)
buildComment.CommentsAdded = append(buildComment.CommentsAdded, createComment)
if err != nil {
log.Println(err)
}
buildComment.CommentsAdded = append(buildComment.CommentsAdded, createComment)
}
removedKeys := make([]string, 0, len(flagsRef.FlagsRemoved))
for key := range flagsRef.FlagsRemoved {
removedKeys = append(removedKeys, key)
}
sort.Strings(removedKeys)
for _, flagKey := range removedKeys {

for _, flagKey := range flagsRef.RemovedKeys() {
flagAliases := flagsRef.FlagsRemoved[flagKey]
idx, _ := find(flags, flagKey)
extinct := false
Expand All @@ -152,10 +143,10 @@ func ProcessFlags(flagsRef refs.ReferenceSummary, flags []ldapi.FeatureFlag, con
extinct = e
}
removedComment, err := githubFlagComment(flags[idx], flagAliases, false, extinct, config)
buildComment.CommentsRemoved = append(buildComment.CommentsRemoved, removedComment)
if err != nil {
log.Println(err)
}
buildComment.CommentsRemoved = append(buildComment.CommentsRemoved, removedComment)
}

return buildComment
Expand Down
22 changes: 22 additions & 0 deletions internal/references/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package flags

import "sort"

type FlagAliasMap = map[string][]string

type ReferenceSummary struct {
Expand All @@ -15,3 +17,23 @@ func (fr ReferenceSummary) Found() bool {
func (fr ReferenceSummary) Count() int {
return len(fr.FlagsAdded) + len(fr.FlagsRemoved)
}

// returns a sorted list of all added flag keys
func (fr ReferenceSummary) AddedKeys() []string {
return fr.sortedKeys(fr.FlagsAdded)
}

// returns a sorted list of all removed flag keys
func (fr ReferenceSummary) RemovedKeys() []string {
return fr.sortedKeys(fr.FlagsRemoved)
}

func (fr ReferenceSummary) sortedKeys(keys map[string][]string) []string {
sortedKeys := make([]string, 0, len(keys))
for k := range keys {
sortedKeys = append(sortedKeys, k)
}
// sort keys so hashing can work for checking if comment already exists
sort.Strings(sortedKeys)
return sortedKeys
}

0 comments on commit abc98c0

Please sign in to comment.