Skip to content

Add remote branch option#196

Merged
yamadashy merged 7 commits intoyamadashy:mainfrom
huy-trn:add_branch_option
Dec 10, 2024
Merged

Add remote branch option#196
yamadashy merged 7 commits intoyamadashy:mainfrom
huy-trn:add_branch_option

Conversation

@huy-trn
Copy link
Contributor

@huy-trn huy-trn commented Dec 9, 2024

Draft Implementation as proposed in #195

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 9, 2024

Caution

Review failed

The head commit changed during the review from 5662450 to 66b6e73.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces enhancements to the handling of branches in repository cloning operations within the CLI. Key changes include the addition of a branch parameter to the runRemoteAction, cloneRepository, and execGitShallowClone functions, allowing users to specify a branch when executing these commands. The CliOptions interface is also updated to include a branch property, and corresponding command-line options are added. Tests for the execGitShallowClone function are updated to validate the new branching functionality.

Changes

File Change Summary
src/cli/actions/remoteAction.ts Updated runRemoteAction to use options.branch. Modified cloneRepository to accept an optional branch.
src/cli/cliRun.ts Added branch?: string; to CliOptions. Introduced command-line option --remote-branch <name>.
src/core/file/gitCommand.ts Updated execGitShallowClone to accept an optional branch parameter and modify the git clone command.
tests/core/file/gitCommand.test.ts Enhanced tests for execGitShallowClone to include branch handling and updated expectations for command checks.

Possibly related issues

Possibly related PRs


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. (Experiment)
  • @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.

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.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (5)
src/core/file/gitCommand.ts (1)

24-24: Add type validation for branch parameter

Consider adding validation to ensure the branch name follows git's branch naming conventions to prevent invalid inputs.

-  branch?:string,
+  branch?: string,
src/cli/cliRun.ts (2)

27-27: Fix interface property spacing

Maintain consistent spacing in the interface definition.

- branch?:string;
+ branch?: string;

48-48: Enhance branch option description

The current description could be more informative about valid inputs and usage.

- .option('--branch <name>', 'select a specific branch or commit id')
+ .option('--branch <name>', 'specify the branch name, tag, or commit hash to clone (defaults to repository default branch)')
tests/core/file/gitCommand.test.ts (1)

67-75: Improve test organization and descriptions

The test descriptions could be more specific about the scenarios being tested.

- test('should execute without branch option if not specified by user', async () => {
+ test('should execute git clone without -b flag when branch is undefined', async () => {
src/cli/actions/remoteAction.ts (1)

Line range hint 81-82: Consider adding branch information to logging

For better debugging and visibility, consider logging the branch information when cloning the repository.

-  logger.log(`Clone repository: ${url} to temporary directory. ${pc.dim(`path: ${directory}`)}`);
+  logger.log(`Clone repository: ${url}${branch ? ` (branch: ${branch})` : ''} to temporary directory. ${pc.dim(`path: ${directory}`)}`);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 05589f7 and 07454e2.

📒 Files selected for processing (4)
  • src/cli/actions/remoteAction.ts (3 hunks)
  • src/cli/cliRun.ts (2 hunks)
  • src/core/file/gitCommand.ts (1 hunks)
  • tests/core/file/gitCommand.test.ts (1 hunks)
🔇 Additional comments (2)
src/cli/actions/remoteAction.ts (2)

76-79: LGTM! Well-structured function signature

The addition of the optional branch parameter is implemented correctly, following TypeScript best practices with proper typing and parameter ordering.


85-85: Verify execGitShallowClone implementation

The branch parameter is correctly passed to execGitShallowClone. Let's verify its implementation to ensure proper handling of the branch parameter.

✅ Verification successful

Branch parameter is properly handled in execGitShallowClone

The implementation in src/core/file/gitCommand.ts correctly handles the branch parameter:

  • It accepts an optional branch parameter
  • When branch is provided, it adds -b ${branch} to the git clone command
  • When branch is not provided, it omits the branch option
  • The implementation is well-tested as evidenced by the test cases in tests/core/file/gitCommand.test.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify execGitShallowClone implementation handles branch parameter correctly
ast-grep --pattern 'export const execGitShallowClone = async (url: string, directory: string, branch?: string) {
  $$$
}'

Length of output: 123


Script:

#!/bin/bash
# Let's try a different approach to find the execGitShallowClone implementation
# First, let's search for the function name without type annotations
ast-grep --pattern 'execGitShallowClone = async ($$$) {
  $$$
}'

# As a backup, let's also use ripgrep to find the implementation
rg "execGitShallowClone" -A 10

Length of output: 8295

Copy link

@standard-input standard-input bot left a comment

Choose a reason for hiding this comment

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

No issues flagged.
Standard Input can make mistakes. Check important info.

@codecov
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.64%. Comparing base (05589f7) to head (66b6e73).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #196      +/-   ##
==========================================
+ Coverage   91.63%   91.64%   +0.01%     
==========================================
  Files          35       35              
  Lines        1949     1952       +3     
  Branches      439      439              
==========================================
+ Hits         1786     1789       +3     
  Misses        163      163              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yamadashy
Copy link
Owner

Hi, @tranquochuy645
I've made some minor tweaks, but it works perfectly!
Thank you for your contribution!
Merging this.

Really appreciate your help!

Note: I'll address the npm vulnerabilities in a separate PR.

@yamadashy yamadashy merged commit 18dd4bf into yamadashy:main Dec 10, 2024
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.

2 participants