Skip to content

Conversation

@LittleCodr
Copy link

@LittleCodr LittleCodr commented Nov 14, 2025

  • Guard the Wakatime summary percentage calculation against zero totals to prevent division errors.
  • Reuse a cached helper reference when building summary chunks to avoid repeated lookups.
  • Update [wakatime_service_test.rb] to assert on the :err key and cover the zero-total case.

Testing

docker compose run web rails test test/lib/wakatime_service_test.rb

Overview

  • add SlackActivityDigestSubscription model, service, and migration to store channel preferences
  • wire up GoodJob scheduler + worker to build and post daily digest blocks to Slack
  • expose management UI under my/activity_digest_subscription and surface link from Slack settings
  • document required SLACK_ACTIVITY_DIGEST_BOT_TOKEN in the README and add coverage for scheduler, service, and job payloads

Testing

  • docker compose run web rails test test/models/slack_activity_digest_subscription_test.rb
  • docker compose run web rails test test/services/slack_activity_digest_service_test.rb
  • docker compose run web rails test test/jobs/slack_activity_digest_job_test.rb

@LittleCodr LittleCodr changed the title Handle zero totals in Wakatime summary percentages Add Slack activity digest scheduling with GoodJob and fix zero-total percentage handling in Wakatime summaries Nov 14, 2025
@3kh0 3kh0 requested a review from Copilot November 14, 2025 14:21
Copy link
Member

@3kh0 3kh0 left a comment

Choose a reason for hiding this comment

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

Tests fail due to migrations

Error:
SlackActivityDigestSubscriptionTest#test_not_due_when_already_sent_today:
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_api_keys_on_token"
DETAIL:  Key (token)=(MyText) already exists.

Copilot finished reviewing on behalf of 3kh0 November 14, 2025 14:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds a scheduled Slack activity digest feature that posts daily coding summaries to Slack channels using GoodJob scheduling, and includes a defensive fix to prevent division-by-zero errors in Wakatime summary percentage calculations.

  • Introduces daily digest scheduling infrastructure with subscription management
  • Guards Wakatime percentage calculations against zero totals and optimizes helper lookups
  • Adds comprehensive test coverage for models, services, and jobs

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
app/models/slack_activity_digest_subscription.rb New model with timezone-aware delivery scheduling logic and validation
app/services/slack_activity_digest_service.rb Service to build digest blocks with user/project activity summaries
app/jobs/slack_activity_digest_scheduler_job.rb Hourly cron job to check and enqueue digest deliveries
app/jobs/slack_activity_digest_job.rb Worker to build and post digest messages to Slack API
app/controllers/my/activity_digest_subscriptions_controller.rb CRUD controller for user digest preference management
app/views/my/activity_digest_subscriptions/show.html.erb UI for configuring digest timezone and delivery hour
app/views/users/edit.html.erb Adds navigation link to digest preferences
config/routes.rb Registers digest subscription resource routes
config/initializers/good_job.rb Configures scheduler to run every hour at 15 minutes past
db/migrate/20251114120000_create_slack_activity_digest_subscriptions.rb Creates subscriptions table with channel and delivery settings
lib/wakatime_service.rb Fixes zero-division error in percentage calculation and caches helper reference
test/models/slack_activity_digest_subscription_test.rb Tests delivery scheduling logic across timezones and dates
test/services/slack_activity_digest_service_test.rb Tests digest block building with and without activity data
test/jobs/slack_activity_digest_job_test.rb Tests Slack API integration and subscription update
test/lib/wakatime_service_test.rb Updates assertion key from :error to :err and adds zero-total test
README.md Documents required SLACK_ACTIVITY_DIGEST_BOT_TOKEN environment variable

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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