Skip to content

feat: add zeabur service search-repo command#233

Merged
leechenghsiu merged 3 commits intomainfrom
matthewlee/des-534-search-repo-command
May 4, 2026
Merged

feat: add zeabur service search-repo command#233
leechenghsiu merged 3 commits intomainfrom
matthewlee/des-534-search-repo-command

Conversation

@leechenghsiu
Copy link
Copy Markdown
Contributor

@leechenghsiu leechenghsiu commented May 1, 2026

Expose Git repository search as a standalone non-interactive command, so the skilled agent can search repos via bash without interactive mode.

DES-534

Description (required)

Related issues & labels (optional)

  • Closes #
  • Suggested label:

View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

Summary by CodeRabbit

  • New Features
    • Added a new search-repo command to query Git repositories by keyword.
    • Accepts the keyword as a command argument or, when omitted, prompts interactively.
    • Returns results as either a JSON array or a formatted plaintext list showing owner/name and repository ID.
    • Gracefully reports when no repositories match the query or when a search fails.

Expose Git repository search as a standalone non-interactive command,
so the skilled agent can search repos via bash without interactive mode.

DES-534

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@leechenghsiu leechenghsiu self-assigned this May 1, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bc097cf9-9b94-44d7-bea9-5cc9e0379f0e

📥 Commits

Reviewing files that changed from the base of the PR and between 6a0d615 and 3ac1699.

📒 Files selected for processing (1)
  • internal/cmd/service/search-repo/search_repo.go
✅ Files skipped from review due to trivial changes (1)
  • internal/cmd/service/search-repo/search_repo.go

Walkthrough

Adds a new Cobra CLI subcommand search-repo (optional keyword; prompts interactively if omitted), calls ApiClient.SearchGitRepositories, and prints results as JSON or plaintext. The subcommand is registered under the service root command.

Changes

Search repository CLI

Layer / File(s) Summary
Command Definition
internal/cmd/service/search-repo/search_repo.go
Adds NewCmdSearchRepo(f *cmdutil.Factory) *cobra.Command defining search-repo [keyword] with cobra.RangeArgs(0,1) and execution via runSearchRepo.
Keyword Resolution / Prompting
internal/cmd/service/search-repo/search_repo.go
Resolves optional keyword arg; if empty requires interactive mode, prompts via f.Prompter.Input, trims whitespace, and returns keyword is required when empty or non-interactive.
API Invocation & Error Wrapping
internal/cmd/service/search-repo/search_repo.go
Calls f.ApiClient.SearchGitRepositories(cmd.Context(), &keyword) and wraps API errors as search repositories failed: %w.
Output Handling
internal/cmd/service/search-repo/search_repo.go
If no repos: returns f.Printer.JSON([]any{}) when f.JSON true, otherwise logs No repositories found for "<keyword>". If repos present: returns JSON when f.JSON or prints owner/name (ID: N) lines.
Service Command Integration
internal/cmd/service/service.go
Imports and registers the new search-repo subcommand in NewCmdService.

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI as "service search-repo"
    participant Prompter as "Prompter (f.Prompter)"
    participant API as "ApiClient.SearchGitRepositories"
    participant Output

    User->>CLI: run `search-repo [keyword]?`
    alt no keyword and interactive
        CLI->>Prompter: prompt for keyword
        Prompter-->>CLI: returns keyword
    end
    CLI->>API: SearchGitRepositories(ctx, keyword)
    API-->>CLI: repos / error
    alt error
        CLI->>Output: print wrapped error
    else no repos
        CLI->>Output: print JSON [] or "No repositories found" message
    else repos
        CLI->>Output: print JSON or lines "owner/name (ID: N)"
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add zeabur service search-repo command' directly and clearly describes the main change: adding a new CLI command for searching Git repositories.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch matthewlee/des-534-search-repo-command

Review rate limit: 4/5 reviews remaining, refill in 12 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
internal/cmd/service/search-repo/search_repo.go (1)

57-59: ⚡ Quick win

Prefer f.Printer for plaintext output consistency.

At Line 57-59, direct fmt.Printf bypasses the shared printer abstraction used in this command (f.Printer.JSON) and reduces output consistency/testability across commands.

