Skip to content

Commit

Permalink
Merge pull request #22 from evankanderson/simplify-frizbee
Browse files Browse the repository at this point in the history
Remove custom setAsSlice for ToSlice, switch to ThreadUnsafeSets
  • Loading branch information
JAORMX authored Nov 30, 2023
2 parents 6b87dfc + 7a05066 commit dd94541
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions pkg/ghactions/ghactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package ghactions provides functions to replace tags for checksums
// in GitHub Actions workflows.
// Package ghactions provides functions to locate action references and
// replace tags for checksums in GitHub Actions workflows.
package ghactions

import (
Expand Down Expand Up @@ -144,7 +144,7 @@ type Action struct {

// ListActionsInYAML returns a list of actions referenced in the given YAML structure.
func setOfActions(node *yaml.Node) (mapset.Set[Action], error) {
actions := mapset.NewSet[Action]()
actions := mapset.NewThreadUnsafeSet[Action]()
foundUses := false

for _, v := range node.Content {
Expand Down Expand Up @@ -177,20 +177,19 @@ func setOfActions(node *yaml.Node) (mapset.Set[Action], error) {

// ListActionsInYAML returns a list of actions referenced in the given YAML structure.
func ListActionsInYAML(node *yaml.Node) ([]Action, error) {
// just convert the set to a slice
actions, err := setOfActions(node)
if err != nil {
return nil, err
}

return setAsSlice[Action](actions), nil
return actions.ToSlice(), nil
}

// ListActionsInDirectory returns a list of actions referenced in the given directory.
func ListActionsInDirectory(dir string) ([]Action, error) {
base := filepath.Base(dir)
bfs := osfs.New(filepath.Dir(dir), osfs.WithBoundOS())
actions := mapset.NewSet[Action]()
actions := mapset.NewThreadUnsafeSet[Action]()

err := TraverseGitHubActionWorkflows(bfs, base, func(path string, wflow *yaml.Node) error {
wfActions, err := setOfActions(wflow)
Expand All @@ -205,15 +204,7 @@ func ListActionsInDirectory(dir string) ([]Action, error) {
return nil, err
}

return setAsSlice[Action](actions), nil
}

func setAsSlice[T comparable](s mapset.Set[T]) []T {
res := make([]T, 0, s.Cardinality())
for item := range s.Iter() {
res = append(res, item) // Type assertion to T
}
return res
return actions.ToSlice(), nil
}

func parseValue(val string) (*Action, error) {
Expand Down

0 comments on commit dd94541

Please sign in to comment.