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

Optimize plugin namespace #139

Merged
merged 3 commits into from
Dec 17, 2024
Merged

Conversation

gladtoeatu
Copy link
Contributor

@gladtoeatu gladtoeatu commented Dec 17, 2024

Summary by CodeRabbit

  • New Features

    • Added an optional description parameter for plugin creation.
    • Enhanced functionality for specifying plugin paths during creation.
  • Bug Fixes

    • Improved error handling for empty plugin names and directory existence checks.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Dec 17, 2024
Copy link

coderabbitai bot commented Dec 17, 2024

Walkthrough

The pull request modifies the CreateCommand class in the AppStore's command system. The changes focus on enhancing the createMineJson method's path handling and expanding the command's configuration by adding an optional description argument. The modifications improve the plugin creation process by providing more flexibility in specifying plugin paths and allowing users to include descriptive information during plugin generation.

Changes

File Change Summary
src/AppStore/src/Command/CreateCommand.php - Updated createMineJson method to handle plugin paths more dynamically
- Modified configure method to add optional description argument
- Maintained existing error handling and command execution logic

Poem

🐰 A Rabbit's Ode to Plugin Creation 🔧

With paths refined and options bright,
Our command now dances with delight
Descriptions bloom, paths softly sway
Creating plugins the nimble way
Code hops forward, elegant and free! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dosubot dosubot bot added the enhancement New feature or request label Dec 17, 2024
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Dec 17, 2024
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 17, 2024
@zds-s
Copy link
Member

zds-s commented Dec 17, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Dec 17, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/AppStore/src/Command/CreateCommand.php (2)

72-75: Add path format validation

While the path handling is improved, consider adding validation for the plugin path format to ensure it follows the expected structure (e.g., vendor/plugin-name).

 public function createMineJson(string $path, string $name, PluginTypeEnum $pluginType): void
 {
     $pluginPath = Str::replace(Plugin::PLUGIN_PATH . '/', '', $path);
+    if (!preg_match('/^[a-z0-9-]+\/[a-z0-9-]+$/', $pluginPath)) {
+        throw new \InvalidArgumentException('Plugin path must follow format: vendor/plugin-name');
+    }
 
     $output = new \stdClass();
     $output->name = $pluginPath ?? $name;

Line range hint 156-160: Maintain consistency in option naming

The shorthand 'desc' for description option differs from the pattern used by other options. Consider using 'description' instead of 'desc' to maintain consistency with other option names.

     $this->addArgument('path', InputArgument::REQUIRED, 'Plugin Path')
         ->addOption('name', 'name', InputOption::VALUE_REQUIRED, 'Plug-in Name')
         ->addOption('type', 'type', InputOption::VALUE_OPTIONAL, 'Plugin type, default mix optional mix,frond,backend')
-        ->addOption('description', 'desc', InputOption::VALUE_OPTIONAL, 'Plug-in Introduction')
+        ->addOption('description', 'description', InputOption::VALUE_OPTIONAL, 'Plug-in Introduction')
         ->addOption('author', 'author', InputOption::VALUE_OPTIONAL, 'Plugin Author Information');
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb88156 and 5c44a2b.

📒 Files selected for processing (1)
  • src/AppStore/src/Command/CreateCommand.php (1 hunks)
🔇 Additional comments (1)
src/AppStore/src/Command/CreateCommand.php (1)

72-75: Verify plugin path usage across the codebase

The changes to plugin path handling might affect existing plugins or related functionality.

✅ Verification successful

Let me check the actual usage of Plugin::PLUGIN_PATH in the files to understand the impact.


Path handling changes are consistent with existing usage

The changes to plugin path handling in CreateCommand.php are consistent with the codebase's existing pattern:

  • AppStoreServiceImpl uses Plugin::PLUGIN_PATH for download/extraction operations
  • InitialCommand uses it for directory creation
  • CreateCommand's path manipulation maintains the expected structure where:
    • Full paths are used for file operations (exists checks, creation)
    • Relative paths are used for namespace and configuration generation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for other uses of Plugin::PLUGIN_PATH and potential impacts
rg -l "Plugin::PLUGIN_PATH" --type php

# Check for existing mine.json files to understand current path patterns
fd -e json mine.json

# Look for other methods that might be affected by the path handling changes
ast-grep --pattern 'function $_(string $path, $_) { $$$ }'

Length of output: 263


Script:

#!/bin/bash
# Check the context of Plugin::PLUGIN_PATH usage in other files
rg "Plugin::PLUGIN_PATH" -B 2 -A 2 --type php

# Check for any path manipulation methods in these files
rg "Str::replace.*path" -B 2 -A 2 --type php

Length of output: 4064

@zds-s zds-s merged commit ccfe015 into mineadmin:3.0 Dec 17, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants