diff --git a/CHANGELOG.md b/CHANGELOG.md index dc2dc40a4d..066c0ab0cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ determinisitic. - Add `buf plugin push` command to push a plugin to the Buf Schema Registry. Only WebAssembly check plugins are supported at this time. +- 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..ad2524707f 100644 --- a/private/buf/bufprint/bufprint.go +++ b/private/buf/bufprint/bufprint.go @@ -199,28 +199,38 @@ 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 { +// NewLabelEntity returns a new label entity to print. It takes a label as an +// interface to allow for modulev1.Label and pluginv1beta1.Label to be passed. +func NewLabelEntity(label interface { + GetName() string + GetCommitId() string + GetCreateTime() *timestamppb.Timestamp + GetArchiveTime() *timestamppb.Timestamp +}, moduleFullName bufparse.FullName) Entity { var archiveTime *time.Time - if label.ArchiveTime != nil { - timeValue := label.ArchiveTime.AsTime() + if label.GetArchiveTime() != nil { + timeValue := label.GetArchiveTime().AsTime() archiveTime = &timeValue } return outputLabel{ - Name: label.Name, - Commit: label.CommitId, - CreateTime: label.CreateTime.AsTime(), + Name: label.GetName(), + Commit: label.GetCommitId(), + CreateTime: label.GetCreateTime().AsTime(), ArchiveTime: archiveTime, - moduleFullName: moduleFullName, + entityFullName: moduleFullName, } } -// NewCommitEntity returns a new commit entity to print. -func NewCommitEntity(commit *modulev1.Commit, moduleFullName bufparse.FullName) Entity { +// NewCommitEntity returns a new commit entity to print. It takes a commit as +// an interface to allow for modulev1.Commit and pluginv1beta1.Commit to be passed. +func NewCommitEntity(commit interface { + GetId() string + GetCreateTime() *timestamppb.Timestamp +}, moduleFullName bufparse.FullName) Entity { return outputCommit{ - Commit: commit.Id, - CreateTime: commit.CreateTime.AsTime(), - moduleFullName: moduleFullName, + Commit: commit.GetId(), + CreateTime: commit.GetCreateTime().AsTime(), + entityFullName: moduleFullName, } } @@ -434,22 +444,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 df33dacabf..f05652382b 100644 --- a/private/buf/cmd/buf/buf.go +++ b/private/buf/cmd/buf/buf.go @@ -82,6 +82,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" @@ -268,6 +272,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/plugin/plugincommit/plugincommitaddlabel/plugincommitaddlabel.go b/private/buf/cmd/buf/command/registry/plugin/plugincommit/plugincommitaddlabel/plugincommitaddlabel.go new file mode 100644 index 0000000000..0cbd41eb2b --- /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