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

Script to upload app files #15290

Merged
merged 5 commits into from
Jan 24, 2025
Merged

Script to upload app files #15290

merged 5 commits into from
Jan 24, 2025

Conversation

dylburger
Copy link
Contributor

@dylburger dylburger commented Jan 13, 2025

Summary by CodeRabbit

  • New Features

    • Added a new script to upload application files to Supabase
    • Expanded workspace configuration to include scripts directory
  • Chores

    • Updated .gitignore to exclude .env* files
    • Created a new package.json for scripts with necessary dependencies
  • Documentation

    • Added environment variable handling for Supabase configuration

Copy link

vercel bot commented Jan 13, 2025

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

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Jan 24, 2025 5:45am
pipedream-docs ⬜️ Ignored (Inspect) Jan 24, 2025 5:45am
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Jan 24, 2025 5:45am

Copy link
Contributor

coderabbitai bot commented Jan 13, 2025

Walkthrough

This pull request introduces minor modifications across several files, primarily adding newlines at the end of various .app.mjs files in the components directory. Additionally, a new script for uploading application files to Supabase has been created, along with supporting configuration files. The changes include updating the pnpm-workspace.yaml to include the scripts directory and adding a .gitignore file to exclude .env* files.

Changes

File Change Summary
components/*/**.app.mjs Added newline at end of file (Clear Books, Dixa, Linkup, Mailboxlayer, Nextdoor)
pnpm-workspace.yaml Added 'scripts/**' to packages section
scripts/.gitignore Added .env* to ignored files
scripts/package.json New file with project metadata and dependencies
scripts/upload-app-files-to-supabase.mjs New script to upload .app.mjs files to Supabase

Possibly related PRs

Suggested reviewers

  • michelle0927

Poem

🐰 Newlines dancing, files so neat
Scripts and configs, a coding treat
Supabase upload, a rabbit's delight
Workspace expanding, everything's right!
Code grows cleaner with each small change 🚀


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

@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: 2

🧹 Nitpick comments (3)
scripts/upload-app-files-to-supabase.mjs (3)

7-9: Consider improving the error message specificity.

Good environment validation! Consider making the error message more specific by checking and reporting each missing variable separately.

-if (!process.env.SUPABASE_URL || !process.env.SUPABASE_KEY) {
-  throw new Error('Missing required environment variables SUPABASE_URL and/or SUPABASE_KEY')
+if (!process.env.SUPABASE_URL) {
+  throw new Error('Missing required environment variable SUPABASE_URL')
+}
+if (!process.env.SUPABASE_KEY) {
+  throw new Error('Missing required environment variable SUPABASE_KEY')
}

43-46: Enhance error reporting and tracking.

Consider collecting errors in an array to provide a summary at the end of processing. This would help track all failures in one place.

+const errors = [];
+
 async function findAndUploadFiles() {
   try {
     // ... existing code ...
     if (error) {
-      console.error(`Error uploading ${filename}:`, error)
+      const errorMsg = `Error uploading ${filename}: ${error.message}`;
+      console.error(errorMsg)
+      errors.push(errorMsg)
       continue
     }
     // ... existing code ...
   } catch (err) {
-    console.error('Error finding files:', err)
+    const errorMsg = `Error finding files: ${err.message}`;
+    console.error(errorMsg)
+    errors.push(errorMsg)
   }
+  return errors;
 }

Also applies to: 49-51, 53-55


58-61: Improve script completion handling.

Add proper exit codes and operation summary for better integration with CI/CD pipelines.

 // Run the script
 findAndUploadFiles()
-  .then(() => console.log('Upload complete'))
-  .catch(err => console.error('Script failed:', err))
+  .then((errors) => {
+    console.log('Upload complete')
+    if (errors.length > 0) {
+      console.log(`Failed to process ${errors.length} files:`)
+      errors.forEach(err => console.log(`- ${err}`))
+      process.exit(1)
+    }
+    process.exit(0)
+  })
+  .catch(err => {
+    console.error('Script failed:', err)
+    process.exit(1)
+  })
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e729e5 and 4e88323.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • components/clear_books/clear_books.app.mjs (1 hunks)
  • components/dixa/dixa.app.mjs (1 hunks)
  • components/linkup/linkup.app.mjs (1 hunks)
  • components/mailboxlayer/mailboxlayer.app.mjs (1 hunks)
  • components/nextdoor/nextdoor.app.mjs (1 hunks)
  • pnpm-workspace.yaml (1 hunks)
  • scripts/.gitignore (1 hunks)
  • scripts/package.json (1 hunks)
  • scripts/upload-app-files-to-supabase.mjs (1 hunks)
✅ Files skipped from review due to trivial changes (7)
  • components/clear_books/clear_books.app.mjs
  • components/nextdoor/nextdoor.app.mjs
  • components/linkup/linkup.app.mjs
  • components/mailboxlayer/mailboxlayer.app.mjs
  • components/dixa/dixa.app.mjs
  • scripts/.gitignore
  • scripts/package.json
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (2)
scripts/upload-app-files-to-supabase.mjs (1)

11-15: LGTM! Supabase client configuration is correct.

pnpm-workspace.yaml (1)

8-8: LGTM! Workspace configuration updated correctly.

The addition of 'scripts/**' follows the existing pattern and will properly manage the script's dependencies.

Comment on lines +20 to +25
const files = await glob('../components/**/*.app.mjs', {
// No need to recurse into the standard subdirs, since app files are always at
// the root of the components/${app} directory
ignore: ['node_modules/**', 'actions/**', 'common/**', 'sources/**'],
absolute: true
})
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

