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

New Components - heroku #14601

Merged
merged 3 commits into from
Nov 8, 2024
Merged

New Components - heroku #14601

merged 3 commits into from
Nov 8, 2024

Conversation

michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented Nov 7, 2024

Resolves #14585

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new constant ENTITIES for Heroku application events.
    • Enhanced functionality for managing Heroku applications and webhook subscriptions.
    • New module for handling and emitting webhook events from Heroku.
    • Added a new package @pipedream/heroku with version 0.0.1.
  • Bug Fixes

    • Improved event deduplication and metadata generation for webhook events.
  • Documentation

    • Updated package metadata and dependencies for better integration and usability.

Copy link

vercel bot commented Nov 7, 2024

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) Nov 7, 2024 5:24pm
pipedream-docs ⬜️ Ignored (Inspect) Nov 7, 2024 5:24pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Nov 7, 2024 5:24pm

Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

Walkthrough

The changes in this pull request introduce new functionalities and constants related to Heroku applications. A new constant ENTITIES is defined to represent various Heroku events. The heroku.app.mjs file is updated to include new properties and methods for managing applications and webhook subscriptions. A new module for handling webhook events is created, along with a corresponding test event module. Additionally, a package.json file is added for the @pipedream/heroku package, defining its metadata and dependencies.

Changes

File Path Change Summary
components/heroku/common/constants.mjs Added constant ENTITIES, an array of event objects with value and label properties.
components/heroku/heroku.app.mjs Updated propDefinitions with appId and entities; added methods for API requests and webhook management.
components/heroku/package.json Introduced new package.json for @pipedream/heroku, defining metadata and dependencies.
components/heroku/sources/new-webhook-event-instant/new-webhook-event-instant.mjs Created a module for handling Heroku webhook events with methods for activation, deactivation, and event processing.
components/heroku/sources/new-webhook-event-instant/test-event.mjs Added a module exporting a default object representing a Heroku webhook event with various properties.

Assessment against linked issues

