Skip to content

Commit

Permalink
No need to resolve keys, use refs directly
Browse files Browse the repository at this point in the history
  • Loading branch information
doriable committed Dec 9, 2024
1 parent 7a9406d commit 38968ae
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions private/buf/cmd/buf/command/plugin/pluginprune/pluginprune.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/bufbuild/buf/private/buf/bufcli"
"github.com/bufbuild/buf/private/buf/bufworkspace"
"github.com/bufbuild/buf/private/bufpkg/bufparse"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appext"
Expand Down Expand Up @@ -66,24 +67,12 @@ func run(
if err != nil {
return err
}
pluginKeyProvider, err := bufcli.NewPluginKeyProvider(container)
if err != nil {
return err
}
configuredRemotePluginKeys, err := pluginKeyProvider.GetPluginKeysForPluginRefs(
ctx,
configuredRemotePluginRefs,
bufplugin.DigestTypeP1,
)
if err != nil {
return err
}
return prune(
ctx,
slicesext.Map(
configuredRemotePluginKeys,
func(pluginKey bufplugin.PluginKey) string {
return pluginKey.String()
configuredRemotePluginRefs,
func(pluginRef bufparse.Ref) string {
return pluginRef.FullName().String()
},
),
workspaceDepManager,
Expand All @@ -92,18 +81,18 @@ func run(

func prune(
ctx context.Context,
bufYAMLBasedRemotePluginKeys []string,
bufYAMLBasedRemotePluginNames []string,
workspaceDepManager bufworkspace.WorkspaceDepManager,
) error {
bufYAMLPluginKeys := slicesext.ToStructMap(bufYAMLBasedRemotePluginKeys)
bufYAMLRemotePluginNames := slicesext.ToStructMap(bufYAMLBasedRemotePluginNames)
existingRemotePluginKeys, err := workspaceDepManager.ExistingBufLockFileRemotePluginKeys(ctx)
if err != nil {
return err
}
var prunedBufLockPluginKeys []bufplugin.PluginKey
for _, existingRemotePluginKey := range existingRemotePluginKeys {
// Check if an existing plugin key from the buf.lock is confiugred in the buf.yaml.
if _, ok := bufYAMLPluginKeys[existingRemotePluginKey.String()]; ok {
if _, ok := bufYAMLRemotePluginNames[existingRemotePluginKey.FullName().String()]; ok {
// If yes, then we keep it for the updated buf.lock.
prunedBufLockPluginKeys = append(prunedBufLockPluginKeys, existingRemotePluginKey)
}
Expand Down

0 comments on commit 38968ae

Please sign in to comment.