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

feat(version): Add extraInfo to version cmd #18063

Merged
merged 15 commits into from
Oct 30, 2023
Merged

feat(version): Add extraInfo to version cmd #18063

merged 15 commits into from
Oct 30, 2023

Conversation

samricotta
Copy link
Contributor

@samricotta samricotta commented Oct 11, 2023

Description

Allow apps to provide extra information to version command through ExtraInfo field

Closes: #11690


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:

  • Enhanced the software's information handling capabilities by introducing an ExtraInfo feature. This allows the software to store and retrieve additional information provided by apps, improving the overall user experience by providing more context-specific data.

Tests:

  • Implemented tests to ensure the correct functioning of the new ExtraInfo feature, ensuring that the software reliably handles the additional information.

This update increases the software's versatility and adaptability, making it more valuable for users who require a more context-aware application.

cmdContext := context.WithValue(rootCmd.Context(), "extraInfo", extraInfo)
rootCmd.SetContext(cmdContext)

rootCmd.AddCommand(version.NewVersionCommand())
Copy link
Member

Choose a reason for hiding this comment

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

we might not need this as it's already being added by server.AddCommands

) {
cfg := sdk.GetConfig()
cfg.Seal()

cmdContext := context.WithValue(rootCmd.Context(), "extraInfo", extraInfo)
Copy link
Member

Choose a reason for hiding this comment

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

the context key should probably be a struct instead of a string.

@samricotta samricotta marked this pull request as ready for review October 11, 2023 13:12
@samricotta samricotta requested a review from a team as a code owner October 11, 2023 13:12
simapp/simd/cmd/commands.go Outdated Show resolved Hide resolved
version/command.go Outdated Show resolved Hide resolved
version/version_test.go Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

you are missing an update in root.go, that's why the build is failing

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

can we get a paragraph in docs for this and upgrading.md entry?

@julienrbrt julienrbrt changed the title chore: Add extraInfo to version cmd feat(version): Add extraInfo to version cmd Oct 12, 2023
@julienrbrt
Copy link
Member

julienrbrt commented Oct 12, 2023

upgrading.md entry?

IMHO, there is no upgrading.md needed, as it is an optional feature. We could revert everything from simapp here, and let people who want to use it, do that directly in their app. Imho, given that we set empty extra info, this is the best to revert simapp changes and add good go doc above NewVersionCommand() with a snippet.

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

utACK. Let's add some extended go doc in NewVersionCommand.

@tac0turtle
Copy link
Member

gentle ping on adding this feature into the docs

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2023

Walkthrough

This update introduces a new feature to the Info struct, allowing it to support additional information via the ExtraInfo field. The changes include the addition of new types, functions, and tests to handle the extraction and storage of this extra information from the context.

Changes

File Summary
CHANGELOG.md Added a new feature to the Info struct to support extra information.
version/command.go Introduced a new function extraInfoFromContext to extract extra information from the context.
version/version.go Added new types ContextKey and ExtraInfo for storing extra information in the context and the Info struct.
version/version_test.go Added tests to create and retrieve ExtraInfo from the context.

🐇

"In the land of code, where the shadows lie,

An update comes, under the digital sky.

With extra info, the Info struct grows,

A new feature blooms, like a binary rose. 🌹"


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.json

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: 6
Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between faca642 and 0e66412.
Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • version/command.go (3 hunks)
  • version/version.go (3 hunks)
  • version/version_test.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
Additional comments (Suppressed): 2
version/version.go (2)
  • 26-28: The ContextKey struct is defined but not used anywhere in the provided hunks. Ensure that it is used in the rest of the codebase, otherwise, it's an unnecessary declaration.

  • 74-74: The ExtraInfo field is added to the Info struct. This is a good way to extend the existing structure with additional information. However, it's important to ensure that all code that creates or manipulates Info objects is updated to handle the ExtraInfo field correctly. Also, since ExtraInfo is a pointer, make sure to check for nil before accessing it to avoid potential runtime errors.

Comment on lines +18 to +22
// Note: When seeking to add the extra info to the context
// The below can be added to the initRootCmd to include the extraInfo field
//
// cmdContext := context.WithValue(context.Background(), version.ContextKey{}, extraInfo)
// rootCmd.SetContext(cmdContext)
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment provides instructions on how to add extra info to the context. However, it would be more maintainable and less error-prone if this was handled by the function itself, rather than requiring the caller to do it. Consider refactoring NewVersionCommand to accept an ExtraInfo parameter, which it can then add to the context.

Comment on lines +36 to +38
// Extract and set extra information from the context
extraInfo := extraInfoFromContext(cmd)
verInfo.ExtraInfo = &extraInfo
Copy link
Contributor

Choose a reason for hiding this comment

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

The extraInfoFromContext function is used to extract extra information from the context. However, there is no error handling if the context does not contain ExtraInfo. This could lead to unexpected behavior if the context is not properly initialized. Consider adding error handling or a default value for ExtraInfo.

version/command.go Show resolved Hide resolved
Comment on lines +61 to +63
// ExtraInfo contains a set of extra information provided by apps
type ExtraInfo map[string]string

Copy link
Contributor

Choose a reason for hiding this comment

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

The ExtraInfo type is defined as a map of string to string. This is a flexible structure that can hold various types of information. However, it might be worth considering if a more structured approach would be beneficial, especially if there are specific pieces of information that will always be included in the ExtraInfo. If that's the case, a struct with specific fields might be a better choice.

version/version_test.go Outdated Show resolved Hide resolved
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

please add mention of this in the docs

@samricotta
Copy link
Contributor Author

@tac0turtle Julien mentions to put them in the godocs, which has been updated here: https://github.com/cosmos/cosmos-sdk/pull/18063/files#diff-dfe56fc35673357926b86baaac4cedf6b197fea52180ec4710437bcef5c24e1bR18

Do you mean something in addition to this?

@tac0turtle
Copy link
Member

a small addition to the documentation which would be hosted on our page in order to show this feature exsits

@tac0turtle tac0turtle dismissed their stale review October 30, 2023 20:56

can do this at a later time

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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0e66412 and 20bc6f8.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional comments: 1
CHANGELOG.md (1)
  • 70-70: The changelog entry is clear and provides a good summary of the changes made in the PR. It includes the issue number for easy tracking and describes the changes in a user-friendly manner.

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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 20bc6f8 and 05efcb3.
Files selected for processing (1)
  • version/version_test.go (3 hunks)
Additional comments: 1
version/version_test.go (1)
  • 158-178: The test case for the new feature is well written. It checks that the ExtraInfo is correctly retrieved from the context and that the value of a specific key in the ExtraInfo is as expected. It also checks that the command execution does not result in an error and that the output is as expected.

@@ -1,13 +1,13 @@
package version_test

import (
context "context"
Copy link
Contributor

Choose a reason for hiding this comment

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

The import of the context package is redundant as it's already included in the standard library and doesn't need to be aliased. You can directly use context.Background() or context.WithValue() without importing it explicitly.

- context "context"

Commitable suggestion (Beta)
Suggested change
context "context"
# context package is already included in the standard library
# You can directly use context.Background() or context.WithValue() without importing it explicitly.

@tac0turtle tac0turtle added this pull request to the merge queue Oct 30, 2023
Merged via the queue into main with commit 88b7666 Oct 30, 2023
56 of 57 checks passed
@tac0turtle tac0turtle deleted the sam/extra-info branch October 30, 2023 21:35
atheeshp pushed a commit that referenced this pull request Nov 1, 2023
Co-authored-by: Marko <marbar3778@yahoo.com>
@julienrbrt
Copy link
Member

@Mergifyio backport release/v0.50.x

Copy link
Contributor

mergify bot commented Nov 10, 2023

backport release/v0.50.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Nov 10, 2023
Co-authored-by: Marko <marbar3778@yahoo.com>
(cherry picked from commit 88b7666)

# Conflicts:
#	CHANGELOG.md
julienrbrt added a commit that referenced this pull request Nov 10, 2023
Co-authored-by: samricotta <37125168+samricotta@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
@faddat faddat mentioned this pull request Nov 8, 2024
12 tasks
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.

Allow apps to provide extra information to version command
6 participants