Skip to content

Conversation

@roderik
Copy link
Member

@roderik roderik commented Oct 7, 2024

Summary by Sourcery

Add a new 'codegen' command to the CLI for generating GraphQL and REST types and queries. Enhance environment variable handling by allowing overrides and defaulting to 'development'. Update the CI workflow to refine the file pattern for version updates.

New Features:

  • Introduce a new 'codegen' command in the CLI to generate GraphQL and REST types and queries for different environments.

Enhancements:

  • Add support for overriding environment variables when loading them, with a default fallback to 'development'.
  • Include the environment name in the .env file paths dynamically, removing the need to pass it explicitly.

CI:

  • Update the CI workflow to exclude 'package.json' files from the file pattern used for version updates.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 7, 2024

Reviewer's Guide by Sourcery

This pull request implements a new 'codegen' command in the CLI, enhances environment handling, and updates the connect command. It introduces GraphQL schema generation for different endpoints (Hasura, Portal, TheGraph) and improves the way environment variables are managed and written.

Sequence diagram for the codegen command execution

sequenceDiagram
    actor User
    participant CLI as CLI
    participant CodegenCommand as CodegenCommand
    participant GqltadaSpinner as GqltadaSpinner
    participant Terminal as Terminal
    participant LoadEnv as LoadEnv

    User ->> CLI: Run codegen command
    CLI ->> CodegenCommand: Execute codegenCommand()
    CodegenCommand ->> Terminal: intro()
    CodegenCommand ->> LoadEnv: loadEnv()
    LoadEnv -->> CodegenCommand: env
    CodegenCommand ->> GqltadaSpinner: gqltadaSpinner(env)
    GqltadaSpinner -->> CodegenCommand: Codegen complete
    CodegenCommand ->> Terminal: outro()
Loading

Sequence diagram for the updated connect command

sequenceDiagram
    actor User
    participant CLI as CLI
    participant ConnectCommand as ConnectCommand
    participant WriteEnvSpinner as WriteEnvSpinner
    participant Terminal as Terminal

    User ->> CLI: Run connect command
    CLI ->> ConnectCommand: Execute connectCommand()
    ConnectCommand ->> WriteEnvSpinner: writeEnvSpinner(env)
    WriteEnvSpinner -->> ConnectCommand: Env written
    ConnectCommand ->> Terminal: outro()
Loading

File-Level Changes

Change Details Files
Implement new 'codegen' command
  • Add new 'codegen' command to CLI
  • Create gqltadaSpinner function for GraphQL schema generation
  • Implement GraphQL schema generation for Hasura, Portal, and TheGraph endpoints
packages/cli/src/cli.ts
packages/cli/src/commands/codegen.ts
packages/cli/src/commands/codegen/gqltada.spinner.ts
Enhance environment variable handling
  • Add SETTLEMINT_ENVIRONMENT to env object
  • Update loadEnvironmentEnv function to handle environment override
  • Modify writeEnv function to use environment from env object
packages/cli/src/commands/connect.ts
packages/utils/src/environment/load-env.ts
packages/utils/src/environment/write-env.ts
Update connect command implementation
  • Refactor writeEnvSpinner function to use env object for environment
  • Update error handling in loadEnvironmentEnv function
packages/cli/src/commands/connect/write-env.spinner.ts
packages/utils/src/environment/load-env.ts
Add utility functions
  • Add 'run' function for executing shell commands
  • Export 'run' function in terminal utilities
packages/utils/src/terminal/run.ts
packages/utils/src/terminal.ts
Update CI/CD configuration
  • Modify file pattern for commit in GitHub Actions workflow
.github/workflows/build.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added the feat New feature label Oct 7, 2024
@github-actions
Copy link

github-actions bot commented Oct 7, 2024

📦 Packages

Package Version
SDK Cli @settlemint/sdk-cli@0.5.0-pr01c66e2
SDK The Graph @settlemint/sdk-thegraph@0.5.0-pr01c66e2
SDK Portal @settlemint/sdk-portal@0.5.0-pr01c66e2
SDK Hasura @settlemint/sdk-hasura@0.5.0-pr01c66e2
SDK JS @settlemint/sdk-js@0.5.0-pr01c66e2
SDK Utils @settlemint/sdk-utils@0.5.0-pr01c66e2

@roderik roderik merged commit 8414ba7 into main Oct 7, 2024
@roderik roderik deleted the feat/codegen branch October 7, 2024 08:05
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @roderik - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Review instructions: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

* "development"
* );
*/
export async function gqltadaSpinner(env: DotEnv) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider refactoring gqltadaCodegen to reduce repetition in the switch statement

You could create a configuration object that maps types to their respective settings, reducing the need for the switch statement and making it easier to add new types in the future.

export async function gqltadaSpinner(env: DotEnv) {
  const typeConfigs = {
    HASURA: { /* Hasura-specific config */ },
    APOLLO: { /* Apollo-specific config */ },
    // Add other types here
  };

  await gqltadaCodegen(typeConfigs[env.GQLTADA_TYPE] || {});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants