diff --git a/CHANGELOG.md b/CHANGELOG.md index fcd8101d81..3b0ac19cea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Add `buf registry plugin {create,delete,info,update}` commands to manage BSR plugins. - Breaking analysis support for `buf beta lsp`. +- Add `buf registry plugin commit {add-label,info,list,resolve}` to manage BSR plugin commits. ## [v1.47.2] - 2024-11-14 diff --git a/private/buf/bufprint/bufprint.go b/private/buf/bufprint/bufprint.go index 28dd537109..de848df7b5 100644 --- a/private/buf/bufprint/bufprint.go +++ b/private/buf/bufprint/bufprint.go @@ -199,8 +199,8 @@ func PrintEntity(writer io.Writer, format Format, entity Entity) error { } } -// NewLabelEntity returns a new label entity to print. -func NewLabelEntity(label *modulev1.Label, moduleFullName bufparse.FullName) Entity { +// NewModuleLabelEntity returns a new label entity to print. +func NewModuleLabelEntity(label *modulev1.Label, moduleFullName bufparse.FullName) Entity { var archiveTime *time.Time if label.ArchiveTime != nil { timeValue := label.ArchiveTime.AsTime() @@ -211,16 +211,16 @@ func NewLabelEntity(label *modulev1.Label, moduleFullName bufparse.FullName) Ent Commit: label.CommitId, CreateTime: label.CreateTime.AsTime(), ArchiveTime: archiveTime, - moduleFullName: moduleFullName, + entityFullName: moduleFullName, } } -// NewCommitEntity returns a new commit entity to print. -func NewCommitEntity(commit *modulev1.Commit, moduleFullName bufparse.FullName) Entity { +// NewModuleCommitEntity returns a new commit entity to print. +func NewModuleCommitEntity(commit *modulev1.Commit, moduleFullName bufparse.FullName) Entity { return outputCommit{ Commit: commit.Id, CreateTime: commit.CreateTime.AsTime(), - moduleFullName: moduleFullName, + entityFullName: moduleFullName, } } @@ -261,6 +261,31 @@ func NewPluginEntity(plugin *pluginv1beta1.Plugin, pluginFullName bufparse.FullN } } +// NewPluginLabelEntity returns a new label entity to print. +func NewPluginLabelEntity(label *pluginv1beta1.Label, pluginFullName bufparse.FullName) Entity { + var archiveTime *time.Time + if label.ArchiveTime != nil { + timeValue := label.ArchiveTime.AsTime() + archiveTime = &timeValue + } + return outputLabel{ + Name: label.Name, + Commit: label.CommitId, + CreateTime: label.CreateTime.AsTime(), + ArchiveTime: archiveTime, + entityFullName: pluginFullName, + } +} + +// NewPluginCommitEntity returns a new commit entity to print. +func NewPluginCommitEntity(commit *pluginv1beta1.Commit, moduleFullName bufparse.FullName) Entity { + return outputCommit{ + Commit: commit.Id, + CreateTime: commit.CreateTime.AsTime(), + entityFullName: moduleFullName, + } +} + // NewUserEntity returns a new user entity to print. func NewUserEntity(user *registryv1alpha1.User) Entity { return outputUser{ @@ -434,22 +459,22 @@ type outputLabel struct { CreateTime time.Time `json:"create_time,omitempty" bufprint:"Create Time"` ArchiveTime *time.Time `json:"archive_time,omitempty" bufprint:"Archive Time,omitempty"` - moduleFullName bufparse.FullName + entityFullName bufparse.FullName } func (l outputLabel) fullName() string { - return fmt.Sprintf("%s:%s", l.moduleFullName.String(), l.Name) + return fmt.Sprintf("%s:%s", l.entityFullName.String(), l.Name) } type outputCommit struct { Commit string `json:"commit,omitempty" bufprint:"Commit"` CreateTime time.Time `json:"create_time,omitempty" bufprint:"Create Time"` - moduleFullName bufparse.FullName + entityFullName bufparse.FullName } func (c outputCommit) fullName() string { - return fmt.Sprintf("%s:%s", c.moduleFullName.String(), c.Commit) + return fmt.Sprintf("%s:%s", c.entityFullName.String(), c.Commit) } type outputModule struct { diff --git a/private/buf/cmd/buf/buf.go b/private/buf/cmd/buf/buf.go index 776b611c06..dcdcd66d18 100644 --- a/private/buf/cmd/buf/buf.go +++ b/private/buf/cmd/buf/buf.go @@ -81,6 +81,10 @@ import ( "github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/organization/organizationdelete" "github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/organization/organizationinfo" "github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/organization/organizationupdate" + "github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/plugin/plugincommit/plugincommitaddlabel" + "github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/plugin/plugincommit/plugincommitinfo" + "github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/plugin/plugincommit/plugincommitlist" + "github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/plugin/plugincommit/plugincommitresolve" "github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/plugin/plugincreate" "github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/plugin/plugindelete" "github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/plugin/plugininfo" @@ -260,6 +264,16 @@ func NewRootCommand(name string) *appcmd.Command { Use: "plugin", Short: "Manage BSR plugins", SubCommands: []*appcmd.Command{ + { + Use: "commit", + Short: "Manage a plugin's commits", + SubCommands: []*appcmd.Command{ + plugincommitaddlabel.NewCommand("add-label", builder, ""), + plugincommitinfo.NewCommand("info", builder, ""), + plugincommitlist.NewCommand("list", builder, ""), + plugincommitresolve.NewCommand("resolve", builder, ""), + }, + }, plugincreate.NewCommand("create", builder), plugininfo.NewCommand("info", builder), plugindelete.NewCommand("delete", builder), diff --git a/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitaddlabel/modulecommitaddlabel.go b/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitaddlabel/modulecommitaddlabel.go index 1b7c06df45..9b6f0cbff9 100644 --- a/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitaddlabel/modulecommitaddlabel.go +++ b/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitaddlabel/modulecommitaddlabel.go @@ -148,7 +148,7 @@ func run( container.Stdout(), format, slicesext.Map(resp.Msg.Labels, func(label *modulev1.Label) bufprint.Entity { - return bufprint.NewLabelEntity(label, moduleRef.FullName()) + return bufprint.NewModuleLabelEntity(label, moduleRef.FullName()) })..., ) } diff --git a/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitinfo/modulecommitinfo.go b/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitinfo/modulecommitinfo.go index 7529c688d4..e15277d2c2 100644 --- a/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitinfo/modulecommitinfo.go +++ b/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitinfo/modulecommitinfo.go @@ -124,6 +124,6 @@ func run( return bufprint.PrintEntity( container.Stdout(), format, - bufprint.NewCommitEntity(commits[0], moduleRef.FullName()), + bufprint.NewModuleCommitEntity(commits[0], moduleRef.FullName()), ) } diff --git a/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitlist/modulecommitlist.go b/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitlist/modulecommitlist.go index b12c7f000e..f739107d5e 100644 --- a/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitlist/modulecommitlist.go +++ b/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitlist/modulecommitlist.go @@ -161,7 +161,7 @@ func run( format, "", "", - []bufprint.Entity{bufprint.NewCommitEntity(commit, moduleRef.FullName())}, + []bufprint.Entity{bufprint.NewModuleCommitEntity(commit, moduleRef.FullName())}, ) } if resource.GetModule() != nil { @@ -200,7 +200,7 @@ func run( resp.Msg.NextPageToken, nextPageCommand(container, flags, resp.Msg.NextPageToken), slicesext.Map(resp.Msg.Commits, func(commit *modulev1.Commit) bufprint.Entity { - return bufprint.NewCommitEntity(commit, moduleRef.FullName()) + return bufprint.NewModuleCommitEntity(commit, moduleRef.FullName()) }), ) } @@ -252,7 +252,7 @@ func run( resp.Msg.NextPageToken, nextPageCommand(container, flags, resp.Msg.NextPageToken), slicesext.Map(commits, func(commit *modulev1.Commit) bufprint.Entity { - return bufprint.NewCommitEntity(commit, moduleRef.FullName()) + return bufprint.NewModuleCommitEntity(commit, moduleRef.FullName()) }), ) } diff --git a/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitresolve/modulecommitresolve.go b/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitresolve/modulecommitresolve.go index d006eacb0f..314dad9f48 100644 --- a/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitresolve/modulecommitresolve.go +++ b/private/buf/cmd/buf/command/registry/module/modulecommit/modulecommitresolve/modulecommitresolve.go @@ -123,6 +123,6 @@ func run( return bufprint.PrintNames( container.Stdout(), format, - bufprint.NewCommitEntity(commit, moduleRef.FullName()), + bufprint.NewModuleCommitEntity(commit, moduleRef.FullName()), ) } diff --git a/private/buf/cmd/buf/command/registry/module/modulelabel/modulelabelinfo/modulelabelinfo.go b/private/buf/cmd/buf/command/registry/module/modulelabel/modulelabelinfo/modulelabelinfo.go index 6a7cb8f83e..066ada7dd6 100644 --- a/private/buf/cmd/buf/command/registry/module/modulelabel/modulelabelinfo/modulelabelinfo.go +++ b/private/buf/cmd/buf/command/registry/module/modulelabel/modulelabelinfo/modulelabelinfo.go @@ -125,6 +125,6 @@ func run( return bufprint.PrintEntity( container.Stdout(), format, - bufprint.NewLabelEntity(labels[0], moduleFullName), + bufprint.NewModuleLabelEntity(labels[0], moduleFullName), ) } diff --git a/private/buf/cmd/buf/command/registry/module/modulelabel/modulelabellist/modulelabellist.go b/private/buf/cmd/buf/command/registry/module/modulelabel/modulelabellist/modulelabellist.go index c354a3b9c9..474796fe74 100644 --- a/private/buf/cmd/buf/command/registry/module/modulelabel/modulelabellist/modulelabellist.go +++ b/private/buf/cmd/buf/command/registry/module/modulelabel/modulelabellist/modulelabellist.go @@ -163,7 +163,7 @@ func run( resp.Msg.NextPageToken, nextPageCommand(container, flags, resp.Msg.NextPageToken), slicesext.Map(resp.Msg.Labels, func(label *modulev1.Label) bufprint.Entity { - return bufprint.NewLabelEntity(label, moduleFullName) + return bufprint.NewModuleLabelEntity(label, moduleFullName) }), ) } diff --git a/private/buf/cmd/buf/command/registry/plugin/plugincommit/plugincommitaddlabel/plugincommitaddlabel.go b/private/buf/cmd/buf/command/registry/plugin/plugincommit/plugincommitaddlabel/plugincommitaddlabel.go new file mode 100644 index 0000000000..d8141301a2 --- /dev/null +++ b/private/buf/cmd/buf/command/registry/plugin/plugincommit/plugincommitaddlabel/plugincommitaddlabel.go @@ -0,0 +1,149 @@ +// Copyright 2020-2024 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package plugincommitaddlabel + +import ( + "context" + "fmt" + + pluginv1beta1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/plugin/v1beta1" + "connectrpc.com/connect" + "github.com/bufbuild/buf/private/buf/bufcli" + "github.com/bufbuild/buf/private/buf/bufprint" + "github.com/bufbuild/buf/private/bufpkg/bufparse" + "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin" + "github.com/bufbuild/buf/private/pkg/app/appcmd" + "github.com/bufbuild/buf/private/pkg/app/appext" + "github.com/bufbuild/buf/private/pkg/slicesext" + "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/spf13/pflag" +) + +const ( + formatFlagName = "format" + labelsFlagName = "label" +) + +// NewCommand returns a new Command. +func NewCommand( + name string, + builder appext.SubCommandBuilder, + deprecated string, +) *appcmd.Command { + flags := newFlags() + return &appcmd.Command{ + Use: name + " --label