Make path resolution more robust.

The relative path '../components' could break if the script is run from a different directory. Consider using path.resolve to create an absolute path relative to the script's location.

-    const files = await glob('../components/**/*.app.mjs', {
+    const files = await glob(path.resolve(__dirname, '../components/**/*.app.mjs'), {

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

Comment on lines +29 to +52
for (const filePath of files) {
try {
const content = await readFile(filePath, 'utf8')

const filename = path.basename(filePath)
const app = filename.replace('.app.mjs', '')

const { data, error } = await supabase
.from('registry_app_files')
.insert({
app: app,
app_file: content
})

if (error) {
console.error(`Error uploading ${filename}:`, error)
continue
}

console.log(`Successfully uploaded ${filename}`)
} catch (err) {
console.error(`Error processing ${filePath}:`, err)
}
}
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

Add content validation and duplicate handling.

Consider these improvements:

  1. Validate file content before upload
  2. Handle potential duplicates in the database
         const content = await readFile(filePath, 'utf8')
+        // Validate content
+        if (!content.trim()) {
+          throw new Error('Empty file')
+        }
 
         const filename = path.basename(filePath)
         const app = filename.replace('.app.mjs', '')
 
         const { data, error } = await supabase
           .from('registry_app_files')
-          .insert({
+          .upsert({
             app: app,
             app_file: content
-          })
+          }, {
+            onConflict: 'app',
+            ignoreDuplicates: false
+          })
📝 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
for (const filePath of files) {
try {
const content = await readFile(filePath, 'utf8')
const filename = path.basename(filePath)
const app = filename.replace('.app.mjs', '')
const { data, error } = await supabase
.from('registry_app_files')
.insert({
app: app,
app_file: content
})
if (error) {
console.error(`Error uploading ${filename}:`, error)
continue
}
console.log(`Successfully uploaded ${filename}`)
} catch (err) {
console.error(`Error processing ${filePath}:`, err)
}
}
for (const filePath of files) {
try {
const content = await readFile(filePath, 'utf8')
// Validate content
if (!content.trim()) {
throw new Error('Empty file')
}
const filename = path.basename(filePath)
const app = filename.replace('.app.mjs', '')
const { data, error } = await supabase
.from('registry_app_files')
.upsert({
app: app,
app_file: content
}, {
onConflict: 'app',
ignoreDuplicates: false
})
if (error) {
console.error(`Error uploading ${filename}:`, error)
continue
}
console.log(`Successfully uploaded ${filename}`)
} catch (err) {
console.error(`Error processing ${filePath}:`, err)
}
}

@dylburger dylburger merged commit 68cfd15 into master Jan 24, 2025
8 checks passed
@dylburger dylburger deleted the upload-app-files branch January 24, 2025 05:45
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.

1 participant