Skip to content

Add WakaTime-compatible profile and summary endpoints - #1569

Open
skyfallwastaken wants to merge 3 commits into
mainfrom
fix/wakatime-api-compatibility
Open

Add WakaTime-compatible profile and summary endpoints#1569
skyfallwastaken wants to merge 3 commits into
mainfrom
fix/wakatime-api-compatibility

Conversation

@skyfallwastaken

@skyfallwastaken skyfallwastaken commented Aug 13, 2026

Copy link
Copy Markdown
Member

Summary of the problem

Hackatime's WakaTime-compatible API returned 404 responses for the current user profile and daily summary routes required by clients using a custom instance. This caused correctly configured clients to report that the provider was unavailable.

Describe your changes

  • Add authenticated current user profile and daily summary endpoints under /api/hackatime/v1
  • Build timezone-aware summaries with empty days, project breakdowns and AI counters

Screenshots / Media

N/A

Copilot AI lite review requested due to automatic review settings August 13, 2026 20:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds authenticated WakaTime-compatible profile and daily-summary endpoints, including timezone-aware aggregation and AI activity counters.

  • Adds current-user profile and inclusive daily-summary API routes.
  • Builds empty-day, project, cumulative, average, and AI telemetry summaries.
  • Corrects cross-project interval attribution by assigning each gap to its preceding heartbeat.
  • Adds request, controller, and OpenAPI coverage for the new endpoints.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously reported cross-project attribution issue is corrected by assigning each interval to its preceding heartbeat and is covered by the updated regression test.

Important Files Changed

Filename Overview
app/controllers/api/hackatime/v1/hackatime_controller.rb Adds authenticated profile and validated, timezone-aware summary actions.
app/models/concerns/heartbeatable.rb Centralizes capped-duration SQL and attributes daily intervals to their preceding heartbeats.
lib/wakatime_service.rb Builds inclusive daily summaries, project breakdowns, cumulative totals, averages, and AI counters.
config/routes.rb Exposes the two new WakaTime-compatible user routes.
test/controllers/api/hackatime/v1/hackatime_controller_test.rb Covers profile responses, daily aggregation, empty days, corrected project attribution, and invalid inputs.
spec/requests/api/hackatime/v1/compatibility_spec.rb Adds request-schema coverage for successful and failed compatibility API requests.
swagger/v1/swagger.yaml Documents the profile and summary endpoint contracts.

Sequence Diagram

sequenceDiagram
  participant Client as WakaTime Client
  participant Controller as HackatimeController
  participant Service as WakatimeService
  participant Heartbeats as Heartbeat Aggregation
  participant DB as PostgreSQL
  Client->>Controller: GET /users/current/summaries
  Controller->>Controller: Authenticate and validate dates/timezone
  Controller->>Service: generate_daily_summaries
  Service->>Heartbeats: daily_activity_summary_rows
  Heartbeats->>DB: Query ordered heartbeat intervals
  DB-->>Heartbeats: Daily project and AI aggregates
  Heartbeats-->>Service: Aggregated rows
  Service-->>Controller: WakaTime-compatible summary
  Controller-->>Client: 200 JSON
Loading

Reviews (3): Last reviewed commit: "Attribute summary gaps to preceding hear..." | Re-trigger Greptile

Comment thread lib/wakatime_service.rb Outdated
Comment on lines +213 to +214
WHEN LAG(time) OVER (PARTITION BY #{local_date_sql} ORDER BY time, id) IS NULL THEN 0
ELSE LEAST(time - LAG(time) OVER (PARTITION BY #{local_date_sql} ORDER BY time, id), #{timeout})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Cross-project gaps are misattributed

When a user alternates between projects or AI models during one day, the date-only LAG window assigns each cross-group gap to the later heartbeat's project and model, causing incorrect project and AI-model duration breakdowns.

Knowledge Base Used: Heartbeat Ingest

Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/wakatime_service.rb
Line: 213-214

Comment:
**Cross-project gaps are misattributed**

When a user alternates between projects or AI models during one day, the date-only `LAG` window assigns each cross-group gap to the later heartbeat's project and model, causing incorrect project and AI-model duration breakdowns.

**Knowledge Base Used:** [Heartbeat Ingest](https://app.greptile.com/mahadk/-/custom-context/knowledge-base/hackclub/hackatime/-/docs/heartbeat-ingest.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

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