Skip to content

Create organization during cloak command#42

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-41
Draft

Create organization during cloak command#42
Copilot wants to merge 2 commits intomainfrom
copilot/fix-41

Conversation

Copy link
Contributor

Copilot AI commented Jun 9, 2025

When running the cloak command for the first time in a repo where the user doesn't have access to the required organization, the system now automatically attempts to create the organization before failing.

Changes Made

1. Created PostOrganization API Service

  • Added src/lib/api/postOrganization.js - handles POST requests to /api/organization endpoint
  • Follows existing API patterns using undici request library
  • Includes proper error handling with buildApiError

2. Enhanced Cloak Service Logic

  • Modified src/lib/services/cloak.js to attempt organization creation when no matching organization is found
  • The new flow:
    1. Loops through existing organizations to find a match
    2. If no match found, attempts to create the organization using the repo's slug
    3. Re-syncs user data to get the newly created organization
    4. Sets up organization keypairs for the first time
    5. Falls back to original error handling if creation fails

3. Added Test Coverage

  • Created tests/lib/api/postOrganization.test.js to validate the new API service
  • All existing tests continue to pass

Behavior

Before: Running dotenvx pro cloak would fail with organizationNotConnected error when the user wasn't connected to an organization matching the repo's slug.

After: The system attempts to create the missing organization automatically. If successful, the cloak operation continues. If creation fails, it falls back to the original error message.

This maintains backwards compatibility while providing a smoother user experience for first-time usage.

Fixes #41.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: motdotla <3848+motdotla@users.noreply.github.com>
Copilot AI changed the title [WIP] Create organization during cloak command Create organization during cloak command Jun 9, 2025
Copilot AI requested a review from motdotla June 9, 2025 18:27
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.

Create organization during cloak command

2 participants