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

enhancement(billing): ensure typescript & esm syntax #2687

Merged
merged 4 commits into from
Nov 27, 2024

Conversation

p6l-richard
Copy link
Contributor

@p6l-richard p6l-richard commented Nov 26, 2024

CleanShot 2024-11-26 at 14 09 25

What does this PR do?

  • update the draftSections LLM prompts to include a guideline for code snippets
  • fixes a nit to order the Q/A pairs (see this PR)
  • updates the create-pr workflow to re-use pending PRs

Fixes # (issue)
CleanShot 2024-11-26 at 13 26 06@2x
CleanShot 2024-11-26 at 13 26 10@2x

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

CleanShot 2024-11-26 at 14 14 35@2x

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

Summary by CodeRabbit

  • New Features

    • Enhanced PR management by checking for open PRs before creating new ones.
    • Added guidelines for drafting content using TypeScript and ESM syntax.
  • Bug Fixes

    • Improved error handling for existing entries in the drafting process.
  • Chores

    • Updated dependencies for improved performance and compatibility.

Copy link

changeset-bot bot commented Nov 26, 2024

⚠️ No Changeset found

Latest commit: 4515ac0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link

vercel bot commented Nov 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 26, 2024 1:22pm

Copy link

vercel bot commented Nov 26, 2024

@p6l-richard is attempting to deploy a commit to the Unkey Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Nov 26, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request include updates to the package.json file for the billing application, specifically incrementing the versions of three @trigger.dev packages and adding a new dependency. Additionally, two TypeScript files have been modified: create-pr.ts, which enhances the logic for managing pull requests, and draft-sections.ts, which introduces new guidelines for drafting content in TypeScript syntax. The modifications streamline processes and clarify code representation standards.

Changes

File Path Change Summary
apps/billing/package.json - Updated dependencies: @trigger.dev/nextjs, @trigger.dev/sdk, @trigger.dev/slack from 3.2.0 to 3.2.1.
- Added new dependency: @types/js-yaml with version ^4.0.9.
apps/billing/src/trigger/glossary/create-pr.ts - Enhanced createPrTask function: added sorting for YAML keys, improved PR handling logic, updated commit messages, and modified return statement.
apps/billing/src/trigger/glossary/draft-sections.ts - Updated draftSectionsTask function: added guidelines for TypeScript and ESM syntax in code snippets.

Possibly related PRs

Suggested labels

Bug, 🕹️ oss.gg, :joystick: 150 points, hacktoberfest

Suggested reviewers

  • mcstepp
  • chronark
  • perkinsjr

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.

Copy link
Contributor

github-actions bot commented Nov 26, 2024

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.
Here is an example:

<type>[optional scope]: <description>
fix: I fixed something for Unkey

Details:

Unknown release type "enhancement" found in pull request title "enhancement(billing): ensure typescript & esm syntax". 

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

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

🧹 Outside diff range and nitpick comments (2)
apps/billing/src/trigger/glossary/draft-sections.ts (2)

154-156: Consider improving prompt formatting for better readability.

The indentation of the new guidelines differs from other items in the list. Consider maintaining consistent indentation for better maintainability.

 9. Code Snippets
-  - When you include code snippets in JavaScript, make sure to always use TypeScript syntax.
-  - Ensure that you always use ESM syntax and not CommonJS syntax (ie use import/export and not 'require').
+   - When you include code snippets in JavaScript, make sure to always use TypeScript syntax.
+   - Ensure that you always use ESM syntax and not CommonJS syntax (ie use import/export and not 'require').

Line range hint 1-156: Consider adding type safety for OpenAI model names.

The OpenAI model names are currently passed as string literals. Consider adding type safety to prevent potential typos or invalid model names.

// Add an enum or const object for model names
const OPENAI_MODELS = {
  GPT4_TURBO: "gpt-4-turbo",
  GPT4_MINI: "gpt-4o-mini",
} as const;

type OpenAIModel = typeof OPENAI_MODELS[keyof typeof OPENAI_MODELS];

// Update the model parameter usage
model: openai(OPENAI_MODELS.GPT4_TURBO)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a87fbbc and 4515ac0.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • apps/billing/package.json (1 hunks)
  • apps/billing/src/trigger/glossary/create-pr.ts (5 hunks)
  • apps/billing/src/trigger/glossary/draft-sections.ts (1 hunks)
🔇 Additional comments (3)
apps/billing/package.json (2)

28-28: LGTM! TypeScript type definitions added for js-yaml.

Adding @types/js-yaml aligns with the PR objective of ensuring TypeScript compatibility. The version (^4.0.9) correctly matches the major version of the runtime js-yaml dependency (^4.1.0).


25-27: LGTM! Verify the changelog for @trigger.dev packages.