Proposed patch
-	for _, repo := range repos {
-		fmt.Printf("%s/%s (ID: %d)\n", repo.Owner, repo.Name, repo.ID)
-	}
+	rows := make([][]string, 0, len(repos))
+	for _, repo := range repos {
+		rows = append(rows, []string{
+			fmt.Sprintf("%s/%s", repo.Owner, repo.Name),
+			fmt.Sprintf("%d", repo.ID),
+		})
+	}
+	f.Printer.Table([]string{"Repository", "ID"}, rows)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/cmd/service/search-repo/search_repo.go` around lines 57 - 59,
Replace the direct use of fmt.Printf in the repository loop with the command's
shared printer to keep output consistent and testable: in the loop that iterates
over repos (the block using fmt.Printf("%s/%s (ID: %d)\n", repo.Owner,
repo.Name, repo.ID)), call the printer on f (e.g., f.Printer.Printf or
f.Printer.Println with the same formatted string) so plaintext output goes
through the same abstraction used by f.Printer.JSON.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/cmd/service/search-repo/search_repo.go`:
- Around line 29-38: The prompt handling for keyword in SearchGitRepositories
currently accepts empty/whitespace input; after calling f.Prompter.Input("Enter
search keyword:", "") you should trim whitespace from the returned k (e.g.,
strings.TrimSpace) and validate it is non-empty; if it is empty, return the same
error used for non-interactive flow (fmt.Errorf("keyword is required")) or
re-prompt as desired so blank input cannot proceed to SearchGitRepositories.
Update the block around f.Prompter.Input in search_repo.go to perform this
trim-and-check on k before assigning to keyword.

---

Nitpick comments:
In `@internal/cmd/service/search-repo/search_repo.go`:
- Around line 57-59: Replace the direct use of fmt.Printf in the repository loop
with the command's shared printer to keep output consistent and testable: in the
loop that iterates over repos (the block using fmt.Printf("%s/%s (ID: %d)\n",
repo.Owner, repo.Name, repo.ID)), call the printer on f (e.g., f.Printer.Printf
or f.Printer.Println with the same formatted string) so plaintext output goes
through the same abstraction used by f.Printer.JSON.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b6ab0015-0ee9-467c-afce-0f4f1d134657

📥 Commits

Reviewing files that changed from the base of the PR and between bcb65be and 83c4aa3.

📒 Files selected for processing (2)
  • internal/cmd/service/search-repo/search_repo.go
  • internal/cmd/service/service.go

Comment thread internal/cmd/service/search-repo/search_repo.go
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@leechenghsiu leechenghsiu requested a review from a team May 2, 2026 04:14
@canyugs
Copy link
Copy Markdown
Contributor

canyugs commented May 3, 2026

Consolidated Review Summary

Reviewed by 4 parties (CodeRabbit + 3 internal reviewers + AI agent).

⚠️ Suggested fix before merge

Positional keyword arg is not trimmed (internal/cmd/service/search-repo/search_repo.go:18-21)

The interactive path trims input via strings.TrimSpace(k), but the CLI-arg path does not:

if len(args) > 0 {
    keyword = args[0]   // not trimmed
}

Running zeabur service search-repo " " bypasses the empty check and sends a whitespace string to SearchGitRepositories, inconsistent with interactive mode.

Fix: trim once at the top of runSearchRepo, then check for empty:

keyword = strings.TrimSpace(keyword)
if keyword == "" {
    if !f.Interactive { ... }
    // existing prompt logic
}

🟡 Non-blocking suggestions (follow-up OK)

  • Use f.Printer instead of raw fmt.Printf for plaintext output (consistency with other commands)
  • Add doc comment on runSearchRepo (docstring coverage)
  • Fix import order in internal/cmd/service/service.go (search-repo should come after restart alphabetically; goimports will fix)
  • Add unit tests for runSearchRepo (empty/whitespace/valid keyword paths)

🟢 Already addressed

  • Interactive prompt validates trimmed empty input
  • cmd.Context() propagation
  • JSON empty result handled

LGTM after the trim fix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@leechenghsiu
Copy link
Copy Markdown
Contributor Author

Fixed: positional keyword arg is now trimmed via strings.TrimSpace.

@leechenghsiu leechenghsiu merged commit ee134a7 into main May 4, 2026
5 checks passed
@leechenghsiu leechenghsiu deleted the matthewlee/des-534-search-repo-command branch May 4, 2026 02:49
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