Skip to content

Commit 2c61a64

Browse files
kurt-rheeAdamRJensenechedey-ls
authored
Top Ranking Issues (#2267)
* reset top ranking issues * flake8 fixes * Create top-ranked-issues.yml * Update f-string formatting * Change Cron job to every 10 minutes * Add quotes to cron schedule * excluding the overview card from the ranked list and changing token name to GITHUB_TOKEN * changed back to GITHUB_ACCESS_TOKEN * Update scripts/update_top_ranking_issues.py Co-authored-by: Echedey Luis <[email protected]> * added break condnition on generator --------- Co-authored-by: Adam R. Jensen <[email protected]> Co-authored-by: Echedey Luis <[email protected]>
1 parent f200e24 commit 2c61a64

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

.github/workflows/top-ranked-issues.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ on:
66
schedule:
77
# # Runs every day at 3:00 AM UTC
88
# - cron: '0 3 * * *'
9-
- cron: */10 * * * *
9+
- cron: '*/10 * * * *'
10+
1011
jobs:
1112
run-script:
1213
runs-on: ubuntu-latest

scripts/update_top_ranking_issues.py

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import os
2+
import itertools
3+
from datetime import datetime, timedelta
4+
5+
from github import Github
6+
from github.Issue import Issue
7+
from github.Repository import Repository
8+
9+
10+
def main():
11+
start_time: datetime = datetime.now()
12+
13+
# --- Initialization ---
14+
# GitHub Workflow will pass in the token as an environment variable,
15+
# but we can place it in our env when running the script locally,
16+
# for convenience
17+
local_github_token: str | None = None
18+
github_token: str | None = (
19+
local_github_token or os.getenv("GITHUB_ACCESS_TOKEN")
20+
)
21+
github = Github(github_token)
22+
23+
# repository name
24+
repo_name: str = "pvlib/pvlib-python"
25+
repository: Repository = github.get_repo(repo_name)
26+
27+
# Number of top issues to list
28+
MAX_ISSUES = 19
29+
TOP_ISSUES_CARD_NUMBER = 2196
30+
31+
# Rate limiting
32+
remaining_requests_before: int = github.rate_limiting[0]
33+
print(f"Remaining requests before: {remaining_requests_before}")
34+
35+
# --- Actions ---
36+
# Get sorted issues
37+
query: str = (
38+
f'repo:{repository.full_name} is:open is:issue sort:reactions-+1-desc'
39+
)
40+
issues = github.search_issues(query)
41+
42+
# Format
43+
ranked_issues = []
44+
# Continuous number generator for the numbered list, starts at 1
45+
index_generator = itertools.count(1)
46+
for issue in issues:
47+
# Don't include the overview card (skip to next iteration)
48+
if issue.number == TOP_ISSUES_CARD_NUMBER:
49+
continue
50+
51+
# Get numbered list item index from generator
52+
i = next(index_generator)
53+
if i >= MAX_ISSUES:
54+
break
55+
56+
markdown_bullet_point: str = (
57+
f"{issue.html_url} " +
58+
f"({issue._rawData['reactions']['+1']} :thumbsup:)"
59+
)
60+
61+
markdown_bullet_point = f"{i}. {markdown_bullet_point}"
62+
ranked_issues.append(markdown_bullet_point)
63+
64+
# edit top issues
65+
top_issues_card: Issue = repository.get_issue(
66+
number=TOP_ISSUES_CARD_NUMBER
67+
)
68+
header = "Top Ranking Issues"
69+
new_body = header + "\n" + "\n".join(ranked_issues)
70+
top_issues_card.edit(
71+
body=new_body
72+
)
73+
74+
print(top_issues_card.body)
75+
76+
run_duration: timedelta = datetime.now() - start_time
77+
print(run_duration)
78+
79+
80+
if __name__ == "__main__":
81+
main()

0 commit comments

Comments
 (0)