Skip to content

Conversation

@michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented May 13, 2025

Resolves #15130

Summary by CodeRabbit

  • New Features

    • Added actions to fetch daily coding heartbeats, list projects, and log coding activity for WakaTime.
    • Introduced new event sources to emit events when new commits, goals, or projects are created in WakaTime.
    • Provided test event data for new commit, goal, and project events for easier testing and simulation.
  • Improvements

    • Released a new WakaTime app integration with enhanced API support, including project and language selection, and improved pagination handling.
    • Introduced a base component for handling event polling and processing in WakaTime sources.
  • Chores

    • Updated package metadata and dependencies for the WakaTime integration.
    • Removed legacy app definition and cleaned up ignored files configuration.

@vercel
Copy link

vercel bot commented May 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 May 13, 2025 6:57pm
pipedream-docs ⬜️ Ignored (Inspect) May 13, 2025 6:57pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) May 13, 2025 6:57pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 13, 2025

Walkthrough

This update introduces a new WakaTime integration with multiple action and source modules, enabling listing and logging of projects, coding activity, and heartbeats, as well as polling for new commits, projects, and goals. The update restructures the app definition, adds a robust API interface with pagination, and provides test event fixtures for source components.

Changes

Files/Paths Change Summary
components/wakatime/.gitignore Deleted the .gitignore file, removing ignore rules for .js, .mjs, and dist.
components/wakatime/app/wakatime.app.ts Removed the old TypeScript WakaTime app definition.
components/wakatime/package.json Updated version to 0.1.0, changed entry point, removed "dist" from "files", added dependency on @pipedream/platform.
components/wakatime/wakatime.app.mjs Added new WakaTime app definition with prop definitions, API methods for projects, heartbeats, languages, commits, goals, heartbeat creation, and a pagination helper.
components/wakatime/actions/fetch-daily-heartbeats/fetch-daily-heartbeats.mjs Added action to fetch daily heartbeats for a given date.
components/wakatime/actions/list-projects/list-projects.mjs Added action to list WakaTime projects, with optional query filtering.
components/wakatime/actions/log-coding-activity/log-coding-activity.mjs Added action to log coding activity (heartbeat) with detailed properties.
components/wakatime/sources/common/base.mjs Added a reusable base source for polling WakaTime resources, handling state, pagination, and event emission.
components/wakatime/sources/new-commit-created/new-commit-created.mjs Added source to poll for new commit events, extending the base source.
components/wakatime/sources/new-commit-created/test-event.mjs Added test event fixture for new commit created source.
components/wakatime/sources/new-goal-created/new-goal-created.mjs Added source to poll for new goal events, extending the base source.
components/wakatime/sources/new-goal-created/test-event.mjs Added test event fixture for new goal created source.
components/wakatime/sources/new-project-created/new-project-created.mjs Added source to poll for new project events, extending the base source.
components/wakatime/sources/new-project-created/test-event.mjs Added test event fixture for new project created source.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Action
    participant WakaTimeApp
    participant WakaTimeAPI

    User->>Action: Trigger action (e.g., fetch daily heartbeats)
    Action->>WakaTimeApp: Call API method (e.g., listHeartbeats)
    WakaTimeApp->>WakaTimeAPI: Make authenticated HTTP request
    WakaTimeAPI-->>WakaTimeApp: Return API response
    WakaTimeApp-->>Action: Return processed data
    Action-->>User: Output summary and data
