From 40a5fc75ed6c27229401b9801e0163364be198e7 Mon Sep 17 00:00:00 2001 From: Jaz White Date: Wed, 2 Aug 2023 10:40:42 -0400 Subject: [PATCH] update flags type --- comments/comments.go | 10 +++++----- comments/comments_test.go | 7 +++---- main.go | 12 ++++++------ search/search.go | 6 +++--- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/comments/comments.go b/comments/comments.go index 1628091c..984c2bbc 100644 --- a/comments/comments.go +++ b/comments/comments.go @@ -110,7 +110,7 @@ func BuildFlagComment(buildComment FlagComments, flagsRef lflags.FlagsRef, exist return postedComments } -func ProcessFlags(flagsRef lflags.FlagsRef, flags ldapi.FeatureFlags, config *lcr.Config) FlagComments { +func ProcessFlags(flagsRef lflags.FlagsRef, flags []ldapi.FeatureFlag, config *lcr.Config) FlagComments { buildComment := FlagComments{} addedKeys := make([]string, 0, len(flagsRef.FlagsAdded)) for key := range flagsRef.FlagsAdded { @@ -122,8 +122,8 @@ func ProcessFlags(flagsRef lflags.FlagsRef, flags ldapi.FeatureFlags, config *lc // If flag is in both added and removed then it is being modified delete(flagsRef.FlagsRemoved, flagKey) flagAliases := uniqueAliases(flagsRef.FlagsAdded[flagKey]) - idx, _ := find(flags.Items, flagKey) - createComment, err := githubFlagComment(flags.Items[idx], flagAliases, config) + idx, _ := find(flags, flagKey) + createComment, err := githubFlagComment(flags[idx], flagAliases, config) buildComment.CommentsAdded = append(buildComment.CommentsAdded, createComment) if err != nil { log.Println(err) @@ -136,8 +136,8 @@ func ProcessFlags(flagsRef lflags.FlagsRef, flags ldapi.FeatureFlags, config *lc sort.Strings(removedKeys) for _, flagKey := range removedKeys { flagAliases := uniqueAliases(flagsRef.FlagsRemoved[flagKey]) - idx, _ := find(flags.Items, flagKey) - removedComment, err := githubFlagComment(flags.Items[idx], flagAliases, config) + idx, _ := find(flags, flagKey) + removedComment, err := githubFlagComment(flags[idx], flagAliases, config) buildComment.CommentsRemoved = append(buildComment.CommentsRemoved, removedComment) if err != nil { log.Println(err) diff --git a/comments/comments_test.go b/comments/comments_test.go index 55bc4243..942a8698 100644 --- a/comments/comments_test.go +++ b/comments/comments_test.go @@ -79,15 +79,14 @@ func newCommentBuilderAccEnv() *testCommentBuilder { } type testProcessor struct { - Flags ldapi.FeatureFlags + Flags []ldapi.FeatureFlag FlagsRef lflags.FlagsRef Config config.Config } func newProcessFlagAccEnv() *testProcessor { flag := createFlag("example-flag") - flags := ldapi.FeatureFlags{} - flags.Items = append(flags.Items, flag) + flags := []ldapi.FeatureFlag{flag} flagsAdded := make(lflags.FlagAliasMap) flagsRemoved := make(lflags.FlagAliasMap) flagsRef := lflags.FlagsRef{ @@ -109,7 +108,7 @@ func newProcessFlagAccEnv() *testProcessor { func newProcessMultipleFlagsFlagAccEnv() *testProcessor { flag := createFlag("example-flag") flag2 := createFlag("second-flag") - flags := ldapi.FeatureFlags{Items: []ldapi.FeatureFlag{flag, flag2}} + flags := []ldapi.FeatureFlag{flag, flag2} flagsAdded := make(lflags.FlagAliasMap) flagsRemoved := make(lflags.FlagAliasMap) flagsRef := lflags.FlagsRef{ diff --git a/main.go b/main.go index e1803c38..78860d58 100644 --- a/main.go +++ b/main.go @@ -40,7 +40,7 @@ func main() { flags, err := getFlags(config) failExit(err) - if len(flags.Items) == 0 { + if len(flags) == 0 { log.Println("No flags found") os.Exit(0) } @@ -87,28 +87,28 @@ func main() { failExit(err) } -func getFlags(config *lcr.Config) (ldapi.FeatureFlags, error) { +func getFlags(config *lcr.Config) ([]ldapi.FeatureFlag, error) { url := fmt.Sprintf("%s/api/v2/flags/%s?env=%s", config.LdInstance, config.LdProject, config.LdEnvironment) client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { - return ldapi.FeatureFlags{}, err + return []ldapi.FeatureFlag{}, err } req.Header.Add("Authorization", config.ApiToken) resp, err := client.Do(req) if err != nil { - return ldapi.FeatureFlags{}, err + return []ldapi.FeatureFlag{}, err } defer resp.Body.Close() flags := ldapi.FeatureFlags{} err = json.NewDecoder(resp.Body).Decode(&flags) if err != nil { - return ldapi.FeatureFlags{}, err + return []ldapi.FeatureFlag{}, err } - return flags, nil + return flags.Items, nil } func checkExistingComments(event *github.PullRequestEvent, config *lcr.Config, ctx context.Context) *github.IssueComment { diff --git a/search/search.go b/search/search.go index 34c1a925..00302d47 100644 --- a/search/search.go +++ b/search/search.go @@ -13,9 +13,9 @@ import ( "github.com/spf13/viper" ) -func GetMatcher(config *lcr.Config, opts options.Options, flags ldapi.FeatureFlags) (matcher lsearch.Matcher, err error) { - flagKeys := make([]string, 0, len(flags.Items)) - for _, flag := range flags.Items { +func GetMatcher(config *lcr.Config, opts options.Options, flags []ldapi.FeatureFlag) (matcher lsearch.Matcher, err error) { + flagKeys := make([]string, 0, len(flags)) + for _, flag := range flags { flagKeys = append(flagKeys, flag.Key) }