Generate weekly Slack report for projects in the org with configurable channel selection
This PR implements a weekly Slack report feature that automatically sends comprehensive project and repository statistics to organizations with Slack integration.
Changes Made
1. Management Command (slack_weekly_report.py)
Created a Django management command that generates and sends weekly reports including:
- Overview Statistics: Total projects, repositories (active/archived breakdown)
- Aggregate Metrics: Total stars, forks, open issues, and contributors across all repos
- Recently Updated Repositories: Top 10 repos updated in the last 7 days
- Project Breakdowns: Detailed information about projects with repository counts and status
The command uses efficient Django ORM queries with aggregates and annotations to prevent N+1 query problems and is timezone-aware for consistent datetime operations.
2. Weekly Cron Command (run_weekly.py)
Updated the existing run_weekly.py command to:
- Call the
slack_weekly_reportcommand - Follow the pattern from
run_daily.pyandrun_hourly.pyfor consistency - Allow easy addition of other weekly commands in the future
- Provide proper error handling and logging for weekly scheduled tasks
3. Configurable Report Channel
Added new fields to SlackIntegration model:
-
weekly_report_channel_name: Optional channel name for weekly reports -
weekly_report_channel_id: Optional channel ID for weekly reports - Falls back to
default_channel_idif weekly report channel is not configured - Allows organizations to send weekly reports to a dedicated channel separate from daily updates or other notifications
4. GitHub Actions Workflow (weekly-slack-report.yml)
Created an automated workflow that:
- Runs every Saturday at 1pm EST (6pm UTC) using cron schedule:
'0 18 * * 6' - Calls the
run_weeklycommand which executes all weekly scheduled tasks - Can be manually triggered via
workflow_dispatchfor testing - Sets up the required environment (PostgreSQL, Python 3.11, Poetry)
5. Tests (test_slack.py)
Added comprehensive test coverage for the weekly report functionality:
- Tests report generation and successful message sending
- Tests report content with and without projects
- Tests custom channel configuration
- Tests fallback to default channel behavior
- Proper mocking of Slack API interactions with specific module path patches
Technical Optimizations
- Single aggregate query with Q filters for efficient repo counting
- Count annotation for project repo counts (prevents N+1 queries)
- Configurable limits via class constants (MAX_RECENT_REPOS, MAX_PROJECTS_IN_REPORT, MAX_DESCRIPTION_LENGTH)
How It Works
The report is automatically sent to all organizations that have a Slack integration configured. Organizations can:
- Use the default channel for all Slack notifications (by not setting
weekly_report_channel_id) - Configure a specific channel for weekly reports (by setting
weekly_report_channel_idand optionallyweekly_report_channel_name)
The workflow runs the centralized run_weekly command, making it easy to add additional weekly scheduled tasks in the future.
- Fixes OWASP-BLT/BLT#2484
Original prompt
This section details on the original issue you should resolve
<issue_title>Generate a report that is sent to Slack Saturday at 1pm EST - weekly slack report of projects in the org </issue_title> <issue_description></issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes OWASP-BLT/BLT#2484
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.