Skip to content

devops-actions/github-user-stats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GitHub User Statistics

A Python-based tool to fetch and analyze GitHub user activity statistics, including pull requests, issues, and discussions. The tool can be run locally or automated via GitHub Actions.

Features

  • πŸ“Š Fetch comprehensive user activity statistics from GitHub
  • πŸ”„ Configurable lookback period (days)
  • πŸ“‹ Track pull requests, issues, and discussions
  • πŸ€– GitHub Actions workflow for automation
  • πŸ“ Detailed activity reports
  • πŸ’Ύ Export results as artifacts
  • πŸ“„ Automatic GitHub Actions step summary integration

Prerequisites

  • Python 3.11 or higher
  • GitHub Personal Access Token (PAT) with appropriate scopes:
    • repo (for private repositories)
    • read:user (for user data)
    • read:discussion (for discussions)

Installation

  1. Clone the repository:
git clone https://github.com/devops-actions/github-user-stats.git
cd github-user-stats
  1. Install dependencies:
pip install -r requirements.txt

Usage

Local Execution

Run the script with default settings (user: rajbos, lookback: 30 days):

export GITHUB_TOKEN=your_github_token_here
python fetch_user_stats.py

Custom Parameters

Specify a different user and lookback period:

python fetch_user_stats.py --username octocat --days 90

Or provide the token directly:

python fetch_user_stats.py --username rajbos --days 7 --token your_token_here

Command-Line Options

  • --username: GitHub username to fetch statistics for (default: rajbos)
  • --days: Number of days to look back (default: 30)
  • --token: GitHub personal access token (alternatively, use GITHUB_TOKEN environment variable)
  • --output-file: Optional path to write the output to a file instead of stdout

Save Output to File

Save the statistics report to a file:

python fetch_user_stats.py --username rajbos --days 30 --output-file report.txt

GitHub Actions Workflow

The repository includes a GitHub Actions workflow that automatically fetches user statistics.

Triggers

The workflow runs:

  • Manually: Via workflow dispatch in the Actions tab
  • Scheduled: Weekly on Mondays at 9 AM UTC
  • On Push: When the script or workflow files are modified

Manual Workflow Run

  1. Go to the Actions tab in your GitHub repository
  2. Select the "GitHub User Statistics" workflow
  3. Click "Run workflow"
  4. Optionally specify:
    • Username to analyze (default: rajbos)
    • Number of days to look back (default: 30)

Workflow Outputs

The workflow:

  1. Displays statistics in the GitHub Actions logs
  2. Generates a detailed report file
  3. Uploads the report as an artifact (retained for 30 days)
  4. Writes statistics to the GitHub Actions step summary (visible in the workflow run summary page)

GitHub Actions Step Summary

When running in GitHub Actions, the script automatically detects the GITHUB_STEP_SUMMARY environment variable and writes the statistics to both the console logs and the step summary. This provides an easy-to-read summary directly on the workflow run page without needing to download artifacts.

Download Artifacts

After a workflow run completes:

  1. Go to the workflow run summary page
  2. View the statistics in the step summary section at the bottom of the page
  3. Or scroll to the "Artifacts" section and download user-statistics-report for offline viewing

Example Output

================================================================================
GitHub User Statistics for @rajbos
Name: Rob Bos
Period: Last 30 days (since 2025-11-20)
================================================================================

πŸ“‹ Pull Requests: 15

Recent Pull Requests:
  βœ… devops-actions/load-used-actions
     Update dependency versions
     https://github.com/devops-actions/load-used-actions/pull/123 (2025-12-15)
  🟒 devops-actions/github-user-stats
     Add new statistics feature
     https://github.com/devops-actions/github-user-stats/pull/5 (2025-12-10)

πŸ› Issues: 8

Recent Issues:
  🟒 devops-actions/marketplace-checks
     Enhancement: Add support for new action types
     https://github.com/devops-actions/marketplace-checks/issues/45 (2025-12-18)

πŸ’¬ Discussions: 3

Recent Discussions:
  πŸ’¬ Best practices for GitHub Actions security
     https://github.com/community/discussions/67890 (2025-12-12)

================================================================================
Summary:
  Total Activity Items: 26
================================================================================

Security Considerations

  • Never commit your GitHub token to the repository
  • Use GitHub Secrets for storing tokens in workflows
  • The default GITHUB_TOKEN provided by GitHub Actions has appropriate permissions for public repositories
  • For private repositories, you may need to create a PAT with additional scopes

Configuration

GitHub Actions Secrets

The workflow uses secrets.GITHUB_TOKEN, which is automatically provided by GitHub Actions. No additional configuration is needed for public repositories.

For enhanced permissions or private repositories, create a PAT and add it as a secret named GITHUB_TOKEN in your repository settings.

Customization

Modify the Lookback Period

Edit the default value in the workflow file (.github/workflows/user-stats.yml):

inputs:
  days:
    description: 'Number of days to look back'
    required: false
    default: '30'  # Change this value

Change the Default User

Update the default username in the workflow file:

inputs:
  username:
    description: 'GitHub username to analyze'
    required: false
    default: 'rajbos'  # Change this value

Troubleshooting

Authentication Errors

If you encounter authentication errors:

  • Verify your token has the required scopes
  • Check that the token hasn't expired
  • Ensure the GITHUB_TOKEN environment variable is set correctly

Rate Limiting

GitHub API has rate limits:

  • Authenticated requests: 5,000 requests per hour
  • The script uses GraphQL API which is more efficient
  • If you hit rate limits, wait before retrying or reduce the lookback period

No Data Returned

If no activity is found:

  • Verify the username is correct
  • Check if there's activity in the specified time period
  • Ensure the token has access to view the user's activity

Data Limitations

The script fetches the most recent 100 items of each type (pull requests, issues, discussions):

  • For very active users, some older items within the time period may not be included
  • This is a limitation of the GitHub GraphQL API query structure
  • The 100-item limit per type typically covers most use cases
  • If you need complete historical data, consider reducing the lookback period

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Maintained by DevOps Actions

About

No description, website, or topics provided.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

 
 
 

Contributors

Languages