From 0bbfdc4b32426f6933d23380f14db812b7589c44 Mon Sep 17 00:00:00 2001 From: kurt-rhee Date: Fri, 18 Oct 2024 13:26:25 -0700 Subject: [PATCH 01/10] reset top ranking issues --- scripts/update_top_ranking_issues.py | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 scripts/update_top_ranking_issues.py diff --git a/scripts/update_top_ranking_issues.py b/scripts/update_top_ranking_issues.py new file mode 100644 index 0000000000..7d735d3a1d --- /dev/null +++ b/scripts/update_top_ranking_issues.py @@ -0,0 +1,68 @@ +import json +import os +import pathlib +from collections import defaultdict +from datetime import datetime, timedelta +from typing import Optional + +from github import Github +from github.Issue import Issue +from github.Repository import Repository +from pytz import timezone + + +def main(): + start_time: datetime = datetime.now() + + # 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) + + # Rate limiting + remaining_requests_before: int = github.rate_limiting[0] + print(f"Remaining requests before: {remaining_requests_before}") + + + repo_name: str = "pvlib/pvlib-python" + repository: Repository = github.get_repo(repo_name) + + # 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} ({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() + print('done') + +# TODO: Sort label output into core and non core sections From 475a1667d68b580ce36376736ecbd4f98af58320 Mon Sep 17 00:00:00 2001 From: kurt-rhee Date: Fri, 18 Oct 2024 13:55:42 -0700 Subject: [PATCH 02/10] flake8 fixes --- scripts/update_top_ranking_issues.py | 34 +++++++++++++--------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/scripts/update_top_ranking_issues.py b/scripts/update_top_ranking_issues.py index 7d735d3a1d..fcfd0fa696 100644 --- a/scripts/update_top_ranking_issues.py +++ b/scripts/update_top_ranking_issues.py @@ -1,42 +1,45 @@ -import json import os -import pathlib -from collections import defaultdict from datetime import datetime, timedelta -from typing import Optional from github import Github from github.Issue import Issue from github.Repository import Repository -from pytz import timezone 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 + # 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_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}") - - repo_name: str = "pvlib/pvlib-python" - repository: Repository = github.get_repo(repo_name) - + # --- Actions --- # Get sorted issues - query: str = f'repo:{repository.full_name} is:open is:issue sort:reactions-+1-desc' + 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} ({issue._rawData["reactions"]["+1"]} :thumbsup:)" + f"{issue.html_url} " + + f"({issue._rawData["reactions"]["+1"]} :thumbsup:)" ) markdown_bullet_point = f"{i + 1}. {markdown_bullet_point}" @@ -45,7 +48,6 @@ def main(): if i >= 19: break - # edit top issues top_issues_card: Issue = repository.get_issue(number=2196) header = "Top Ranking Issues" @@ -60,9 +62,5 @@ def main(): print(run_duration) - if __name__ == "__main__": main() - print('done') - -# TODO: Sort label output into core and non core sections From 66685b134df1ff98f51f207c6e9afeec8deb18e5 Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Sat, 19 Oct 2024 17:37:55 +0200 Subject: [PATCH 03/10] Create top-ranked-issues.yml --- .github/workflows/top-ranked-issues.yml | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/top-ranked-issues.yml diff --git a/.github/workflows/top-ranked-issues.yml b/.github/workflows/top-ranked-issues.yml new file mode 100644 index 0000000000..b8cce80dad --- /dev/null +++ b/.github/workflows/top-ranked-issues.yml @@ -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 From 0cc31a35b0316927fd2a0600d49d6e7a85480d3d Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Sat, 19 Oct 2024 17:40:11 +0200 Subject: [PATCH 04/10] Update f-string formatting --- scripts/update_top_ranking_issues.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_top_ranking_issues.py b/scripts/update_top_ranking_issues.py index fcfd0fa696..f1ddd81c76 100644 --- a/scripts/update_top_ranking_issues.py +++ b/scripts/update_top_ranking_issues.py @@ -39,7 +39,7 @@ def main(): for i, issue in enumerate(issues): markdown_bullet_point: str = ( f"{issue.html_url} " + - f"({issue._rawData["reactions"]["+1"]} :thumbsup:)" + f"({issue._rawData['reactions']['+1']} :thumbsup:)" ) markdown_bullet_point = f"{i + 1}. {markdown_bullet_point}" From d4fccf834e736918075ce9c3501aeeafab9c90dc Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Sat, 19 Oct 2024 17:47:16 +0200 Subject: [PATCH 05/10] Change Cron job to every 10 minutes --- .github/workflows/top-ranked-issues.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/top-ranked-issues.yml b/.github/workflows/top-ranked-issues.yml index b8cce80dad..f901298d20 100644 --- a/.github/workflows/top-ranked-issues.yml +++ b/.github/workflows/top-ranked-issues.yml @@ -4,8 +4,12 @@ on: # For testing purposes (can be removed later) pull_request: schedule: - # Runs every day at 3:00 AM UTC - - cron: '0 3 * * *' + # # Runs every day at 3:00 AM UTC + # - cron: '0 3 * * *' + - cron: */10 * * * * + +permissions: + issues: write # This grants permission to create, update, and manage issues jobs: run-script: From e453984112cf12b79c4f641de5d541fed2b57e13 Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Sat, 19 Oct 2024 18:03:52 +0200 Subject: [PATCH 06/10] Add quotes to cron schedule --- .github/workflows/top-ranked-issues.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/top-ranked-issues.yml b/.github/workflows/top-ranked-issues.yml index 97ceffa941..cc47a418e8 100644 --- a/.github/workflows/top-ranked-issues.yml +++ b/.github/workflows/top-ranked-issues.yml @@ -6,7 +6,7 @@ on: schedule: # # Runs every day at 3:00 AM UTC # - cron: '0 3 * * *' - - cron: */10 * * * * + - cron: '*/10 * * * *' jobs: run-script: From 322e6592cdb0765c8c49f2d9afd093dd386b57d5 Mon Sep 17 00:00:00 2001 From: kurt-rhee Date: Sat, 19 Oct 2024 09:04:27 -0700 Subject: [PATCH 07/10] excluding the overview card from the ranked list and changing token name to GITHUB_TOKEN --- scripts/update_top_ranking_issues.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/update_top_ranking_issues.py b/scripts/update_top_ranking_issues.py index f1ddd81c76..335fff943e 100644 --- a/scripts/update_top_ranking_issues.py +++ b/scripts/update_top_ranking_issues.py @@ -15,7 +15,7 @@ def main(): # for convenience local_github_token: str | None = None github_token: str | None = ( - local_github_token or os.getenv("GITHUB_ACCESS_TOKEN") + local_github_token or os.getenv("GITHUB_TOKEN") ) github = Github(github_token) @@ -23,6 +23,10 @@ def main(): 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}") @@ -36,7 +40,12 @@ def main(): # Format markdown ranked_issues = [] - for i, issue in enumerate(issues): + for (i, issue) in zip(range(MAX_ISSUES), issues): + + # Don't include the overview card + if issue.number == TOP_ISSUES_CARD_NUMBER: + pass + markdown_bullet_point: str = ( f"{issue.html_url} " + f"({issue._rawData['reactions']['+1']} :thumbsup:)" @@ -45,11 +54,10 @@ def main(): 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) + 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( From 568ac3483e461f26bc5971423267174c68346e78 Mon Sep 17 00:00:00 2001 From: kurt-rhee Date: Sat, 19 Oct 2024 09:17:11 -0700 Subject: [PATCH 08/10] changed back to GITHUB_ACCESS_TOKEN --- scripts/update_top_ranking_issues.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_top_ranking_issues.py b/scripts/update_top_ranking_issues.py index 335fff943e..e30c802ac6 100644 --- a/scripts/update_top_ranking_issues.py +++ b/scripts/update_top_ranking_issues.py @@ -15,7 +15,7 @@ def main(): # for convenience local_github_token: str | None = None github_token: str | None = ( - local_github_token or os.getenv("GITHUB_TOKEN") + local_github_token or os.getenv("GITHUB_ACCESS_TOKEN") ) github = Github(github_token) From 2ffc6875d34c60892449f1239ef7b38ba732ad4f Mon Sep 17 00:00:00 2001 From: Kurt Rhee <33131958+kurt-rhee@users.noreply.github.com> Date: Sat, 19 Oct 2024 09:19:16 -0700 Subject: [PATCH 09/10] Update scripts/update_top_ranking_issues.py Co-authored-by: Echedey Luis <80125792+echedey-ls@users.noreply.github.com> --- scripts/update_top_ranking_issues.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/update_top_ranking_issues.py b/scripts/update_top_ranking_issues.py index e30c802ac6..6bb9fe93c7 100644 --- a/scripts/update_top_ranking_issues.py +++ b/scripts/update_top_ranking_issues.py @@ -40,18 +40,22 @@ def main(): # Format markdown ranked_issues = [] - for (i, issue) in zip(range(MAX_ISSUES), issues): - - # Don't include the overview card + # 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: - pass + continue + + # Get numbered list item index from generator + i = next(index_generator) markdown_bullet_point: str = ( f"{issue.html_url} " + f"({issue._rawData['reactions']['+1']} :thumbsup:)" ) - markdown_bullet_point = f"{i + 1}. {markdown_bullet_point}" + markdown_bullet_point = f"{i}. {markdown_bullet_point}" ranked_issues.append(markdown_bullet_point) # edit top issues From 7f1d15a69197d3e74b28dab9f42179315275f4c9 Mon Sep 17 00:00:00 2001 From: kurt-rhee Date: Sat, 19 Oct 2024 09:33:00 -0700 Subject: [PATCH 10/10] added break condnition on generator --- scripts/update_top_ranking_issues.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/update_top_ranking_issues.py b/scripts/update_top_ranking_issues.py index 6bb9fe93c7..3608d43344 100644 --- a/scripts/update_top_ranking_issues.py +++ b/scripts/update_top_ranking_issues.py @@ -1,4 +1,5 @@ import os +import itertools from datetime import datetime, timedelta from github import Github @@ -38,7 +39,7 @@ def main(): ) issues = github.search_issues(query) - # Format markdown + # Format ranked_issues = [] # Continuous number generator for the numbered list, starts at 1 index_generator = itertools.count(1) @@ -49,6 +50,8 @@ def main(): # Get numbered list item index from generator i = next(index_generator) + if i >= MAX_ISSUES: + break markdown_bullet_point: str = ( f"{issue.html_url} " +