Skip to content

feat: add stats subcommand to existing .github command#1729

Open
oskarnurm wants to merge 12 commits intopython-discord:mainfrom
DD2280-Group-16:feat/github-stats
Open

feat: add stats subcommand to existing .github command#1729
oskarnurm wants to merge 12 commits intopython-discord:mainfrom
DD2280-Group-16:feat/github-stats

Conversation

@oskarnurm
Copy link

@oskarnurm oskarnurm commented Feb 28, 2026

Relevant Issues

Closes #1724
Fixes #1728

Description

Added the subcommand stats to the existing command .github.

The statscommand will take the arguments <start_date> <end_date> <repo> where the date is formatted YY-MM-DD and repo follows the username/name format. The bot will then fetch and display GitHub stats for the given repo over the specified timeframe.

Example:
image

Key changes:

This was done by adding several helper methods to githubinfo.py that the stats command would then call:

  • get_issue_count
  • get_pr_count
  • get_commit_count
  • get_stars_gained
  • parse_date,
  • validate_date_format
  • validate_date_range

Did you:

* feat: rename file to follow project convention

* feat: add issue count method

* feat: return -1 if fetching issues failed
* feat: implemented get_commit_count metohd

* fix: fixed status code handling

* fix: fixed the potential excessive API calls by reading the links header

---------

Co-authored-by: Markus Selin <marselin@kth.sem>
* feat: add get_stars_gained

* refactor: optimize github API requests

---------

Co-authored-by: Ali Najib <anajib@kth.se>
Co-authored-by: Oskar Nurm <19738295+oskarnurm@users.noreply.github.com>
@oskarnurm oskarnurm marked this pull request as ready for review February 28, 2026 18:19
Selino10101 and others added 2 commits February 28, 2026 19:44
* feat: implemented validate methods

* fix: fixed validate methods to match the functionality of the command

* fix: removed the async since it isnt needed
* feat: implemented the validate methods into githubinfo.py

* feat: check date before API calls and simplify validate range

Checking valid input before API calls is smarter as we can prevent someone rate limiting the bot this way. We also don't need to guard  against future calls as GitHub will just happily return all the issues up to the present moment.

---------

Co-authored-by: oskarnurm <19738295+oskarnurm@users.noreply.github.com>
Copy link
Member

@jb3 jb3 left a comment

Choose a reason for hiding this comment

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

Feedback comments left.

Please also revert the linting changes you've made to the repository, none of the linting tools we use should've raised errors providing you are using the versions we specify in our pyproject.toml and are using uv & ruff is picking up our configuration correctly.

@oskarnurm
Copy link
Author

Thank you @jb3 for the extensive review. I apologize for the headache with the linting. Turns out I was wrong to trust ruff to pick up the pyproject.toml. We will look into fixing the other comments ASAP!

* fix: raise exceptions for errors instead of integers

* fix: use literals when passing arguments

* fix: not pass headers around and add a few missing exception raises

* chore: update pydis_core

* refactor: refine error handling
@oskarnurm
Copy link
Author

Hey @jb3, I think I have resolved all the issues now. Hopefully didn't miss anything.

Key changes:

  • Raising errors instead of returning integers using custom GithubAPIError and StargazersLimitError
  • Refactored date parsing with ISODateTime
  • Refactored github_stats with try-catch error handling
  • Bumped pydis_core to 11.9.0, also pydantic as a dependency (let me know how you want to handle this)
  • Refactored get_stars_gained with a helper method get_date_with_cache

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.

Bug Fix: Automatic issue linking escaping inline codeblocks feature: Add a !stats command for stats on Python discord repos

6 participants