Skip to content

Added ssh cmd to lagoon helper.#65

Merged
richardgaunt merged 2 commits intomainfrom
feature/add-ssh-cmd
Sep 5, 2025
Merged

Added ssh cmd to lagoon helper.#65
richardgaunt merged 2 commits intomainfrom
feature/add-ssh-cmd

Conversation

@richardgaunt
Copy link
Owner

@richardgaunt richardgaunt commented Aug 25, 2025

Checklist before requesting a review

  • This PR does not have an associated ticket
  • I have provided information in section about WHY something was done if this was not a normal implementation
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have run new and existing relevant tests locally with my changes, and they passed
  • I have provided screenshots, where applicable

Changed

  1. Added ssh cmd generator.

Screenshots

Summary by CodeRabbit

  • New Features

    • Added an “SSH to Environment” action in the interactive CLI: choose project/environment (PR context shown when available), optionally specify a container, receive a ready-to-run SSH command, view usage tips, and continue after confirmation.
  • Chores

    • Added a clipboard integration dependency to enable copying generated SSH commands to the clipboard.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 25, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds an "SSH to Environment" interactive CLI action that selects an environment and container, generates an SSH command via a new API function, and optionally copies it to the clipboard. Adds clipboardy dependency. getSSHCommand was added but duplicated in src/lagoon-api.mjs.

Changes

Cohort / File(s) Summary
Dependency update
package.json
Added runtime dependency clipboardy@^4.0.0.
Interactive CLI flow
src/interactive.mjs
Added “SSH to Environment” action and sshToEnvironmentFlow: loads environments, presents options (with PR context), prompts for container (default cli), calls getSSHCommand, displays { command, message }, optionally copies command to clipboard, and waits for confirmation.
API: SSH command builder
src/lagoon-api.mjs
Added and exported getSSHCommand(instance, project, environment, container = null) returning { command, message }. The function appears twice in the file (duplicate declaration).

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant CLI as Interactive CLI
  participant API as Lagoon API
  participant CB as Clipboard (optional)

  U->>CLI: Start CLI & choose "SSH to Environment"
  CLI->>API: getEnvironments(project)
  API-->>CLI: environments list
  CLI->>U: prompt select environment
  U-->>CLI: selects environment
  CLI->>U: prompt container name (default "cli")
  U-->>CLI: provides container or accepts default

  CLI->>API: getSSHCommand(instance, project, environment, container)
  API-->>CLI: { command, message }
  CLI->>U: display command and message
  alt user chooses to copy
    CLI->>CB: copy command
    CB-->>CLI: copy result
  end
  CLI->>U: prompt press Enter to continue
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit taps the terminal bright,
Picks an env, a container, a light.
An SSH line appears in the glen—
Clipboard ready, hop in then!
Two twins found; one trimmed, and we run again. 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2bd7af2 and c08de4c.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • package.json (1 hunks)
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/add-ssh-cmd

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

🧹 Nitpick comments (4)
package.json (1)

23-23: Clipboard support looks good; dynamic import in the flow keeps startup light.

No issues adding clipboardy@^4.0.0. The interactive flow imports it dynamically, so users without a clipboard provider won’t be blocked. Consider marking clipboardy as optionalDependency if you expect headless CI installs to skip it, but this is non-blocking.

src/lagoon-api.mjs (1)

353-375: Optional: guard user-entered target with a safe charset to avoid malformed commands.

Although we only display the command (not execute it), validating target to something like ^[a-zA-Z0-9_.-]+$ reduces surprises and aligns with the earlier branch-name validation style.

If you’d like, I can add a small validator and unit tests for getSSHCommand covering service vs container and message text.

src/interactive.mjs (2)

550-629: Clarify printed instructions to match lagoon ssh behavior.

After adopting --conn-string in getSSHCommand, the returned message will explain that running the command prints the actual ssh ... connection string, which the user then runs. That avoids the current impression that running lagoon ssh ... directly opens the session. (uselagoon.github.io)


603-622: Clipboard UX: solid fallback, minor refinement available.

The dynamic import/try-catch is great. If you want to further reduce noise in headless environments, you could gate the “Copy to clipboard?” prompt behind a successful import, which your current structure already effectively does—so this is just a thumbs-up.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0640e0f and 2bd7af2.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/interactive.mjs (4 hunks)
  • src/lagoon-api.mjs (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: richardgaunt
PR: richardgaunt/lagoon-cli-wrapper#8
File: src/lagoon-api.js:0-0
Timestamp: 2025-05-07T10:29:17.490Z
Learning: Security improvement: Lagoon CLI commands should use Node.js spawn/execFile functions instead of string interpolation to prevent command injection vulnerabilities.
Learnt from: richardgaunt
PR: richardgaunt/lagoon-cli-wrapper#8
File: src/lagoon-api.js:0-0
Timestamp: 2025-05-07T10:29:17.490Z
Learning: Security improvement: Lagoon CLI commands should use Node.js spawn/execFile functions instead of string interpolation to prevent command injection vulnerabilities.
🔇 Additional comments (4)
src/lagoon-api.mjs (1)

353-375: No duplicate getSSHCommand declaration found

I’ve verified that getSSHCommand is declared only once in src/lagoon-api.mjs (line 363) and is merely imported and used in src/interactive.mjs (lines 14–16 and 597–598). There is no second definition elsewhere in the codebase, so the original summary about a duplicate declaration is incorrect.

Likely an incorrect or invalid review comment.

src/interactive.mjs (3)

14-16: Import additions look fine.

The new import of getSSHCommand is correct and localizes SSH command generation to the API layer.


92-94: Main switch integration is clean.

Adding a dedicated sshToEnvironment action follows the existing pattern and avoids coupling with other flows.


198-199: Menu label is clear and discoverable.

Good phrasing; it mirrors the action name used in the switch.

@richardgaunt richardgaunt merged commit 709bbf6 into main Sep 5, 2025
2 of 3 checks passed
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.

1 participant