Loading
sequenceDiagram
    participant Source
    participant WakaTimeApp
    participant WakaTimeAPI
    participant EventStream

    Source->>WakaTimeApp: Call paginated API method (e.g., listCommits)
    WakaTimeApp->>WakaTimeAPI: Make authenticated HTTP request
    WakaTimeAPI-->>WakaTimeApp: Return API response
    WakaTimeApp-->>Source: Return data
    Source->>EventStream: Emit new event(s) with metadata
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement polling sources: new-commit-created, new-project-created, new-goal-created (#15130)
Implement actions: list-projects, log-coding-activity, fetch-daily-heartbeats (#15130)
Support required and optional props as described for each action/source (#15130)
Use WakaTime API endpoints and pagination as specified (#15130)

Suggested labels

action, trigger / source, ai-assisted

Suggested reviewers

  • lcaresia

Poem

A hop and a skip through the code today,
WakaTime’s magic now on display!
New projects, goals, and commits in sight,
Actions and sources working just right.
With heartbeats logged and data in tow,
The rabbit’s delight continues to grow!
🐇✨

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/wakatime/sources/new-commit-created/new-commit-created.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/wakatime/wakatime.app.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)

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 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 abded72 and dfc4e28.

📒 Files selected for processing (2)
  • components/wakatime/sources/new-commit-created/new-commit-created.mjs (1 hunks)
  • components/wakatime/wakatime.app.mjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • components/wakatime/sources/new-commit-created/new-commit-created.mjs
  • components/wakatime/wakatime.app.mjs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Verify TypeScript components
  • 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

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

🧹 Nitpick comments (9)
components/wakatime/actions/log-coding-activity/log-coding-activity.mjs (1)

27-31: Consider improving time property with defaults and validation

The time property currently accepts any string value, but it's a critical parameter for heartbeats. Consider:

  1. Adding a default value using the current timestamp
  2. Adding validation for timestamp format
  3. Considering a datetime type prop instead of string
 time: {
   type: "string",
   label: "Time",
   description: "UNIX epoch timestamp; numbers after decimal point are fractions of a second",
+  default: () => Math.floor(Date.now() / 1000).toString(),
+  validator: (value) => !isNaN(parseFloat(value)) || "Please provide a valid UNIX timestamp",
 },
components/wakatime/actions/fetch-daily-heartbeats/fetch-daily-heartbeats.mjs (1)

11-15: Add date format validation and improve date input

The date property could benefit from format validation and potentially a better input mechanism.

 date: {
   type: "string",
   label: "Date",
   description: "The date to fetch heartbeats for (YYYY-MM-DD)",
+  default: () => new Date().toISOString().split("T")[0],
+  validator: (value) => /^\d{4}-\d{2}-\d{2}$/.test(value) || "Please provide date in YYYY-MM-DD format",
 },
components/wakatime/sources/new-goal-created/test-event.mjs (2)

1-160: Consider adding documentation to explain test event structure

The test event data is comprehensive, but adding comments or documentation would help developers understand:

  1. The purpose of key fields
  2. Which fields are essential for testing vs optional
  3. How to modify the event for different test scenarios

Consider adding a comment block at the beginning of the file explaining the structure and important fields:

+/**
+ * Sample WakaTime goal event for testing the New Goal Created source.
+ * Key fields:
+ * - id: Goal identifier (empty for new goals)
+ * - title: Display name of the goal
+ * - type: Goal category (coding, etc.)
+ * - seconds: Goal target time in seconds
+ * - created_at: Creation timestamp (used for deduplication)
+ * - chart_data: Historical tracking data by day
+ */
 export default {
   "id": "",
   "type": "coding",
   // ...

2-2: Add a mock ID value for testing

The ID field is currently empty (""), but having a mock value would make the test event more realistic.

-    "id": "",
+    "id": "goal-12345-abcde",
components/wakatime/actions/list-projects/list-projects.mjs (1)

18-38: Consider adding explicit error handling.

The action correctly implements pagination for retrieving all projects, with nice attention to detail in the summary message (handling singular/plural). However, you might want to add explicit error handling to gracefully handle API failures.

  async run({ $ }) {
+   try {
      const results = this.wakatime.paginate({
        fn: this.wakatime.listProjects,
        args: {
          $,
          params: {
            q: this.q,
          },
        },
      });

      const projects = [];
      for await (const project of results) {
        projects.push(project);
      }

      $.export("$summary", `Successfully retrieved ${projects.length} project${projects.length === 1
        ? ""
        : "s"}`);
      return projects;
+   } catch (error) {
+     $.export("$summary", "Failed to retrieve projects");
+     throw error;
+   }
  },
components/wakatime/wakatime.app.mjs (1)

35-90: Add JSDoc comments to methods for better documentation.

The API methods would benefit from JSDoc comments documenting parameters, return values, and example usage to help developers understand how to use them correctly.

For example, add comments like this to your methods:

+  /**
+   * Makes authenticated requests to the WakaTime API
+   * @param {Object} opts - Request options
+   * @param {Object} opts.$ - Pipedream context
+   * @param {string} opts.path - API endpoint path
+   * @returns {Promise<Object>} - The API response
+   */
  _makeRequest({
    $ = this,
    path,
    ...otherOpts
  }) {
    // implementation...
  }

+  /**
+   * Lists all projects for the current user
+   * @param {Object} opts - Request options
+   * @param {Object} [opts.params] - Query parameters
+   * @param {string} [opts.params.q] - Search term to filter projects
+   * @returns {Promise<Object>} - The API response containing projects
+   */
  listProjects(opts = {}) {
    // implementation...
  }
components/wakatime/sources/common/base.mjs (2)

16-37: Add documentation for the timestamp field format.

The getTsField method returns 'created_at', but there's no documentation about the expected format of this field. Adding a comment would help developers understand the timestamp format expectations.

+  /**
+   * Returns the name of the field containing the timestamp
+   * @returns {string} The name of the timestamp field (expected to be in ISO format)
+   */
  getTsField() {
    return "created_at";
  },

85-91: Consider adding more descriptive comments for lifecycle hooks.

The deploy and run hooks could benefit from more descriptive comments explaining their purpose and expected behavior.

  hooks: {
+   /**
+    * Process up to 25 initial events when the source is first deployed
+    */
    async deploy() {
      await this.processEvent(25);
    },
  },
+ /**
+  * Process all new events on each scheduled execution
+  */
  async run() {
    await this.processEvent();
  },
components/wakatime/package.json (1)

5-5: Confirm the new main entry point is packaged
The main field now points to wakatime.app.mjs. Without a "files" array or an .npmignore, you may unintentionally omit or include extra files in the published package. Consider adding a "files" whitelist for the component.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 848305f and abded72.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • components/wakatime/.gitignore (0 hunks)
  • components/wakatime/actions/fetch-daily-heartbeats/fetch-daily-heartbeats.mjs (1 hunks)
  • components/wakatime/actions/list-projects/list-projects.mjs (1 hunks)
  • components/wakatime/actions/log-coding-activity/log-coding-activity.mjs (1 hunks)
  • components/wakatime/app/wakatime.app.ts (0 hunks)
  • components/wakatime/package.json (1 hunks)
  • components/wakatime/sources/common/base.mjs (1 hunks)
  • components/wakatime/sources/new-commit-created/new-commit-created.mjs (1 hunks)
  • components/wakatime/sources/new-commit-created/test-event.mjs (1 hunks)
  • components/wakatime/sources/new-goal-created/new-goal-created.mjs (1 hunks)
  • components/wakatime/sources/new-goal-created/test-event.mjs (1 hunks)
  • components/wakatime/sources/new-project-created/new-project-created.mjs (1 hunks)
  • components/wakatime/sources/new-project-created/test-event.mjs (1 hunks)
  • components/wakatime/wakatime.app.mjs (1 hunks)
💤 Files with no reviewable changes (2)
  • components/wakatime/app/wakatime.app.ts
  • components/wakatime/.gitignore
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Lint Code Base
🔇 Additional comments (11)
components/wakatime/sources/new-commit-created/new-commit-created.mjs (1)

1-39: Well-structured component with good separation of concerns.

The component follows good practices by:

  • Extending a common base component for code reuse
  • Including documentation link in the description
  • Properly defining methods with single responsibilities
  • Using proper deduplication strategy for commit events

The implementation will effectively detect and emit new commit events from WakaTime.

components/wakatime/actions/log-coding-activity/log-coding-activity.mjs (1)

122-146: LGTM! The run method correctly maps properties and handles API interactions

The implementation properly transforms camelCase property names to snake_case for the API request and provides a clear success message.

components/wakatime/actions/fetch-daily-heartbeats/fetch-daily-heartbeats.mjs (1)

25-27: Nice summary message with proper grammar handling!

The summary message correctly handles singular/plural cases for the heartbeat count.

components/wakatime/sources/new-goal-created/new-goal-created.mjs (1)

1-22: LGTM! Clean implementation leveraging common base source

The source component follows good practices by:

  1. Extending the common base source for consistent behavior
  2. Implementing only goal-specific functionality
  3. Setting appropriate deduplication strategy
  4. Including a sample event for testing
components/wakatime/sources/new-project-created/new-project-created.mjs (1)

1-22: Clean and well-structured source component implementation.

The component properly extends the common base module and implements the required methods. The pattern of extending a common base promotes code reuse and consistency across source components.

Good job on providing:

  • Clear naming and description with documentation link
  • Properly implemented getResourceFn() and getSummary() methods
  • Appropriate deduplication strategy
components/wakatime/package.json (2)

15-16: Dependency version alignment
You've added "@pipedream/platform": "^3.0.3". Verify that this matches the version used by other components to avoid runtime conflicts or duplicate installations.


3-3:

✅ Verification successful

Version bump to 0.1.0 – verify consistency across components
The version was updated from 0.0.3 to 0.1.0. Please ensure that release notes, changelogs, and any references in other packages or documentation are updated accordingly.

Could you run:

to confirm there are no lingering pins to 0.0.3?


🏁 Script executed:

#!/bin/bash
# Verify no remaining references to the old version
rg -l '"version": "0.0.3"' -g '*.json'

Length of output: 6827


Version bump to 0.1.0 confirmed
No lingering references to 0.0.3 in components/wakatime/package.json. Other packages remain at 0.0.3 as expected. Please update the changelog, release notes, and any documentation to reflect this new version.

components/wakatime/sources/new-project-created/test-event.mjs (2)

1-16: Approve new test event fixture
The object includes all expected fields from the WakaTime API response and can serve as the sampleEmit fixture for the "new-project-created" source.


2-2: Verify the id field usage
The id property is an empty string in this fixture. Ensure this aligns with the deduplication/tracking logic in your source component—blank IDs may lead to duplicate event emissions if not handled explicitly.

components/wakatime/sources/new-commit-created/test-event.mjs (2)

1-32: Approve new commit test event
The fixture exports a comprehensive commit object matching the WakaTime API and is ready for use as the sampleEmit in the "new-commit-created" source.


2-3: Verify id and hash fields
Both id and hash are empty strings here. Confirm that your event-tracking/deduplication logic in the source component can handle blank values without unintended duplications.

@michelle0927 michelle0927 merged commit 26413b6 into master May 15, 2025
11 checks passed
@michelle0927 michelle0927 deleted the issue-15130 branch May 15, 2025 14:26
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] wakatime

3 participants