Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

endorsement_velocity_summary script #24618

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/issues-summary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Issues Summary

on:
schedule:
- cron: '0 0 * * 2' # Runs every Tuesday at midnight
workflow_dispatch:

jobs:
generate-summary:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests

- name: Run summary script
run: python scripts/generate_summary.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46 changes: 46 additions & 0 deletions scripts/generate_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import requests
import os
from datetime import datetime, timezone

GITHUB_API_URL = "https://api.github.com"
REPO = "microsoft/vscode-python"
TOKEN = os.getenv("GITHUB_TOKEN")


def fetch_issues():
headers = {"Authorization": f"token {TOKEN}"}
query = f"{GITHUB_API_URL}/repos/{REPO}/issues?state=open&per_page=100"
response = requests.get(query, headers=headers)
response.raise_for_status()
return response.json()


def calculate_thumbs_up_per_day(issue):
created_at = datetime.strptime(issue["created_at"], "%Y-%m-%dT%H:%M:%SZ")
now = datetime.now(timezone.utc)
days_open = (now - created_at).days or 1
thumbs_up = next(
(group["count"] for group in issue["reactions"] if group["content"] == "+1"), 0
)
return thumbs_up / days_open


def generate_markdown_summary(issues):
summary = "| URL | Title | 👍/day |\n| --- | ----- | ------ |\n"
for issue in issues:
thumbs_up_per_day = calculate_thumbs_up_per_day(issue)
summary += (
f"| {issue['html_url']} | {issue['title']} | {thumbs_up_per_day:.2f} |\n"
)
return summary


def main():
issues = fetch_issues()
summary = generate_markdown_summary(issues)
with open("endorsement_velocity_summary.md", "w") as f:
f.write(summary)


if __name__ == "__main__":
main()
Loading