-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sc-231506] fix: extinction checking not working correctly (#93)
- Loading branch information
Showing
12 changed files
with
177 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
testDir/*.js | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,38 @@ | ||
package extinctions | ||
|
||
import ( | ||
gha "github.com/launchdarkly/find-code-references-in-pull-request/internal/github_actions" | ||
refs "github.com/launchdarkly/find-code-references-in-pull-request/internal/references" | ||
"github.com/launchdarkly/find-code-references-in-pull-request/search" | ||
"github.com/launchdarkly/ld-find-code-refs/v2/options" | ||
ld_search "github.com/launchdarkly/ld-find-code-refs/v2/search" | ||
) | ||
|
||
func CheckExtinctions(opts options.Options, builder *refs.ReferenceSummaryBuilder) error { | ||
flagKeys := make([]string, 0, len(builder.RemovedFlagKeys())) | ||
flagKeys := builder.RemovedFlagKeys() | ||
if len(flagKeys) == 0 { | ||
return nil | ||
} | ||
gha.StartLogGroup("Checking for extinctions...") | ||
defer gha.EndLogGroup() | ||
|
||
matcher, err := search.GetMatcher(opts, flagKeys, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
gha.Debug("Searching for any remaining references to %d removed flags...", len(flagKeys)) | ||
references, err := ld_search.SearchForRefs(opts.Dir, matcher) | ||
if err != nil { | ||
return err | ||
} | ||
gha.Debug("Found %d references to removed flags", len(references)) | ||
|
||
for _, ref := range references { | ||
for _, hunk := range ref.Hunks { | ||
gha.Debug("Flag '%s' is not extinct", hunk.FlagKey) | ||
builder.AddHeadFlag(hunk.FlagKey) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package flags | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBuilder_Build(t *testing.T) { | ||
ref := ReferenceSummaryBuilder{ | ||
flagsAdded: map[string][]string{ | ||
"flag1": {"alias1"}, | ||
"flag2": {"alias2"}, | ||
}, | ||
flagsRemoved: map[string][]string{ | ||
"flag2": {}, | ||
"flag3": {"alias3"}, | ||
"flag4": {"alias4"}, | ||
}, | ||
flagsFoundAtHead: map[string]struct{}{ | ||
"flag3": {}, | ||
}, | ||
foundFlags: map[string]struct{}{ | ||
"flag1": {}, | ||
"flag2": {}, | ||
"flag3": {}, | ||
"flag4": {}, | ||
}, | ||
includeExtinctions: true, | ||
} | ||
|
||
built := ref.Build() | ||
|
||
assert.Len(t, built.FlagsAdded, 2) | ||
assert.Len(t, built.FlagsRemoved, 2) | ||
assert.Len(t, built.ExtinctFlags, 1) | ||
} | ||
|
||
func TestBuilder_RemovedFlagKeys(t *testing.T) { | ||
ref := ReferenceSummaryBuilder{ | ||
flagsAdded: map[string][]string{ | ||
"flag1": {"alias1"}, | ||
"flag2": {"alias2"}, | ||
}, | ||
flagsRemoved: map[string][]string{ | ||
"flag2": {}, | ||
"flag3": {"alias3"}, | ||
"flag4": {"alias4"}, | ||
}, | ||
flagsFoundAtHead: map[string]struct{}{ | ||
"flag3": {}, | ||
}, | ||
foundFlags: map[string]struct{}{ | ||
"flag1": {}, | ||
"flag2": {}, | ||
"flag3": {}, | ||
"flag4": {}, | ||
}, | ||
includeExtinctions: true, | ||
} | ||
|
||
keys := ref.RemovedFlagKeys() | ||
|
||
assert.Len(t, keys, 3) | ||
assert.ElementsMatch(t, keys, []string{"flag2", "flag3", "flag4"}) | ||
} |
Oops, something went wrong.