[+] PR statistics feature

This commit is contained in:
Azalea (on HyDEV-Daisy) 2022-08-11 23:14:16 -04:00
parent 503cc3ec98
commit 39e5dd0471
2 changed files with 37 additions and 16 deletions

View file

@ -1,12 +1,15 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import math
import os
import shlex import shlex
from collections import Counter
from pathlib import Path from pathlib import Path
from subprocess import check_output from subprocess import check_output
from github import Github from github import Github
from github.PullRequest import PullRequest from github.PullRequest import PullRequest
import ruamel.yaml as yaml import ruamel.yaml as yaml
from hypy_utils.tqdm_utils import tq, pmap, tmap
def obtain_resolved(): def obtain_resolved():
@ -23,29 +26,45 @@ def obtain_resolved():
if __name__ == '__main__': if __name__ == '__main__':
# Obtain a list of resolved issues # Obtain a list of resolved issues
resolved = set(obtain_resolved()) resolved = set(obtain_resolved())
print(f'There are {len(resolved)} resolved PRs')
# Read the ignore-list # Read the ignore-list
with open(Path(__file__).parent / "pull_request_markings.yaml") as stream: with open(Path(__file__).parent / "pull_request_markings.yaml") as stream:
ignore_list = yaml.safe_load(stream)['IgnoreList'] ignore_list: dict[int, str] = yaml.safe_load(stream)['IgnoreList']
ignore_list.update({r: 'merged' for r in resolved})
# Obtain a list of open issues # Obtain a list of open issues
g = Github(per_page=100) g = Github(per_page=100, login_or_token=os.environ.get('GH_TOKEN'))
repo = g.get_repo('dylanaraps/neofetch') repo = g.get_repo('dylanaraps/neofetch')
pager = repo.get_pulls(state='open') pager = repo.get_pulls(state='all')
# Filter only unresolved issues # Filter only unresolved issues
unresolved: list[PullRequest] = [] pages = list(range(math.ceil(pager.totalCount // 100) + 1))
for i in range(10000000): pulls: list[list[PullRequest]] = tmap(pager.get_page, pages, desc='Crawling pull requests...', unit='page')
pulls: list[PullRequest] = pager.get_page(i) pulls: set[PullRequest] = {p for lst in pulls for p in lst}
if len(pulls) == 0: unresolved: set[PullRequest] = {p for p in pulls if p.number not in resolved and p.number not in ignore_list}
break
unresolved += [p for p in pulls if p.number not in resolved and p.number not in ignore_list and not p.draft] # Filter merged / closed
if len(unresolved) > 50: draft = {p for p in unresolved if p.draft}
break unresolved -= draft
merged = {p for p in unresolved if p.merged_at}
unresolved -= merged
closed = {p for p in unresolved if p.state == 'closed'}
unresolved -= closed
unresolved.sort(key=lambda p: p.number) ignore_counter = Counter(ignore_list.values())
hyfetch_merged = ignore_counter.pop('merged')
print(f'Pull Request Statistics:')
print(f'> {hyfetch_merged} PRs merged by HyFetch')
print('\n'.join(f'> {c} PRs closed as {v} by HyFetch' for v, c in sorted(ignore_counter.items(), key=lambda x: -x[1])))
print()
print(f'> {len(draft)} PR drafts')
print(f'> {len(merged)} PRs merged by neofetch')
print(f'> {len(closed)} PRs closed without merging')
print()
print(f'> {len(unresolved)} open PRs that needs to be addressed:')
print()
opened = sorted(list(unresolved), key=lambda p: p.number)
# Print unresolved issues # Print unresolved issues
print('\n'.join(f'[{p.number}] {p.title} {p.html_url}' for p in unresolved)) print('\n'.join(f'[{p.number}] {p.title} {p.html_url}' for p in opened))

View file

@ -34,7 +34,7 @@ IgnoreList:
# [1861] Added FriendlyOS # [1861] Added FriendlyOS
1861: bad 1861: bad
# [1857] Speed up `get_packages` # [1857] Speed up `get_packages`
1857: disagree 1857: bad
# [1852] Added Aravalli Logo # [1852] Added Aravalli Logo
1852: deleted 1852: deleted
# [1850] neofetch: remove duplicate distro ASCII logo # [1850] neofetch: remove duplicate distro ASCII logo
@ -43,3 +43,5 @@ IgnoreList:
1830: deleted 1830: deleted
# [1827] Improve manjaro logo # [1827] Improve manjaro logo
1827: deleted 1827: deleted
# [1585] Fix for Improvement idea for multiprocessor systems, current output is unclear
1585: incorrect