Skip to content

Conversation

@robindiddams
Copy link
Member

@robindiddams robindiddams commented May 26, 2025

Summary by CodeRabbit

  • New Features
    • Added an optional --org-id flag to the project list and delete commands, allowing users to filter projects by organization when listing or deleting.

@robindiddams robindiddams requested a review from jhaynie May 26, 2025 14:26
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 26, 2025

Walkthrough

The changes add a listProjects helper function to filter projects by orgId, used in list and delete commands to centralize filtering. The --org-id flag is registered for these commands, enabling organization-specific project operations.

Changes

File(s) Change Summary
cmd/project.go Added listProjects function; registered --org-id flag for list, delete, and create commands; updated commands to use the new filtering logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant API

    User->>CLI: project list --org-id=<orgId>
    CLI->>API: Fetch all projects
    API-->>CLI: Return project list
    CLI->>CLI: Filter projects by orgId (if provided)
    CLI-->>User: Display filtered list

    User->>CLI: project delete --org-id=<orgId>
    CLI->>API: Fetch all projects
    API-->>CLI: Return project list
    CLI->>CLI: Filter projects by orgId (if provided)
    CLI->>API: Delete filtered projects
    CLI-->>User: Confirm deletion
Loading

Poem

In the garden of code, a new flag grows,
Filtering projects where the right orgId shows.
Listing and deleting, now neat and precise,
Rabbits rejoice—organization feels nice!
With a hop and a skip, the CLI’s now spry,
Thanks to a flag that lets orgs specify! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

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

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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: 0

🧹 Nitpick comments (3)
cmd/project.go (3)

733-734: Handle potential GetString flag errors instead of discarding them

Although cmd.Flags().GetString() is unlikely to fail at runtime (the flag should exist), the call still returns an error value that is currently ignored. Propagating or at least logging this error will make unexpected flag-table issues far easier to diagnose.

-orgId, _ := cmd.Flags().GetString("org-id")
+orgId, err := cmd.Flags().GetString("org-id")
+if err != nil {
+	logger.Fatalf("unable to read --org-id flag: %v", err)
+}

741-749: Factor out and validate the organisation-filtering logic

  1. Efficiency / DRY – The slice-filter loop is fine, but we are already allocating a new slice and doing the copy for the happy path (orgId == "").
    A concise pattern avoids duplication:
filtered := make([]project.ProjectListData, 0, len(unfilteredProjects))
for _, p := range unfilteredProjects {
    if orgId == "" || p.OrgId == orgId {
        filtered = append(filtered, p)
    }
}
projects = filtered
  1. Better UX for invalid IDs – If the user supplies an --org-id that does not belong to them (or is mistyped), projects ends up empty and we just show “no projects found”. Consider surfacing a clearer message:
if orgId != "" && len(projects) == 0 {
    tui.ShowWarning("no projects found for organization %s", orgId)
    return
}

This prevents silent confusion when a typo is made.


897-897: Flag added only to delete – confirm if list should also accept --org-id

The new flag is registered for project delete, but the project list command does not currently expose or honour the same flag, even though that might be equally useful. If this is intentional, please disregard; otherwise, consider adding:

projectListCmd.Flags().String("org-id", "", "Only list the projects in the specified organization")

…and apply filtering similar to the delete path.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between deb31c9 and a9d3159.

📒 Files selected for processing (1)
  • cmd/project.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test CLI Upgrade Path (windows-latest)

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

🧹 Nitpick comments (1)
cmd/project.go (1)

901-906: Consider moving the hidden flag configuration closer to related flags.

The hidden flag configuration for projectImportCmd is positioned between the list and delete flag configurations. For better code organization, consider grouping all flag configurations for each command together.

+	// hidden because they must be all passed together and we havent documented that
+	projectImportCmd.Flags().MarkHidden("name")
+	projectImportCmd.Flags().MarkHidden("description")
+	projectImportCmd.Flags().MarkHidden("org-id")
+
 	projectDeleteCmd.Flags().String("org-id", "", "Only delete the projects in the specified organization")
-
-	// hidden because they must be all passed together and we havent documented that
-	projectImportCmd.Flags().MarkHidden("name")
-	projectImportCmd.Flags().MarkHidden("description")
-	projectImportCmd.Flags().MarkHidden("org-id")
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a9d3159 and fecfdd3.

📒 Files selected for processing (1)
  • cmd/project.go (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test CLI Upgrade Path (windows-latest)
🔇 Additional comments (4)
cmd/project.go (4)

613-628: LGTM! Well-designed helper function with proper error handling.

The listProjects function effectively centralizes the filtering logic and provides a clean abstraction. The implementation correctly handles the case where no orgId filter is applied by returning all projects, and properly filters when an orgId is specified.


654-658: Good refactoring to use the centralized filtering logic.

The list command now properly retrieves the org-id flag and delegates to the new listProjects helper function, which ensures consistent filtering behavior across commands.


747-751: Excellent implementation of organization filtering in delete command.

This change successfully addresses the PR objective by adding --org-id filter support to the project delete command. The implementation mirrors the pattern used in the list command, ensuring consistency.


888-888: Appropriate flag registration for the list command.

The org-id flag is properly registered with a clear description that explains its filtering purpose.

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

🧹 Nitpick comments (1)
cmd/project.go (1)

613-628: Good implementation of the filtering helper function.

The listProjects function properly centralizes the organization filtering logic and handles the empty orgId case correctly. The error handling is appropriate.

However, consider validating the provided orgId to give users better feedback when they specify an invalid organization ID.

Consider adding orgId validation to provide better user experience:

 func listProjects(ctx context.Context, logger logger.Logger, apiUrl string, apikey string, orgId string) []project.ProjectListData {
 	unfilteredProjects, err := project.ListProjects(ctx, logger, apiUrl, apikey)
 	if err != nil {
 		errsystem.New(errsystem.ErrApiRequest, err, errsystem.WithContextMessage("Failed to list projects")).ShowErrorAndExit()
 	}
 	if orgId == "" {
 		return unfilteredProjects
 	}
+	
+	// Check if any projects exist for the specified orgId
+	hasMatchingOrg := false
+	for _, project := range unfilteredProjects {
+		if project.OrgId == orgId {
+			hasMatchingOrg = true
+			break
+		}
+	}
+	
 	var projects []project.ProjectListData
 	for _, project := range unfilteredProjects {
 		if project.OrgId == orgId {
 			projects = append(projects, project)
 		}
 	}
+	
+	// If no projects found but we have projects in other orgs, suggest the orgId might be invalid
+	if len(projects) == 0 && len(unfilteredProjects) > 0 && !hasMatchingOrg {
+		logger.Warn("No projects found for organization '%s'. Use 'agentuity organization list' to see available organizations.", orgId)
+	}
+	
 	return projects
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fecfdd3 and b981732.

📒 Files selected for processing (1)
  • cmd/project.go (7 hunks)
🔇 Additional comments (5)
cmd/project.go (5)

630-638: Clean enhancement to support organization-specific messaging.

The modification to showNoProjects function properly handles both filtered and unfiltered cases, providing appropriate messaging based on whether an organization filter is applied.


658-658: Proper integration of organization filtering in list command.

The changes correctly integrate the new listProjects function and pass the orgId parameter consistently throughout the command execution.

Also applies to: 662-662, 671-671


751-752: Consistent implementation of organization filtering in delete command.

The delete command properly adopts the same pattern as the list command, ensuring consistent behavior across project management operations.

Also applies to: 755-755, 771-771


892-892: Appropriate flag registration for organization filtering.

The --org-id flag is properly registered for both list and delete commands with clear descriptions that match their functionality.

Also applies to: 910-910


905-909:

Details

✅ Verification successful

Verify the necessity of marking org-id as hidden for import command.

The org-id flag is marked as hidden for the import command along with other flags. Based on the comment, this is because all these flags must be passed together and aren't documented for individual use.

Verify that the org-id flag behavior is intentional for the import command:


🏁 Script executed:

#!/bin/bash
# Description: Check if org-id flag is used in import command logic and verify its hidden status is appropriate

# Search for org-id usage in import command
ast-grep --pattern $'func (cmd *cobra.Command, args []string) {
  $$$
  orgId, _ := cmd.Flags().GetString("org-id")
  $$$
}'

# Look for other hidden flags in import command for consistency
rg -A 10 -B 2 "MarkHidden.*org-id"

Length of output: 15030


Confirmed intentional hiding of org-id for headless import

The org-id flag in cmd/project.go is only read in the headless‐import branch (when name, description, api-key and org-id are all provided together). Hiding it alongside name and description prevents users from seeing undocumented, multi‐flag only options in help output. No changes required.

• cmd/project.go – projectImportCmd.Flags().MarkHidden("org-id") (with "name" and "description") aligns with the headless import logic.

@robindiddams robindiddams merged commit 2a61017 into main May 26, 2025
14 checks passed
@robindiddams robindiddams deleted the org-id-rm-filter branch May 26, 2025 14:56
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