From 412f1cbb8e5d9a572e36e7c3838a88d1f5be1cda Mon Sep 17 00:00:00 2001 From: Jaz Date: Mon, 13 Nov 2023 15:51:14 -0500 Subject: [PATCH] allow no max flags --- README.md | 2 +- action.yml | 2 +- config/config.go | 3 +++ flags/builder.go | 5 ++++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ac48b132..20522bfb 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ This action does not support monorepos or searching for flags across LaunchDarkl | environment-key | LaunchDarkly environment key for creating flag links | `false` | production | | placeholder-comment | Comment on PR when no flags are found. If flags are found in later commits, this comment will be updated. | `false` | false | | include-archived-flags | Scan for archived flags | `false` | true | -| max-flags | Maximum number of flags to find per PR | `false` | 5 | +| max-flags | Maximum number of flags to find per PR. Set to `-1` to find all changed flags. | `false` | 5 | | base-uri | The base URI for the LaunchDarkly server. Most users should use the default value. | `false` | https://app.launchdarkly.com | diff --git a/action.yml b/action.yml index df578690..75a79c29 100644 --- a/action.yml +++ b/action.yml @@ -34,7 +34,7 @@ inputs: required: false default: 'true' max-flags: - description: Maximum number of flags to find per PR + description: Maximum number of flags to find per PR. Set to `-1` to find all changed flags. required: false default: '5' base-uri: diff --git a/config/config.go b/config/config.go index 8f045860..883e4e6a 100644 --- a/config/config.go +++ b/config/config.go @@ -68,6 +68,9 @@ func ValidateInputandParse(ctx context.Context) (*Config, error) { return nil, err } config.MaxFlags = int(maxFlags) + if config.MaxFlags == 0 || config.MaxFlags < -1 { + return nil, errors.New("`max-flags` must be a positive integer or -1 to search for all changed flags") + } if placholderComment, err := strconv.ParseBool(os.Getenv("INPUT_PLACEHOLDER-COMMENT")); err == nil { // ignore error - default is false diff --git a/flags/builder.go b/flags/builder.go index 91cf0a66..8e5a139b 100644 --- a/flags/builder.go +++ b/flags/builder.go @@ -25,7 +25,10 @@ func NewReferenceBuilder(max int) *ReferenceBuilder { } func (b *ReferenceBuilder) MaxReferences() bool { - return len(b.foundFlags) >= b.max + if b.max > 0 { + return len(b.foundFlags) >= b.max + } + return false } func (b *ReferenceBuilder) AddReference(flagKey string, op diff_util.Operation, aliases []string) error {