-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add command add-project
#4
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
Conversation
WalkthroughA new CLI command for adding a project and associating GitHub organizations was introduced. Supporting API client functions, TypeScript types, and test fixtures were added. The test suite was expanded to cover the new functionality. A new runtime dependency for string parsing was included in the project. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant APIClient
participant API
User->>CLI: add-project --name <name> --github-orgs <urls>
CLI->>APIClient: createProject(name)
APIClient->>API: POST /projects
API-->>APIClient: Project details or error
APIClient-->>CLI: Project details or error
alt Project created
loop For each githubOrgUrl
CLI->>APIClient: addGithubOrgToProject(projectId, githubOrgUrl)
APIClient->>API: POST /projects/:id/github-orgs
API-->>APIClient: Org details or error
APIClient-->>CLI: Org details or error
end
end
CLI-->>User: Success or error messages
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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)
src/cli-commands.ts (1)
40-59: LGTM! Consider handling partial success scenarios.The implementation correctly handles sequential processing to avoid race conditions and provides proper error handling. However, if GitHub organization addition fails after project creation, the project will remain in a partially configured state.
Consider documenting this behavior or implementing cleanup logic for failed GitHub organization additions.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (7)
package.json(1 hunks)src/__tests__/cli-commands.test.ts(3 hunks)src/__tests__/fixtures.ts(1 hunks)src/api-client.ts(2 hunks)src/cli-commands.ts(2 hunks)src/index.ts(2 hunks)src/types.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
src/__tests__/fixtures.ts (1)
src/types.ts (3)
APIHealthResponse(8-13)APIProjectDetails(76-106)APIGithubOrgDetails(18-71)
src/__tests__/cli-commands.test.ts (3)
src/__tests__/fixtures.ts (3)
mockApiHealthResponse(3-8)mockAPIProjectResponse(10-40)mockAPIGithubOrgResponse(42-95)src/types.ts (3)
APIProjectDetails(76-106)APIGithubOrgDetails(18-71)APIErrorResponse(121-127)src/cli-commands.ts (1)
addProjectWithGithubOrgs(40-59)
src/api-client.ts (1)
src/types.ts (3)
APIHealthResponse(8-13)APIProjectDetails(76-106)APIGithubOrgDetails(18-71)
src/cli-commands.ts (2)
src/types.ts (1)
CommandResult(136-139)src/api-client.ts (2)
createProject(21-35)addGithubOrgToProject(37-54)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: Test on ubuntu-latest with Node 22.x
- GitHub Check: Test on macOS-latest with Node 22.x
- GitHub Check: Test on macOS-latest with Node 24.x
- GitHub Check: Test on windows-latest with Node 20.x
- GitHub Check: Test on windows-latest with Node 24.x
- GitHub Check: Test on ubuntu-latest with Node 24.x
- GitHub Check: Test on windows-latest with Node 18.x
- GitHub Check: Test on windows-latest with Node 22.x
🔇 Additional comments (14)
package.json (1)
41-41: Verify the dependency version and security status.The added dependency should be checked for the latest version and any known security vulnerabilities.
What is the latest version of @ulisesgascon/string-to-array npm package and are there any known security vulnerabilities?src/types.ts (1)
15-127: LGTM! Comprehensive and well-structured type definitions.The new interfaces provide excellent type safety with proper nullable field handling and follow TypeScript best practices. The APIGithubOrgDetails interface comprehensively covers GitHub organization metadata, while APIProjectDetails handles the extensive policy configuration options appropriately.
src/index.ts (1)
32-32: Clarify the GitHub organization URL processing logic.The pattern
stringToArray(options.githubOrgs[0])is confusing - it takes the first element of an array and then converts it to an array. This suggests the command line parsing might not be working as expected.Verify how Commander.js handles the
<githubOrgUrls...>option and whether this processing is correct:#!/bin/bash # Verify how Commander.js processes array options and the string-to-array library usage rg -A 10 -B 5 "githubOrgs\[0\]" rg -A 5 -B 5 "stringToArray"src/__tests__/fixtures.ts (1)
1-95: LGTM! Comprehensive test fixtures with proper typing.The fixtures provide excellent test data coverage with realistic values and proper TypeScript typing. The dynamic timestamps using
new Date().toISOString()are appropriate for test scenarios and ensure fresh data for each test run.src/api-client.ts (4)
3-3: LGTM: Import statement updated correctly.The new types
APIProjectDetailsandAPIGithubOrgDetailsare properly imported to support the new functions.
16-16: LGTM: Enhanced error message with status code and response body.The improved error handling provides more debugging context by including the HTTP status code and response body.
21-35: Well-implemented function with proper error handling.The
createProjectfunction correctly:
- Uses proper TypeScript typing
- Handles the 409 conflict case with a meaningful error message
- Uses
throwHttpErrors: falsefor manual error handling- Returns strongly typed response
37-54: Comprehensive error handling for GitHub organization addition.The
addGithubOrgToProjectfunction properly handles multiple error scenarios:
- 409 (organization already exists)
- 404 (project not found)
- Other HTTP errors with detailed messages
The implementation follows the same pattern as
createProjectand maintains consistency.src/__tests__/cli-commands.test.ts (6)
3-6: LGTM: Imports properly updated for new functionality.The imports correctly include the new function under test, required types, and fixture mocks to support the expanded test coverage.
36-36: Good refactoring: Using fixture instead of inline mock data.The change to use
mockApiHealthResponsefixture improves test maintainability and consistency.
88-108: Well-structured test setup with proper beforeEach initialization.The test setup correctly:
- Cleans nock mocks between tests
- Uses fixtures to create consistent test data
- Creates variations of mock data for different test scenarios
110-135: Comprehensive happy path test with proper verification.The test correctly:
- Mocks all required API endpoints
- Verifies the success response structure
- Uses
nock.isDone()to ensure all mocked endpoints were called- Tests with multiple GitHub organizations
137-153: Good error handling test for project creation failure.The test properly verifies:
- Error response structure matches expected format
- Error message contains relevant details (project name)
- Success flag is correctly set to false
155-176: ```shell
#!/bin/bashLocate the implementation of addProjectWithGithubOrgs and inspect its error handling
rg -n "addProjectWithGithubOrgs" -C 20 src
</details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Related #1
Summary by CodeRabbit