Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bufplugin package #3431

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Add bufplugin package #3431

wants to merge 12 commits into from

Conversation

emcfarlane
Copy link
Contributor

@emcfarlane emcfarlane commented Oct 29, 2024

This adds a new package, bufplugin, which implements types and functions for operating on Buf plugins. It is similar to the bufmodule package for modules.

Parsing of full names and refs has been split out into a separate package from bufmodule called bufparse. This exposes two types FullName and Ref which replace ModuleFullName and ModuleRef and is used by both. Methods ModuleFullName() ModuleFullName and ModuleRef() ModuleRef have been renamed to FullName() bufparse.FullName and Ref() bufparse.Ref.

The error type ParseError returned from Parse.* methods have been moved to the single type bufparse.ParseError updating the packages bufcas, bufmodule and bufplugin.

Copy link
Contributor

github-actions bot commented Oct 29, 2024

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedOct 30, 2024, 9:14 PM

@@ -0,0 +1,83 @@
// Copyright 2020-2024 Buf Technologies, Inc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this stuff was being pulled out to a common bufparse package? Also would likely result in some of errors.go being pulled out (and potentially other stuff).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did look at pulling it out into bufparse but reverted in 477557f. I noticed we already had another ParseError type in bufcas so thought copying was more consistent. Will refactor back out to a package.

}

// ParsePluginFullName parses a PluginFullName from a string in the form "registry/owner/name".
func ParsePluginFullName(pluginFullNameString string) (PluginFullName, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assume this would be pulled out to a ParseFullName for example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has now been pulled out into bufparse.ParseFullName and returns a type of bufparse.FullName. Updated the PR docs.

Copy link
Member

@doriable doriable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this change seems very reasonable -- it's more of a refactor to unifying the types and then adding the plugin types. We should discuss whether it makes sense to have digest and commit as shared types instead also. There could even be an argument to be made for Key to be a single interface that bufmodule and bufplugin each implement with its own semantics (e.g. restrictions on digest types, etc.).

Comment on lines 51 to 52
// TODO: this is dumb
return nil, NewInvalidPathError(format, path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bufparse.ParseRef only returns an error from the util parseRefComponents, which only ever returns a ParseError. To keep it consistent for now, we should continuing to return the invalid path error, but in the future, we should consider returning ParseError where appropriate from buffetch.

Comment on lines +53 to +58
// ParseDigestType parses a DigestType from its string representation.
//
// This reverses DigestType.String().
//
// Returns an error of type *bufparse.ParseError if the string could not be parsed.
func ParseDigestType(s string) (DigestType, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had an offline conversation about whether DigestType should also be a shared package (e.g. bufpkg/bufdigest), since this is also duplicated across modules and plugins. The respective keys (e.g. ModuleKey and PluginKey) types would control for the digest type at the time of construction. Our conclusion is that this makes sense, but should it be done as a follow-up PR given the size of the migration of Ref/FullName?

@@ -75,15 +76,15 @@ func (d DigestType) String() string {
//
// This reverses DigestType.String().
//
// Returns an error of type *ParseError if thie string could not be parsed.
// Returns an error of type *bufparse.ParseError if the string could not be parsed.
func ParseDigestType(s string) (DigestType, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment in bufplugin/digest.go: we considered splitting digest into its own shared package. Looking at this, it does make sense, but maybe it should be done in a follow-up.

Comment on lines +32 to +41
// NewCommit returns a new Commit.
func NewCommit(
pluginKey PluginKey,
getCreateTime func() (time.Time, error),
) Commit {
return newCommit(
pluginKey,
getCreateTime,
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to digest, it might make sense to split Commit into its own package as well. Same question/concern around whether that should be a follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants