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

fix(client/v2): fix short command description if not set and skip unsupported commands #18324

Merged
merged 13 commits into from
Nov 6, 2023

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Nov 1, 2023

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • run make lint and make test
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Summary by CodeRabbit

  • New Features

    • Introduced a default short description for the buildMethodCommandCommon function if none is provided.
    • Added a version check to the AddMsgServiceCommands function to skip unsupported versions.
    • Added a "burn" command that executes the Burn RPC method.
  • Bug Fixes

    • Updated the "multi-send", "set-send-enabled", and "update-params" commands to execute the correct RPC methods.
  • Tests

    • Added TestIsSupportedVersion and TestParseSinceComment to validate new utility functions.
  • Refactor

    • Enhanced the util package with new functions for retrieving descriptor comments and checking supported versions.

Copy link
Contributor

coderabbitai bot commented Nov 1, 2023

Warning

Rate Limit Exceeded

@julienrbrt has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 13 minutes and 11 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per repository.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 8114d66 and 66a586c.

Walkthrough

The changes introduced in this commit primarily focus on enhancing the functionality of the autocli and util packages in the client. The updates include the addition of new functions, import statements, and checks for supported versions. The changes also modify the behavior of certain commands and introduce new test functions to validate the updated functionality.

Changes

File(s) Summary
client/v2/autocli/common.go The buildMethodCommandCommon function in the Builder struct has been updated to include a new variable short for default short descriptions.
client/v2/autocli/msg.go, client/v2/autocli/query.go New import statements have been added. The functions AddMsgServiceCommands and the loop in query.go now include checks for supported versions using the IsSupportedVersion function from the "util" package.
client/v2/autocli/testdata/help-deprecated.golden, client/v2/autocli/testdata/help-toplevel-msg.golden Changes to the available commands in the code have been made, including deprecation of the "echo" command and addition/modification of several other commands.
client/v2/internal/util/util.go, client/v2/internal/util/util_test.go The util package has been updated with new functions (DescriptorDocs, IsSupportedVersion, parseSinceComment) and tests (TestIsSupportedVersion, TestParseSinceComment). The DescriptorKebabName function has also been modified.

🐇🍂
As the leaves fall, the code evolves,
With new functions, mysteries to solve.
Autumn winds whisper, "Change is near",
And our code responds, shedding old gear.
Echo fades, while Burn ignites,
In the coder's world, filled with bytes.
So let's hop forward, with no fear,
For the season of updates is here! 🍁🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

@julienrbrt julienrbrt added the backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release label Nov 1, 2023
@github-actions github-actions bot added the C:CLI label Nov 1, 2023
@julienrbrt julienrbrt marked this pull request as ready for review November 3, 2023 18:11
@julienrbrt julienrbrt requested a review from a team as a code owner November 3, 2023 18:11
Copy link
Contributor

github-actions bot commented Nov 3, 2023

@julienrbrt your pull request is missing a changelog!

@julienrbrt julienrbrt changed the title fix(client/v2): fix short and long command description if not set fix(client/v2): fix short and long command description if not set and skip unsupported commands Nov 3, 2023
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between cd19bac and a3a2fe6.
Files selected for processing (7)
  • client/v2/autocli/common.go (2 hunks)
  • client/v2/autocli/msg.go (4 hunks)
  • client/v2/autocli/query.go (3 hunks)
  • client/v2/autocli/testdata/help-deprecated.golden (1 hunks)
  • client/v2/autocli/testdata/help-toplevel-msg.golden (1 hunks)
  • client/v2/internal/util/util.go (2 hunks)
  • client/v2/internal/util/util_test.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • client/v2/autocli/testdata/help-deprecated.golden
  • client/v2/internal/util/util_test.go
Additional comments: 12
client/v2/autocli/testdata/help-toplevel-msg.golden (1)
  • 5-14: The changes to the available commands look good. Ensure that the new and modified commands ("burn", "multi-send", "set-send-enabled", "update-params") are working as expected and that their respective RPC methods are correctly implemented.
client/v2/autocli/common.go (2)
  • 27-37: The code is providing default values for short and long descriptions if they are not provided. This is a good practice as it ensures that every command will have a description, improving usability.

  • 49-55: The cobra.Command struct is being populated with the short and long descriptions. This is a good practice as it ensures that every command will have a description, improving usability.

client/v2/autocli/msg.go (4)
  • 3-9: The import of the "runtime/debug" package is new. Ensure that it is used appropriately and that it does not introduce any potential security or performance issues.

  • 16-16: The import of the "cosmossdk.io/client/v2/internal/util" package is new. Ensure that it is used appropriately and that it does not introduce any potential security or performance issues.

  • 79-85: The debug.ReadBuildInfo() function is used to get build information. This is a good practice for version checking, but be aware that it can return false if the binary was not built using the go tool.

  • 98-100: The IsSupportedVersion function is used to check if a version is supported. This is a good practice for ensuring compatibility.

client/v2/autocli/query.go (4)
  • 4-8: The new import "runtime/debug" is used to fetch build information for version compatibility checks. Ensure that this package is compatible with the rest of your codebase.

  • 76-81: The build information is fetched using debug.ReadBuildInfo(). If it fails to fetch the build information, an empty debug.BuildInfo is created. This is a good practice to avoid nil pointer dereference in the subsequent code.

  • 91-100: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [83-96]

The loop iterates over all methods of the service. For each method, it checks if the version is supported using the util.IsSupportedVersion function. If the version is not supported, it skips the current iteration. This is a good practice to ensure compatibility with different versions.

  • 98-100: The BuildQueryMethodCommand function is called to build the command for the method. If there is an error, it is returned immediately. This is a good practice for error handling.
client/v2/internal/util/util.go (1)
  • 1-24: The DescriptorDocs function is marked as not working. If this is still the case, it should be fixed or removed to avoid confusion.
- // TODO this does not work, to fix.
- func DescriptorDocs(descriptor protoreflect.Descriptor) string {
- 	return descriptor.ParentFile().SourceLocations().ByDescriptor(descriptor).LeadingComments
- }

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9c2f464 and 863b63d.
Files selected for processing (7)
  • client/v2/autocli/common.go (2 hunks)
  • client/v2/autocli/msg.go (4 hunks)
  • client/v2/autocli/query.go (3 hunks)
  • client/v2/autocli/testdata/help-deprecated.golden (1 hunks)
  • client/v2/autocli/testdata/help-toplevel-msg.golden (1 hunks)
  • client/v2/internal/util/util.go (2 hunks)
  • client/v2/internal/util/util_test.go (1 hunks)
Files skipped from review due to trivial changes (3)
  • client/v2/autocli/common.go
  • client/v2/autocli/testdata/help-deprecated.golden
  • client/v2/internal/util/util_test.go
Additional comments: 10
client/v2/autocli/testdata/help-toplevel-msg.golden (1)
  • 5-14: The changes to the available commands look good. The addition of the "burn" command and modifications to the "multi-send", "set-send-enabled", and "update-params" commands align with the summary provided. Ensure that these changes are reflected in the corresponding documentation and user guides.
client/v2/autocli/query.go (3)
  • 4-8: The import of "runtime/debug" is new and is used to get build information for version compatibility checks. Ensure that this package is used correctly and safely.

  • 91-100: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [83-96]

The loop iterates over the methods and checks if the version is supported using util.IsSupportedVersion(). If not, it skips the method. This is a good practice to ensure compatibility.

  • 91-96: The util.IsSupportedVersion() function is used to check if the version is supported. Ensure that this function is implemented correctly and handles all edge cases.
client/v2/autocli/msg.go (5)
  • 3-9: The import of "runtime/debug" is new and is used to read build information for version compatibility checks. Ensure that this package is used responsibly as it can expose sensitive information.

  • 14-16: The import of "cosmossdk.io/client/v2/internal/util" is new and is used for the IsSupportedVersion function. Ensure that this package is imported correctly and that the function is available.

  • 76-85: The build information is read and stored in buildInfo. If the build information cannot be read, an empty BuildInfo struct is created. This is a good practice to prevent nil pointer dereferences later in the code.

  • 98-100: The IsSupportedVersion function is used to check if the version in the method descriptor's comments is supported. If it is not, the loop continues to the next iteration. This is a good practice to prevent unsupported versions from being used.

  • 102-104: The BuildMsgMethodCommand function is used to build a command for the method. If there is an error, it is returned immediately. This is a good practice to prevent further execution in the case of an error.

client/v2/internal/util/util.go (1)
  • 1-24: The DescriptorDocs function is marked as not working. If this is still the case, it should be fixed or removed to avoid confusion.
- // TODO this does not work, to fix.
- func DescriptorDocs(descriptor protoreflect.Descriptor) string {
- 	return descriptor.ParentFile().SourceLocations().ByDescriptor(descriptor).LeadingComments
- }

client/v2/autocli/query.go Outdated Show resolved Hide resolved
client/v2/internal/util/util.go Outdated Show resolved Hide resolved
client/v2/internal/util/util.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 863b63d and ebef8d4.
Files selected for processing (4)
  • client/v2/autocli/msg.go (2 hunks)
  • client/v2/autocli/query.go (1 hunks)
  • client/v2/internal/util/util.go (2 hunks)
  • client/v2/internal/util/util_test.go (1 hunks)
Additional comments: 9
client/v2/autocli/msg.go (3)
  • 12-18: The new import statement for the "util" package is correctly placed in alphabetical order.

  • 86-91: The check for supported versions using the "IsSupportedVersion" function is correctly implemented. It correctly skips the loop iteration if the method descriptor is not supported.

if !util.IsSupportedVersion(util.DescriptorDocs(methodDescriptor)) {
	continue
}
  • 93-95: Error handling is correctly implemented for the "BuildMsgMethodCommand" function.
methodCmd, err := b.BuildMsgMethodCommand(methodDescriptor, methodOpts)
if err != nil {
	return err
}
client/v2/internal/util/util.go (6)
  • 1-13: The new imports "regexp" and "runtime/debug" are added correctly and are used in the code. The global variable buildInfo is also initialized correctly.

  • 15-18: The global variable buildInfo is used to store build information. This is a good use of a global variable as it allows the build information to be accessed throughout the package without having to read it multiple times.

  • 20-23: The function DescriptorKebabName is correctly implemented and returns the kebab case name of a descriptor.

  • 36-38: The function ResolveMessageType correctly resolves a message type from a descriptor.

  • 40-44: The function IsSupportedVersion correctly determines if a RPC is supported in the current version.

  • 46-68: The function isSupportedVersion correctly checks if a RPC is supported based on the build information. It also correctly handles the case where the input is empty or the build information is nil.

client/v2/autocli/query.go Show resolved Hide resolved
client/v2/internal/util/util_test.go Outdated Show resolved Hide resolved
client/v2/internal/util/util.go Outdated Show resolved Hide resolved
@julienrbrt julienrbrt changed the title fix(client/v2): fix short and long command description if not set and skip unsupported commands fix(client/v2): fix short command description if not set and skip unsupported commands Nov 4, 2023
Copy link
Collaborator

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

Nice work and thank you @julienrbrt! LGTM, but just some tightening needed around parsing "// Since"

client/v2/internal/util/util.go Outdated Show resolved Hide resolved
input = strings.ToLower(input)
input = strings.ReplaceAll(input, "cosmos sdk", "cosmos-sdk")

re := regexp.MustCompile(`\/\/\s?since: (\S+) (\S+)`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment above says "Since", yet this regex uses "since", but we aren't using the case insensitive flag "(?i)" We could simply use "[sS]ince". I highly recommend removing the strings.ToLower then simply using that regexp suggestion that I've made. This way if some module's name is for example PbValidator, it won't be returned as "pbvalidator"

Copy link
Member Author

@julienrbrt julienrbrt Nov 5, 2023

Choose a reason for hiding this comment

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

Case insensitive definitely makes sense, but I am getting that with strings.ToLower.
Additionally, I actually really need to get the module name lowercase to match it properly with the build info.
Lastly, it is easier to replace any writing of CosMoS SdK / Cosmos-SDK -> cosmos-sdk that way.

client/v2/internal/util/util.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ebef8d4 and 8114d66.
Files selected for processing (2)
  • client/v2/internal/util/util.go (2 hunks)
  • client/v2/internal/util/util_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • client/v2/internal/util/util_test.go

client/v2/internal/util/util.go Show resolved Hide resolved
client/v2/internal/util/util.go Show resolved Hide resolved
client/v2/internal/util/util.go Show resolved Hide resolved
client/v2/internal/util/util.go Show resolved Hide resolved
client/v2/internal/util/util.go Outdated Show resolved Hide resolved
input = strings.ToLower(input)
input = strings.ReplaceAll(input, "cosmos sdk", "cosmos-sdk")

re := regexp.MustCompile(`\/\/\s*since: (\S+) (\S+)`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh btw I forgot to mention, given that this is a regex from a constant string, let's hoist it out to be a global variable per https://cyber.orijtech.com/scsec/cosmos-go-coding-guide#real-world-exhibit-in-the-cosmos-sdk

Copy link
Member Author

@julienrbrt julienrbrt Nov 5, 2023

Choose a reason for hiding this comment

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

Want to make a PR to https://github.com/cosmos/awesome-cosmos#articles to add this guide?
I forgot about it. Bookmarking now :)

client/v2/internal/util/util.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @julienrbrt!

@julienrbrt julienrbrt added this pull request to the merge queue Nov 6, 2023
Merged via the queue into main with commit 9c0256e Nov 6, 2023
59 of 60 checks passed
@julienrbrt julienrbrt deleted the julien/autocli-comments branch November 6, 2023 11:21
mergify bot pushed a commit that referenced this pull request Nov 6, 2023
julienrbrt added a commit that referenced this pull request Nov 6, 2023
…upported commands (backport #18324) (#18371)

Co-authored-by: Julien Robert <julien@rbrt.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release C:CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants