|
| 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