Skip to content

Commit

Permalink
update flags type
Browse files Browse the repository at this point in the history
  • Loading branch information
jazanne committed Aug 2, 2023
1 parent 78584d6 commit 40a5fc7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
10 changes: 5 additions & 5 deletions comments/comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions comments/comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 40a5fc7

Please sign in to comment.