Skip to content

[Sources] Wordpress_com #16500

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

SokolovskyiK
Copy link
Contributor

@SokolovskyiK SokolovskyiK commented May 1, 2025

@vunguyenhung
Fixes #15127
Fixed sources: new post, comment, and follower.
Tested via pd dev — everything works.

Please note that I added activate() so that when the source is deployed, it fetches the latest comment, post, or follower to initialize properly and emit events only for items with higher IDs.

If the user changes something like the site or type, the last comment/post/follower ID is reinitialized without emitting events.
For example, if they change the post ID to one where the last comment ID is lower, it could otherwise cause unpredictable behavior.
To prevent this, activate() reinitializes on any change.

изображение
изображение
изображение
изображение

Summary by CodeRabbit

  • New Features
    • Added timer settings to control how often new comments, posts, and followers are checked.
    • Enhanced initialization and activation for new comment, post, and follower monitoring, improving setup and reliability.
    • Introduced more user-friendly and detailed success messages for creating and deleting posts and uploading media.
  • Improvements
    • Streamlined and modularized fetching and initialization processes for comments, posts, and followers.
    • Improved error handling defaults for more robust operation.
    • Added utility functions for initialization and mock logging to support setup and debugging.
  • Bug Fixes
    • Resolved potential issues with missing warnings in error handling.

Copy link

vercel bot commented May 1, 2025

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

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) May 3, 2025 6:26pm

Copy link

vercel bot commented May 1, 2025

@SokolovskyiK is attempting to deploy a commit to the Pipedreamers Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented May 1, 2025

Walkthrough

This set of changes updates several WordPress.com integration components. It increments the version numbers and refines summary messages for the "Create Post," "Delete Post," and "Upload Media" actions to provide more informative feedback. The sources for "New Post," "New Comment," and "New Follower" are enhanced with a timer property for polling, modularized data fetching methods, and an activation hook for initialization and cursor management. Additionally, two utility methods, _mock$ and initialize, are added to the app module to support mocking and state initialization. A minor improvement is made to the error handling utility to default warnings to an empty array.

Changes

Files/Group Change Summary
components/wordpress_com/actions/create-post/create-post.mjs Updated version from 0.0.1 to 0.0.2; improved summary message after post creation to include post title and ID.
components/wordpress_com/actions/delete-post/delete-post.mjs Updated version from 0.0.1 to 0.0.2; refined summary message after post deletion with updated formatting and wording.
components/wordpress_com/actions/upload-media/upload-media.mjs Updated version from 0.0.1 to 0.0.2; changed summary message after media upload to use only media ID with curly quotes; added inert string literal.
components/wordpress_com/common/methods.mjs Made warnings parameter in throwCustomError default to empty array.
components/wordpress_com/sources/new-comment/new-comment.mjs Updated version from 0.0.1 to 0.0.2; added timer prop, modularized comment fetching, added activation hook, simplified cursor initialization.
components/wordpress_com/sources/new-follower/new-follower.mjs Updated version from 0.0.1 to 0.0.2; added timer prop, modularized follower fetching, added activation hook, simplified cursor initialization.
components/wordpress_com/sources/new-post/new-post.mjs Updated version from 0.0.1 to 0.0.2; added timer prop, modularized post fetching, added activation hook, simplified cursor initialization.
components/wordpress_com/wordpress_com.app.mjs Added _mock$ method for generic mocking; added initialize method for cursor state setup.
components/airtable_oauth/package.json Updated version from 0.5.0 to 0.5.1; no other changes.
components/wordpress_com/package.json Updated version from 0.7.0 to 0.7.1; no other changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Source (e.g. New Post)
    participant WordPress App
    participant Database

    User->>Source: Activate source
    Source->>WordPress App: getWordpressPosts($)
    WordPress App-->>Source: Posts array
    Source->>WordPress App: initialize(posts, db, "lastPostId")
    WordPress App->>Database: Store first post ID as cursor
    Database-->>WordPress App: Ack
    WordPress App-->>Source: Initialization result
