From 2c61a6403bb4482bc60b0b674de85222a469bc35 Mon Sep 17 00:00:00 2001 From: Kurt Rhee <33131958+kurt-rhee@users.noreply.github.com> Date: Sat, 19 Oct 2024 09:47:10 -0700 Subject: [PATCH] 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 <80125792+echedey-ls@users.noreply.github.com> * added break condnition on generator --------- Co-authored-by: Adam R. Jensen <39184289+AdamRJensen@users.noreply.github.com> Co-authored-by: Echedey Luis <80125792+echedey-ls@users.noreply.github.com> --- .github/workflows/top-ranked-issues.yml | 3 +- scripts/update_top_ranking_issues.py | 81 +++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 scripts/update_top_ranking_issues.py diff --git a/.github/workflows/top-ranked-issues.yml b/.github/workflows/top-ranked-issues.yml index 9774643c8..cc47a418e 100644 --- a/.github/workflows/top-ranked-issues.yml +++ b/.github/workflows/top-ranked-issues.yml @@ -6,7 +6,8 @@ on: schedule: # # Runs every day at 3:00 AM UTC # - cron: '0 3 * * *' - - cron: */10 * * * * + - cron: '*/10 * * * *' + jobs: run-script: runs-on: ubuntu-latest diff --git a/scripts/update_top_ranking_issues.py b/scripts/update_top_ranking_issues.py new file mode 100644 index 000000000..3608d4334 --- /dev/null +++ b/scripts/update_top_ranking_issues.py @@ -0,0 +1,81 @@ +import os +import itertools +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) + + # Number of top issues to list + MAX_ISSUES = 19 + TOP_ISSUES_CARD_NUMBER = 2196 + + # 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 + ranked_issues = [] + # Continuous number generator for the numbered list, starts at 1 + index_generator = itertools.count(1) + for issue in issues: + # Don't include the overview card (skip to next iteration) + if issue.number == TOP_ISSUES_CARD_NUMBER: + continue + + # Get numbered list item index from generator + i = next(index_generator) + if i >= MAX_ISSUES: + break + + markdown_bullet_point: str = ( + f"{issue.html_url} " + + f"({issue._rawData['reactions']['+1']} :thumbsup:)" + ) + + markdown_bullet_point = f"{i}. {markdown_bullet_point}" + ranked_issues.append(markdown_bullet_point) + + # edit top issues + top_issues_card: Issue = repository.get_issue( + number=TOP_ISSUES_CARD_NUMBER + ) + 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()