Objective Addressed Explanation
Emit notifications for various Heroku entities (issue #14585)
Use async options to list apps (issue #14585)
Provide a multi-selectable property for Entity (issue #14585)
Use additionalProps to list valid eventTypes to subscribe to (issue #14585) AdditionalProps for eventTypes not implemented.

Possibly related PRs

Suggested labels

action, trigger / source

Poem

🐰 In the meadow where the code does play,
New constants hop, brightening the day.
With webhooks dancing, events in delight,
Heroku's magic, a wondrous sight!
So let us code, with joy and cheer,
For every change brings us near! 🌼


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

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

🧹 Outside diff range and nitpick comments (8)
components/heroku/common/constants.mjs (1)

1-42: Add JSDoc documentation and group related events.

The implementation correctly defines all major Heroku webhook event types with clear descriptions. Consider these improvements for better maintainability:

+/**
+ * @typedef {Object} HerokuEntity
+ * @property {string} value - The webhook event identifier
+ * @property {string} label - Human-readable description of the event
+ */

+/**
+ * Supported Heroku webhook event types
+ * @type {HerokuEntity[]}
+ */
 const ENTITIES = [
+  // Add-on related events
   {
     value: "api:addon-attachment",
     label: "addon-attachment - An add-on has been attached or removed from the app",
   },
   {
     value: "api:addon",
     label: "addon - An add-on for the app has been newly provisioned or deleted, or its details have been modified",
   },
+  // Application and build events
   {
     value: "api:app",
     label: "app - The app itself has been provisioned or deleted, or its details have been modified",
   },
   // ... rest of the events
components/heroku/sources/new-webhook-event-instant/new-webhook-event-instant.mjs (1)

11-27: Consider adding validation for required props.

While the props are well-structured, consider adding explicit required: true to the appId prop definition since it's essential for webhook subscription.

 appId: {
   propDefinition: [
     heroku,
     "appId",
+    {
+      required: true,
+    },
   ],
 },
components/heroku/sources/new-webhook-event-instant/test-event.mjs (3)

1-2: Consider adding JSDoc comments to document the test event structure.

The event metadata follows Heroku's webhook format correctly. However, adding documentation would help developers understand the purpose and structure of this test event.

+/**
+ * Sample Heroku webhook event for testing.
+ * Represents an app update event with minimal test data.
+ * @see https://devcenter.heroku.com/articles/app-webhooks#events
+ */
 export default {

Also applies to: 42-48


3-37: Enhance test data quality for better testing coverage.

While sensitive fields are properly sanitized, consider:

  1. Using realistic test values for non-sensitive fields (e.g., name, region, stack)
  2. Adding comments to indicate which fields are intentionally empty
 "data": {
   "id": "9a4eaeed-24cc-4b23-a8ca-7867b251eaf3",
   "acm": false,
-  "name": "",
+  "name": "test-app-123", // Example test app name
   "team": null,
   "owner": {
     "id": "7b25912d-b147-48d6-b03d-f0fc72be381b",
-    "email": ""
+    "email": "" // Intentionally empty for privacy
   },

49-53: Document the purpose of previous_data.

The structure correctly tracks changed fields, but it would be helpful to document why only these specific fields are included.

+  // Track changes to key fields for testing update scenarios
   "previous_data": {
components/heroku/heroku.app.mjs (3)

33-35: Simplify parameter destructuring in _makeRequest method

The default parameter $ = this within the destructuring assignment may reduce readability for some developers.

Consider restructuring the parameter assignment for clarity:

  _makeRequest(opts = {}) {
+   const { path, ...otherOpts } = opts;
+   const $ = opts.$ || this;
    const {
-     $ = this,
-     path,
-     ...otherOpts
    } = opts;

52-60: Add parameter validation in createWebhookSubscription method

The createWebhookSubscription method assumes that appId is provided. Adding a check to validate that appId is present can prevent potential runtime errors.

Consider adding a parameter validation:

  createWebhookSubscription({
    appId, ...opts
  }) {
+   if (!appId) {
+     throw new Error("appId is required to create a webhook subscription.");
+   }
    return this._makeRequest({
      method: "POST",
      path: `/apps/${appId}/webhooks`,
      ...opts,
    });
  },

61-68: Add parameter validation in deleteWebhookSubscription method

Similarly, ensure that both appId and hookId are provided in the deleteWebhookSubscription method to prevent errors when deleting a webhook.

Consider adding validation for these parameters:

  deleteWebhookSubscription({
    appId, hookId, ...opts
  }) {
+   if (!appId || !hookId) {
+     throw new Error("Both appId and hookId are required to delete a webhook subscription.");
+   }
    return this._makeRequest({
      method: "DELETE",
      path: `/apps/${appId}/webhooks/${hookId}`,
      ...opts,
    });
  },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cb22999 and 41ceb01.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • components/heroku/common/constants.mjs (1 hunks)
  • components/heroku/heroku.app.mjs (1 hunks)
  • components/heroku/package.json (1 hunks)
  • components/heroku/sources/new-webhook-event-instant/new-webhook-event-instant.mjs (1 hunks)
  • components/heroku/sources/new-webhook-event-instant/test-event.mjs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • components/heroku/package.json
🔇 Additional comments (8)
components/heroku/common/constants.mjs (2)

44-46: LGTM! Export pattern is clean and extensible.

The export implementation follows modern ES module patterns and allows for easy addition of more constants in the future.


1-46: Verify the integration with dependent components.

Let's ensure the ENTITIES constant is properly integrated with the app and webhook components.

✅ Verification successful

Let me gather more information about the webhook component usage to ensure complete verification.


Let me try one final verification with a different approach to check the webhook component's implementation.


Integration verified with proper usage in dependent components

The ENTITIES constant is correctly integrated:

  • In heroku.app.mjs: Imported and used as prop options (constants.ENTITIES)
  • In webhook component: Properly referenced through heroku app's propDefinition for the entities prop
  • The webhook implementation correctly uses the entity value in the webhook subscription creation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of ENTITIES constant in related files

# Test 1: Check if ENTITIES is imported and used in the app component
echo "Checking app component integration..."
rg -l "import.*constants" components/heroku/heroku.app.mjs
rg "ENTITIES" components/heroku/heroku.app.mjs

# Test 2: Check if ENTITIES values are used in webhook component
echo "Checking webhook component integration..."
rg "api:[a-z-]+" components/heroku/sources/new-webhook-event-instant/

Length of output: 519


Script:

#!/bin/bash
# Check the webhook component implementation for ENTITIES import and usage
echo "Checking webhook component imports and implementation..."
rg -l "import.*constants" components/heroku/sources/new-webhook-event-instant/
rg "ENTITIES" components/heroku/sources/new-webhook-event-instant/ -A 2

# Check if there are any other files using these constants
echo "Checking other potential usages..."
rg "api:(addon-attachment|addon|app|build|collaborator|domain|dyno|formation|release|sni-endpoint)" --type js

Length of output: 466


Script:

#!/bin/bash
# Check the webhook component's source code
echo "Examining webhook component implementation..."
cat components/heroku/sources/new-webhook-event-instant/new-webhook-event-instant.mjs

# Check if there are any prop type validations
echo "Checking for prop types or schema validations..."
rg "prop-types|schema" components/heroku/sources/new-webhook-event-instant/ -A 3

Length of output: 2607

components/heroku/sources/new-webhook-event-instant/new-webhook-event-instant.mjs (2)

1-10: LGTM! Component metadata is well-structured.

The component is properly configured with appropriate metadata, documentation link, and event deduplication.


13-13: Verify HTTP endpoint security configuration.

Ensure that the HTTP interface is properly configured with security measures such as:

  1. Rate limiting
  2. IP allowlisting for Heroku webhook IPs
  3. Request size limits
components/heroku/sources/new-webhook-event-instant/test-event.mjs (2)

38-41: LGTM! Proper handling of sensitive information.

The actor object correctly sanitizes the email field while maintaining a valid structure for testing.


54-68: Verify webhook metadata structure against Heroku's documentation.

The webhook metadata structure looks correct, but let's verify it matches Heroku's latest webhook delivery format.

✅ Verification successful

Based on the search results, I can now generate the final response. The webhook metadata structure in the test event matches Heroku's webhook delivery format, as evidenced by:

  1. The usage in the codebase shows consistent handling of this structure in new-webhook-event-instant.mjs
  2. The metadata contains all required fields for Heroku webhooks: attempt ID, delivery ID, event ID (with include type), and webhook ID
  3. The structure is being actively used in the component to generate event metadata using event.webhook_metadata.event.include

The webhook metadata structure is correctly implemented and matches Heroku's webhook delivery format.

The structure contains all required tracking IDs and event type information needed for proper webhook event handling and follows Heroku's webhook schema.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for other test events to ensure consistent structure
# and verify against Heroku's documentation patterns

# Test: Look for other webhook test events in the codebase
fd -e mjs -e js 'test-event' -x rg -l 'webhook_metadata'

# Test: Search for webhook structure documentation
rg -i 'webhook.*metadata|delivery.*metadata' README.md docs/

Length of output: 232


Script:

#!/bin/bash
# Let's search for any webhook-related patterns in the codebase to understand the structure
rg -A 5 -B 5 'webhook.*metadata|delivery.*metadata' --type js --type mjs

# Also search for any webhook documentation or schema definitions
fd -e json -e schema.mjs 'webhook|schema' -x cat {}

Length of output: 158


Script:

#!/bin/bash
# Search for webhook patterns in the codebase, including the file extension explicitly
rg -A 5 -B 5 'webhook.*metadata|delivery.*metadata' -g '*.{js,mjs}'

# Look for any schema or type definitions related to webhooks
rg -A 10 'webhook.*interface|webhook.*type|webhook.*schema' -g '*.{js,mjs,ts}'

# Search specifically in the Heroku component directory for webhook-related files
fd . components/heroku -x cat {} | rg -A 5 -B 5 'webhook'

Length of output: 30183

components/heroku/heroku.app.mjs (2)

41-41: Ensure proper access to authentication token

Verify that this.$auth.oauth_access_token correctly retrieves the OAuth access token. Proper authentication is crucial for API requests to Heroku.

To confirm that this.$auth.oauth_access_token is accessible and contains the expected token, you can check its usage in the context of your code.


24-24: Verify that constants.ENTITIES is defined and imported correctly

The entities property relies on constants.ENTITIES for its options. Ensure that ENTITIES is defined in your constants.mjs file and that it exports the correct array of entity options.

To confirm that ENTITIES is properly defined, you can run:

✅ Verification successful

constants.ENTITIES is properly defined and imported

The verification confirms that ENTITIES is correctly defined in components/heroku/common/constants.mjs and properly imported in heroku.app.mjs. The constant contains an array of Heroku entity options used for webhook subscriptions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that 'ENTITIES' is exported from 'constants.mjs'

# Search for the export of 'ENTITIES' in 'constants.mjs'
rg 'export\s+const\s+ENTITIES' ./common/constants.mjs

Length of output: 118


Script:

#!/bin/bash
# Let's first find where constants.mjs might be located
fd -e mjs -e js constants

# Then search for ENTITIES export in all JS/MJS files
rg -l "export.*ENTITIES" --type js

Length of output: 27781


Script:

#!/bin/bash
# Let's check the content of the Heroku component's constants file
cat components/heroku/common/constants.mjs

# Also check if ENTITIES is defined in the file being reviewed
cat components/heroku/heroku.app.mjs

Length of output: 3199

Copy link
Collaborator

@jcortes jcortes left a comment

Choose a reason for hiding this comment

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

Hi @michelle0927 lgtm! Ready for QA!

@michelle0927 michelle0927 merged commit 9241d4c into master Nov 8, 2024
12 checks passed
@michelle0927 michelle0927 deleted the issue-14585 branch November 8, 2024 16:04
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.

[Components] heroku
2 participants