Skip to content
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

Fix: vercelSyncEnvVars teamId #1463

Merged
merged 6 commits into from
Nov 12, 2024

Conversation

nneven
Copy link
Contributor

@nneven nneven commented Nov 8, 2024

Closes https://discord.com/channels/1066956501299777596/1303601937282895943/1304512833056411759

✅ Checklist

  • I have followed every step in the contributing guide
  • The PR title follows the convention.
  • I ran and tested the code works

Testing

  1. Configured VERCEL_TEAM_ID environment variable
  2. Tested vercelSyncEnvVars with:
  • Default env vars (VERCEL_TEAM_ID)
  • Explicitly passed teamId option
  1. Verified environment variables sync correctly with team projects

Changelog

  • Renamed syncVercelEnvVars to vercelSyncEnvVars to match documentation
  • Added support for team projects in vercelSyncEnvVars by introducing teamId option
  • Updated documentation in multiple files to include VERCEL_TEAM_ID requirement for team projects
  • Added teamId parameter to URL when making Vercel API requests
  • Created new changeset for minor version bump

Screenshots

[Screenshots]

💯

Summary by CodeRabbit

  • New Features

    • Introduced teamId option for vercelSyncEnvVars, enhancing environment variable management for team projects.
    • Added new lifecycle functions in the configuration to allow custom logic execution at various stages of task execution.
    • Expanded build configuration options for greater customization, including new extensions for managing additional files and packages.
  • Documentation

    • Updated guides to clarify the requirement of VERCEL_TEAM_ID for syncing environment variables in team projects.
    • Enhanced setup instructions for integrating Trigger.dev with Next.js, including detailed revalidation handler examples.

Copy link

changeset-bot bot commented Nov 8, 2024

🦋 Changeset detected

Latest commit: 2b2ed57

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@trigger.dev/build Minor
trigger.dev Minor
@trigger.dev/core Minor
@trigger.dev/react-hooks Minor
@trigger.dev/sdk Minor
@trigger.dev/database Minor
@trigger.dev/otlp-importer Minor
@internal/redis-worker Patch
@internal/zod-worker Patch
@internal/testcontainers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Nov 8, 2024

Walkthrough

The changes in this pull request introduce enhancements to the vercelSyncEnvVars functionality by adding a teamId option, allowing for improved management of environment variables in team contexts. Additionally, the documentation has been updated to reflect new lifecycle functions, configuration options, and build extensions in the trigger.config.ts file, as well as clarifications regarding environment variable requirements for team projects in the Vercel integration guides.

Changes

File Path Change Summary
.changeset/rotten-dolphins-punch.md Added teamId option to vercelSyncEnvVars functionality.
docs/config/config-file.mdx Updated documentation for trigger.config.ts with new lifecycle functions, runtime options, and build extensions.
docs/guides/examples/vercel-sync-env-vars.mdx Clarified setup requirements for syncing environment variables, including VERCEL_TEAM_ID.
docs/guides/frameworks/nextjs.mdx Enhanced setup guide for Next.js, adding VERCEL_TEAM_ID requirement and revalidation handler instructions.
packages/build/src/extensions/core/vercelSyncEnvVars.ts Renamed function to vercelSyncEnvVars and updated signature to include vercelTeamId.

Possibly related PRs

Suggested reviewers

  • matt-aitken
  • nicktrn

🐇 In the meadow, changes bloom,
A teamId added, dispelling gloom.
With configs updated, tasks align,
Environment variables, now divine!
In Next.js, we set the stage,
For a brighter, organized page! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

@nneven nneven changed the title Update vercelSyncEnvVars.ts Fix: vercelSyncEnvVars teamId Nov 8, 2024
@nneven nneven marked this pull request as ready for review November 10, 2024 00:34
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

🧹 Outside diff range and nitpick comments (6)
.changeset/rotten-dolphins-punch.md (1)

1-5: Enhance the changeset description with more details.

While the version bump is appropriate for the new feature, the description could be more comprehensive to help users understand the changes and requirements better.

Consider expanding the description like this:

---
"@trigger.dev/build": minor
---

-Add teamId option to vercelSyncEnvVars
+Add teamId support to vercelSyncEnvVars
+
+- Add `teamId` option to support Vercel team projects
+- Rename function from `syncVercelEnvVars` to `vercelSyncEnvVars`
+- Requires `VERCEL_TEAM_ID` environment variable for team projects
docs/guides/examples/vercel-sync-env-vars.mdx (1)

16-17: LGTM! Clear documentation of the new team project requirement.

The addition of the VERCEL_TEAM_ID requirement for team projects is well-documented and placed appropriately within the existing note block.

Consider adding a link to Vercel's documentation on how to find the team ID, similar to how you've linked to the access token page. This would make it easier for users to locate this information.

-  build extension. If you're working with a team project, you'll also need to set `VERCEL_TEAM_ID`. 
+  build extension. If you're working with a team project, you'll also need to set `VERCEL_TEAM_ID` 
+  (found in your [team settings](https://vercel.com/teams/select)). 
packages/build/src/extensions/core/vercelSyncEnvVars.ts (2)

13-14: Consider adding validation for vercelTeamId

While the fallback chain is well-implemented, consider adding validation for the teamId format when present, similar to how projectId and vercelAccessToken are validated. This would help catch configuration issues early.

    const vercelTeamId = options?.vercelTeamId ?? process.env.VERCEL_TEAM_ID ??
      ctx.env.VERCEL_TEAM_ID;
+   if (vercelTeamId && !/^team_[a-zA-Z0-9]+$/.test(vercelTeamId)) {
+     console.warn("vercelSyncEnvVars: The provided teamId may be invalid. Expected format: team_*");
+   }

42-44: Consider making the Vercel API base URL configurable

The URL construction using URLSearchParams is well-implemented. However, consider making the base URL configurable for testing purposes or future API version changes.

+   const VERCEL_API_BASE = options?.apiBaseUrl ?? "https://api.vercel.com/v8";
    const params = new URLSearchParams({ decrypt: "true" });
    if (vercelTeamId) params.set("teamId", vercelTeamId);
-   const vercelApiUrl = `https://api.vercel.com/v8/projects/${projectId}/env?${params}`;
+   const vercelApiUrl = `${VERCEL_API_BASE}/projects/${projectId}/env?${params}`;

Update the options type to include:

type Options = {
  projectId?: string;
  vercelAccessToken?: string;
  vercelTeamId?: string;
+ apiBaseUrl?: string;
}
docs/guides/frameworks/nextjs.mdx (1)

254-257: LGTM with a minor suggestion for clarity.

The addition of the VERCEL_TEAM_ID requirement for team projects is clear and well-documented. The information is correctly placed within the environment variables section.

Consider adding a link to Vercel's documentation about finding the team ID, similar to how you've linked to the access token page. This would make it easier for users to locate their team ID. Here's a suggested revision:

  working with a team project, you'll also need to set `VERCEL_TEAM_ID`. You can find / generate
- the `VERCEL_ACCESS_TOKEN` in your Vercel [dashboard](https://vercel.com/account/settings/tokens).
+ the `VERCEL_ACCESS_TOKEN` in your Vercel [dashboard](https://vercel.com/account/settings/tokens) and
+ find your team ID in the [team settings](https://vercel.com/teams/select).
  Make sure the scope of the token covers the project you want to sync.
docs/config/config-file.mdx (1)

514-517: Documentation looks good but could be more detailed.

The addition of VERCEL_TEAM_ID documentation is clear and well-placed. However, consider these enhancements for better clarity:

  1. Explicitly state whether VERCEL_TEAM_ID is mandatory for team projects
  2. Add an example showing how to pass teamId explicitly as an argument
  3. Include a link to the Vercel team settings page for finding the team ID

Consider updating the text to include an example:

  Make sure the scope of the token covers the project you want to sync.
+ 
+ For team projects, you can either set the `VERCEL_TEAM_ID` environment variable or pass it explicitly:
+ 
+ ```ts
+ vercelSyncEnvVars({
+   teamId: "team_yourTeamId"  // Optional: Override VERCEL_TEAM_ID environment variable
+ })
+ ```
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 71808fa and 2b2ed57.

📒 Files selected for processing (5)
  • .changeset/rotten-dolphins-punch.md (1 hunks)
  • docs/config/config-file.mdx (1 hunks)
  • docs/guides/examples/vercel-sync-env-vars.mdx (1 hunks)
  • docs/guides/frameworks/nextjs.mdx (1 hunks)
  • packages/build/src/extensions/core/vercelSyncEnvVars.ts (2 hunks)
🔇 Additional comments (2)
packages/build/src/extensions/core/vercelSyncEnvVars.ts (2)

Line range hint 4-44: Verify error handling in team context

The implementation looks solid overall. However, let's ensure proper error handling when using team-specific endpoints.

#!/bin/bash
# Search for any existing error handling patterns with team contexts
rg "teamId.*error|error.*teamId" --type ts

# Look for any existing tests involving team scenarios
rg "test.*team|describe.*team" --type test

4-5: Function signature change looks good!

The rename from syncVercelEnvVars to vercelSyncEnvVars and the addition of the optional vercelTeamId parameter are well-implemented.

Let's verify if there are any existing imports of the old function name that need updating:

✅ Verification successful

Function rename is safe to proceed

The function rename from syncVercelEnvVars to vercelSyncEnvVars is well-implemented. The only references found are:

  • The function definition file itself: packages/build/src/extensions/core/vercelSyncEnvVars.ts
  • A barrel file that re-exports it: packages/build/src/extensions/core.ts

The barrel file is already using the new name in its export statement, indicating the rename was properly implemented across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to the old function name
rg "syncVercelEnvVars" --type ts

Length of output: 118


Script:

#!/bin/bash
# Search for any references to the function name (both old and new) in TypeScript files
rg "vercelSyncEnvVars|syncVercelEnvVars" --type ts -l

# Search for import statements containing either function name
ast-grep --pattern 'import { $_ } from $_'

Length of output: 194


Script:

#!/bin/bash
# Let's check the content of core.ts to see how the function is used
cat packages/build/src/extensions/core.ts

Length of output: 284

Copy link

pkg-pr-new bot commented Nov 12, 2024

@trigger.dev/build

pnpm add https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/build@1463

@trigger.dev/react-hooks

pnpm add https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/react-hooks@1463

trigger.dev

pnpm add https://pkg.pr.new/triggerdotdev/trigger.dev@1463

@trigger.dev/sdk

pnpm add https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/sdk@1463

@trigger.dev/core

pnpm add https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/core@1463

commit: 2b2ed57

@D-K-P D-K-P merged commit a5d59de into triggerdotdev:main Nov 12, 2024
10 checks passed
@nneven nneven deleted the fix-vercel-sync-env-vars branch November 14, 2024 16:15
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