The patch version updates (3.2.0 → 3.2.1) for @trigger.dev packages look good. All packages are kept in sync at the same version.

✅ Verification successful

Patch update (3.2.0 → 3.2.1) includes React hooks improvements and Zod upgrade

The changelog shows that version 3.2.1 includes:

  • React hooks now support accessToken and baseURL options without requiring Provider
  • Upgrade of Zod dependency to 3.23.8
  • Addition of realtime streams feature
  • Updates to core dependencies

These changes are safe improvements that maintain backward compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the changelog for @trigger.dev packages to verify the patch updates

# Fetch the latest releases for trigger.dev packages
gh api graphql -f query='
{
  repository(owner: "triggerdotdev", name: "trigger.dev") {
    releases(first: 2, orderBy: {field: CREATED_AT, direction: DESC}) {
      nodes {
        tagName
        description
      }
    }
  }
}'

Length of output: 1115

apps/billing/src/trigger/glossary/draft-sections.ts (1)

154-156: LGTM! Guidelines for TypeScript and ESM syntax.

The added guidelines ensure consistency in code examples by mandating TypeScript and ESM syntax, which aligns well with modern JavaScript practices.

Comment on lines +78 to +84
sortKeys: (a, b) => {
// Ensure that 'question' always comes first
if (a === "question" || b === "question") {
return a === "question" ? -1 : 1;
}
return 0;
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure 'sortKeys' function is effective

The sortKeys function aims to position the 'question' key first in the YAML output. However, the provided data does not have a top-level 'question' key, so this sorting logic may not have the intended effect. Please verify the data structure and adjust the sorting function accordingly.

Comment on lines +129 to +134
const existingFile = await octokit.repos.getContent({
owner,
repo,
ref: existingPr.data[0].head.ref,
path,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle missing files when retrieving content

When using octokit.repos.getContent, a 404 error is thrown if the file does not exist. This can cause unhandled exceptions. Please implement error handling to manage cases where the file may not exist.

Apply this diff to add error handling:

-let existingFile = await octokit.repos.getContent({
+let existingFile;
+try {
+  existingFile = await octokit.repos.getContent({
     owner,
     repo,
     ref: existingPr.data[0].head.ref,
     path,
-});
+  });
+} catch (error) {
+  if (error.status === 404) {
+    existingFile = null;
+  } else {
+    throw error;
+  }
+}

Adjust the subsequent code to handle existingFile being null:

 ...("sha" in existingFile.data && { sha: existingFile.data.sha }),
+...(existingFile && "sha" in existingFile.data && { sha: existingFile.data.sha }),

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +110 to 113
const owner = "unkeyed";
const repo = "unkey";
const branch = `richard/add-${input.replace(/\s+/g, "-").toLowerCase()}`;
const path = `apps/www/content/glossary/${input.replace(/\s+/g, "-").toLowerCase()}.mdx`;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use consistent slug generation to prevent potential issues

To ensure consistency and handle special characters safely, consider using the existing slugger instance for creating the branch and path variables instead of manually replacing spaces and changing to lowercase.

Apply this diff to use slugger.slug(input):

 const owner = "unkeyed";
 const repo = "unkey";
-const branch = `richard/add-${input.replace(/\s+/g, "-").toLowerCase()}`;
-const path = `apps/www/content/glossary/${input.replace(/\s+/g, "-").toLowerCase()}.mdx`;
+const slug = slugger.slug(input);
+const branch = `richard/add-${slug}`;
+const path = `apps/www/content/glossary/${slug}.mdx`;

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +211 to +215
const existingFile = await octokit.repos.getContent({
owner,
repo,
path,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for getContent when the file may not exist

Similar to the previous instance, when committing to the new branch, the file might not exist, leading to an error. Please wrap the getContent call in a try-catch block to handle this scenario.

Apply this diff to handle the potential error:

-let existingFile = await octokit.repos.getContent({
+let existingFile;
+try {
+  existingFile = await octokit.repos.getContent({
     owner,
     repo,
     path,
-});
+  });
+} catch (error) {
+  if (error.status === 404) {
+    existingFile = null;
+  } else {
+    throw error;
+  }
+}

And adjust the subsequent code accordingly:

 ...("sha" in existingFile.data && { sha: existingFile.data.sha }),
+...(existingFile && "sha" in existingFile.data && { sha: existingFile.data.sha }),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const existingFile = await octokit.repos.getContent({
owner,
repo,
path,
});
let existingFile;
try {
existingFile = await octokit.repos.getContent({
owner,
repo,
path,
});
} catch (error) {
if (error.status === 404) {
existingFile = null;
} else {
throw error;
}
}

@chronark chronark merged commit 512c4e1 into unkeyed:main Nov 27, 2024
4 of 9 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Nov 29, 2024
18 tasks
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