Loading
sequenceDiagram
    participant User
    participant Action (Create Post)
    participant WordPress API

    User->>Action: Trigger create-post
    Action->>WordPress API: Create post with title, content, etc.
    WordPress API-->>Action: Post ID and details
    Action-->>User: Summary message with post title and ID
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement "new-post" source with polling, required/optional props, and event emission (#15127)
Implement "new-comment" source with polling, required/optional props, and event emission (#15127)
Implement "new-follower" source with polling, required props, and event emission (#15127)
Implement "create-post", "upload-media", "delete-post" actions with required/optional props (#15127)
Add summary messages and improve error handling for actions (#15127)

Possibly related PRs

Suggested labels

action

Poem

In the garden of code where the WordPress bunnies hop,
New posts, comments, and followers now pop!
With timers and hooks, our carrots align,
Summaries sparkle, and errors decline.
Hop, hop, hooray—
More features for today!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

components/wordpress_com/actions/create-post/create-post.mjs

Oops! Something went wrong! :(

ESLint: 8.57.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

components/wordpress_com/actions/delete-post/delete-post.mjs

Oops! Something went wrong! :(

ESLint: 8.57.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

components/wordpress_com/actions/upload-media/upload-media.mjs

Oops! Something went wrong! :(

ESLint: 8.57.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

  • 3 others

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 41b4d37 and 7ce16de.

📒 Files selected for processing (6)
  • components/wordpress_com/actions/create-post/create-post.mjs (2 hunks)
  • components/wordpress_com/actions/delete-post/delete-post.mjs (2 hunks)
  • components/wordpress_com/actions/upload-media/upload-media.mjs (2 hunks)
  • components/wordpress_com/sources/new-comment/new-comment.mjs (3 hunks)
  • components/wordpress_com/sources/new-follower/new-follower.mjs (4 hunks)
  • components/wordpress_com/sources/new-post/new-post.mjs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • components/wordpress_com/actions/delete-post/delete-post.mjs
  • components/wordpress_com/actions/create-post/create-post.mjs
  • components/wordpress_com/actions/upload-media/upload-media.mjs
  • components/wordpress_com/sources/new-post/new-post.mjs
  • components/wordpress_com/sources/new-follower/new-follower.mjs
  • components/wordpress_com/sources/new-comment/new-comment.mjs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Lint Code Base
  • GitHub Check: Publish TypeScript components
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

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

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@adolfo-pd adolfo-pd added the User submitted Submitted by a user label May 1, 2025
@pipedream-component-development
Copy link
Collaborator

Thank you so much for submitting this! We've added it to our backlog to review, and our team has been notified.

@pipedream-component-development
Copy link
Collaborator

Thanks for submitting this PR! When we review PRs, we follow the Pipedream component guidelines. If you're not familiar, here's a quick checklist:

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 comments (2)
components/wordpress_com/sources/new-follower/new-follower.mjs (2)

80-87: ⚠️ Potential issue

initialize is called with the wrong cursor key ("lastPostId" instead of "lastFollowerId").

Passing the wrong key means the cursor for followers is never updated; every run after the first will treat all followers as “new” and emit duplicates.

-    if (!lastFollowerId) await wordpress.initialize(followers, db, "lastPostId");
+    if (!lastFollowerId) await wordpress.initialize(followers, db, "lastFollowerId");

90-110: 🛠️ Refactor suggestion

Persist the cursor as a number to avoid string/number mismatches.

maxFollowerIdTracker may be set to a string when you copy follower.ID.
Persisting it as a string and later coercing with Number()NaN can break the “no-duplicate” guarantee.

-      if (Number(follower.ID) > maxFollowerIdTracker) {
-        maxFollowerIdTracker = follower.ID;
+      const followerIdNum = Number(follower.ID);
+      if (followerIdNum > maxFollowerIdTracker) {
+        maxFollowerIdTracker = followerIdNum;
       }
 …
-      await db.set("lastFollowerId", maxFollowerIdTracker);
+      await db.set("lastFollowerId", Number(maxFollowerIdTracker));
🧹 Nitpick comments (5)
components/wordpress_com/wordpress_com.app.mjs (1)

165-175: Good implementation of the initialization logic

The initialize method provides a centralized way to handle cursor initialization for WordPress sources. It appropriately:

  • Checks for empty arrays
  • Logs informative messages
  • Sets the database cursor value
  • Returns appropriate Boolean results

This implementation will help prevent duplicate event emissions as mentioned in the PR objectives.

There's a small style issue with an extra space before the semicolon on line 174.

-      return true ;
+      return true;
components/wordpress_com/actions/upload-media/upload-media.mjs (1)

78-79: Improved success message format

The summary message has been reformatted to be more user-friendly with consistent formatting for warnings.

There's a parenthesis in the message that appears to be a typo:

- $.export("$summary", `Media ID "${media.ID})" has been successfully uploaded` +
+ $.export("$summary", `Media ID "${media.ID}" has been successfully uploaded` +
components/wordpress_com/common/methods.mjs (1)

204-212: Suppress dangling hyphen when no warnings are present

throwCustomError() now safely defaults warnings to an empty array – great!
However, when warnings.length === 0, the formatted string still appends "\n- " which leaves a stray hyphen at the end of every error message.

-  throw new Error(` ${mainMessage} ( ${thrower} error ) : ${error.message}. ` + "\n- " +
-     warnings.join("\n- "));
+  const warningsBlock = warnings.length
+    ? "\n- " + warnings.join("\n- ")
+    : "";
+
+  throw new Error(
+    ` ${mainMessage} ( ${thrower} error ) : ${error.message}. ${warningsBlock}`,
+  );

This keeps the output tidy when no warnings exist while preserving the current format when they do.

components/wordpress_com/sources/new-follower/new-follower.mjs (2)

35-60: Minor: use the destructured db consistently (or drop it).

Inside activate() you destructure db but still reference this.db.
Pick one form to keep the code consistent and easier to read.

-      await this.db.set("lastFollowerId", null); //reset
+      await db.set("lastFollowerId", null); // reset

(or remove db from the destructuring list).


29-33: Consider adding sensible defaults to the timer prop.

Without a default, users must always configure the interval manually, which can be error-prone.
Typical sources expose a reasonable default (e.g. every 15 min) while still allowing overrides.

Example:

 timer: {
   type: "$.interface.timer",
   label: "Timer",
   description: "How often to poll WordPress for new followers.",
+  default: {
+    intervalSeconds: 900,
+  },
 },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 302aec1 and c1859ac.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (8)
  • components/wordpress_com/actions/create-post/create-post.mjs (2 hunks)
  • components/wordpress_com/actions/delete-post/delete-post.mjs (2 hunks)
  • components/wordpress_com/actions/upload-media/upload-media.mjs (2 hunks)
  • components/wordpress_com/common/methods.mjs (1 hunks)
  • components/wordpress_com/sources/new-comment/new-comment.mjs (3 hunks)
  • components/wordpress_com/sources/new-follower/new-follower.mjs (4 hunks)
  • components/wordpress_com/sources/new-post/new-post.mjs (3 hunks)
  • components/wordpress_com/wordpress_com.app.mjs (2 hunks)
🔇 Additional comments (6)
components/wordpress_com/wordpress_com.app.mjs (1)

48-54: Well-implemented mock utility function

This _mock$ function provides a clean implementation using Proxy to intercept any property access and return a function that logs arguments. This will be useful for testing and debugging purposes.

components/wordpress_com/actions/delete-post/delete-post.mjs (2)

7-7: Version increment is appropriate

The version bump from 0.0.1 to 0.0.2 is appropriate for the message format change.


51-52: Improved success message format

The summary message has been reformatted to be more user-friendly with better wording and formatting.

components/wordpress_com/actions/create-post/create-post.mjs (2)

7-7: Significant version increment

The version has been incremented from 0.0.1 to 0.0.9, which is a substantial jump for what appears to be a relatively minor change in the summary message format.

Was this intended to be such a large version increment, or was it meant to be 0.0.2 to match the other actions?


83-85: Enhanced success message with post title

The summary message has been improved to include the post title in addition to the ID, making it more informative for users.

components/wordpress_com/actions/upload-media/upload-media.mjs (1)

8-8: Version increment is appropriate

The version bump from 0.0.1 to 0.0.2 is appropriate for the message format change.

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

🧹 Nitpick comments (2)
components/wordpress_com/sources/new-follower/new-follower.mjs (2)

35-60: The activate hook implementation looks good but needs documentation.

The activate hook properly initializes the component by resetting state and fetching initial data. This prevents emitting historical events on first run and handles parameter changes correctly.

Consider adding a brief JSDoc comment explaining the purpose of the activate hook, particularly highlighting how it handles reinitialization when parameters change.

hooks: {
+  /**
+   * Initializes the component by resetting state and fetching initial follower data.
+   * This ensures we only emit events for new followers after activation and
+   * properly reinitialize when site parameters change.
+   */
  async activate() {

52-58: Consider conditional initialization in activate hook.

The activate hook always resets the lastFollowerId to null, which means any deployment will reset tracking. Consider if this is the intended behavior, especially for updates that don't change functionality.

You might want to use conditional logic that only resets when certain props change:

- await this.db.set("lastFollowerId", null); //reset
+ // Only reset if site has changed
+ const currentSite = await this.db.get("currentSite");
+ if (currentSite !== site) {
+   await this.db.set("lastFollowerId", null);
+   await this.db.set("currentSite", site);
+ }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c1859ac and 588ac45.

📒 Files selected for processing (8)
  • components/airtable_oauth/package.json (1 hunks)
  • components/wordpress_com/actions/create-post/create-post.mjs (2 hunks)
  • components/wordpress_com/actions/delete-post/delete-post.mjs (2 hunks)
  • components/wordpress_com/actions/upload-media/upload-media.mjs (2 hunks)
  • components/wordpress_com/sources/new-comment/new-comment.mjs (3 hunks)
  • components/wordpress_com/sources/new-follower/new-follower.mjs (4 hunks)
  • components/wordpress_com/sources/new-post/new-post.mjs (3 hunks)
  • components/wordpress_com/wordpress_com.app.mjs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • components/airtable_oauth/package.json
🚧 Files skipped from review as they are similar to previous changes (6)
  • components/wordpress_com/actions/delete-post/delete-post.mjs
  • components/wordpress_com/actions/create-post/create-post.mjs
  • components/wordpress_com/actions/upload-media/upload-media.mjs
  • components/wordpress_com/wordpress_com.app.mjs
  • components/wordpress_com/sources/new-comment/new-comment.mjs
  • components/wordpress_com/sources/new-post/new-post.mjs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: pnpm publish
  • GitHub Check: Lint Code Base
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Verify TypeScript components
🔇 Additional comments (4)
components/wordpress_com/sources/new-follower/new-follower.mjs (4)

7-7: Version increment looks appropriate.

The version bump from 0.0.1 to 0.0.4 aligns with the significant functionality changes in this component.


10-19: Good refactoring for improved modularity.

Extracting the follower fetching logic into a dedicated method improves code organization and maintainability. This encapsulation makes the code more readable and easier to maintain.


29-33: User-configurable polling frequency is a good addition.

Adding a timer property allows users to control how frequently the component checks for new followers, which improves flexibility and resource utilization.


75-75: Code refactoring improves consistency.

Using the extracted method aligns with the architectural improvements made throughout the component.

Copy link
Collaborator

@michelle0927 michelle0927 left a comment

Choose a reason for hiding this comment

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

Looks good, I just updated some of the versions. I know when you're testing, you probably have to increase them more. However, for publishing, we want the versions just one digit higher than they were previously published at.

@SokolovskyiK
Copy link
Contributor Author

@michelle0927
Oh, so when I publish to my account for testing, increasing the version doesn’t affect the version in the whole system for the same key?
Got it — just +1 from the latest merged version.
Thanks, will do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
User submitted Submitted by a user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Components] wordpress_com
4 participants