Skip to content
Merged
33 changes: 33 additions & 0 deletions .github/workflows/top-ranked-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Update Top Ranked Issues

on:
# For testing purposes (can be removed later)
pull_request:
schedule:
# Runs every day at 3:00 AM UTC
- cron: '0 3 * * *'

jobs:
run-script:
runs-on: ubuntu-latest

env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Check out the repository
uses: actions/checkout@v4 # This ensures the repository code is available

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

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

- name: Run update_top_ranking_issues.py
run: |
python ./scripts/update_top_ranking_issues.py
66 changes: 66 additions & 0 deletions scripts/update_top_ranking_issues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os
from datetime import datetime, timedelta

from github import Github
from github.Issue import Issue
from github.Repository import Repository


def main():
start_time: datetime = datetime.now()

# --- Initialization ---
# GitHub Workflow will pass in the token as an environment variable,
# but we can place it in our env when running the script locally,
# for convenience
local_github_token: str | None = None
github_token: str | None = (
local_github_token or os.getenv("GITHUB_ACCESS_TOKEN")
)
github = Github(github_token)

# repository name
repo_name: str = "pvlib/pvlib-python"
repository: Repository = github.get_repo(repo_name)

# Rate limiting
remaining_requests_before: int = github.rate_limiting[0]
print(f"Remaining requests before: {remaining_requests_before}")

# --- Actions ---
# Get sorted issues
query: str = (
f'repo:{repository.full_name} is:open is:issue sort:reactions-+1-desc'
)
issues = github.search_issues(query)

# Format markdown
ranked_issues = []
for i, issue in enumerate(issues):
markdown_bullet_point: str = (
f"{issue.html_url} " +
f"({issue._rawData['reactions']['+1']} :thumbsup:)"
)

markdown_bullet_point = f"{i + 1}. {markdown_bullet_point}"
ranked_issues.append(markdown_bullet_point)

if i >= 19:
break

# edit top issues
top_issues_card: Issue = repository.get_issue(number=2196)
header = "Top Ranking Issues"
new_body = header + "\n" + "\n".join(ranked_issues)
top_issues_card.edit(
body=new_body
)

print(top_issues_card.body)

run_duration: timedelta = datetime.now() - start_time
print(run_duration)


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