[+] Script to list unmerged pr
This commit is contained in:
parent
2af034697c
commit
7d26a8e60c
3 changed files with 63 additions and 0 deletions
80
merging/accept_upstream.py
Normal file
80
merging/accept_upstream.py
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import os
|
||||
import shlex
|
||||
from subprocess import check_output
|
||||
|
||||
import pyperclip
|
||||
import requests
|
||||
from github import Github
|
||||
|
||||
upstream = 'dylanaraps/neofetch'
|
||||
my_fork = 'hykilpikonna/hyfetch'
|
||||
my_base = 'master'
|
||||
# gh_token = os.environ['GH_TOKEN']
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Helper for accepting upstream pull requests')
|
||||
parser.add_argument('pull', type=int, help='Pull request number')
|
||||
args = parser.parse_args()
|
||||
pr = args.pull
|
||||
|
||||
print(f'Accepting pull request {pr}...')
|
||||
|
||||
# Fetch original pr's information
|
||||
info = requests.get(f'https://api.github.com/repos/{upstream}/pulls/{pr}').json()
|
||||
# print(info)
|
||||
head = info['head']['repo']['full_name']
|
||||
head_br = info['head']['ref']
|
||||
head_lbl = info['head']['label']
|
||||
user = info['user']['login']
|
||||
print()
|
||||
print('Original Pull Request Info:')
|
||||
print('> State:', info['state'])
|
||||
print('> Title:', info['title'])
|
||||
print('> User:', user)
|
||||
print('> Created:', info['created_at'])
|
||||
print('> Head:', head, head_br, head_lbl)
|
||||
|
||||
# Fetch commit information
|
||||
commits = requests.get(f'https://api.github.com/repos/{upstream}/pulls/{pr}/commits').json()
|
||||
author = commits[0]['commit']['author']
|
||||
|
||||
# Fetch head branch
|
||||
print()
|
||||
print('Fetching head branch...')
|
||||
os.system(f'git fetch https://github.com/{head} {head_br}')
|
||||
|
||||
# Merge head branch
|
||||
print()
|
||||
print('Merging fetch_head...')
|
||||
title = info["title"].replace('"', '\\"')
|
||||
os.system(f'git merge FETCH_HEAD --no-ff --no-edit '
|
||||
f'-m "[PR] {upstream}#{pr} from {user} - {title}" '
|
||||
f'-m "Upstream PR: https://github.com/{upstream}/pull/{pr} \n'
|
||||
f'Thanks to @{user}\n\n'
|
||||
f'Co-authored-by: {author["name"]} <{author["email"]}>"')
|
||||
|
||||
# Push
|
||||
print()
|
||||
print('Pushing...')
|
||||
os.system('git push')
|
||||
|
||||
# Get commit SHA
|
||||
sha = check_output(shlex.split('git rev-parse --short HEAD')).decode().strip()
|
||||
|
||||
# Copy comment to clipboard
|
||||
comment = f"""
|
||||
Thank you for your contribution!
|
||||
|
||||
This PR is [merged into hyfetch](https://github.com/hykilpikonna/hyfetch/commit/{sha}) since this repo (dylanaraps/neofetch) seems no longer maintained.
|
||||
|
||||
[HyFetch](https://github.com/hykilpikonna/hyfetch) is a fork of neofetch with LGBTQ pride flags, but the repo also serves as an updated version of neofetch, addressing many pull requests that are not merged in the original repo.
|
||||
|
||||
Read the ["Running Updated Original Neofetch" section](https://github.com/hykilpikonna/hyfetch#running-updated-original-neofetch) for more info!
|
||||
"""
|
||||
pyperclip.copy(comment.strip())
|
||||
print()
|
||||
print('Done!')
|
||||
print('Comment response copied to clipboard.')
|
||||
48
merging/list_unresolved.py
Normal file
48
merging/list_unresolved.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import shlex
|
||||
from pathlib import Path
|
||||
from subprocess import check_output
|
||||
|
||||
from github import Github
|
||||
from github.PullRequest import PullRequest
|
||||
import ruamel.yaml as yaml
|
||||
|
||||
|
||||
def obtain_resolved():
|
||||
"""
|
||||
Obtain a list of resolved issues.
|
||||
"""
|
||||
prefix = 'dylanaraps/neofetch#'
|
||||
commits = check_output(shlex.split('git log --pretty=format:"%s"')).decode().strip().split('\n')
|
||||
commits = [(c, c.find(prefix)) for c in commits]
|
||||
commits = [(c, i+len(prefix)) for c, i in commits if i != -1]
|
||||
return sorted([int(c[i:c.find(' ', i)]) for c, i in commits])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Obtain a list of resolved issues
|
||||
resolved = set(obtain_resolved())
|
||||
|
||||
# Read the ignore-list
|
||||
with open(Path(__file__).parent / "pull_request_markings.yaml") as stream:
|
||||
ignore_list = yaml.safe_load(stream)['IgnoreList']
|
||||
|
||||
# Obtain a list of open issues
|
||||
g = Github(per_page=100)
|
||||
repo = g.get_repo('dylanaraps/neofetch')
|
||||
pager = repo.get_pulls(state='open')
|
||||
|
||||
# Filter only unresolved issues
|
||||
unresolved: list[PullRequest] = []
|
||||
for i in range(10000000):
|
||||
pulls: list[PullRequest] = pager.get_page(i)
|
||||
if len(pulls) == 0:
|
||||
break
|
||||
|
||||
unresolved += [p for p in pulls if p.number not in resolved and p.number not in ignore_list and not p.draft]
|
||||
if len(unresolved) > 50:
|
||||
break
|
||||
|
||||
unresolved.sort(key=lambda p: p.number)
|
||||
|
||||
# Print unresolved issues
|
||||
print('\n'.join(f'[{p.number}] {p.title} {p.html_url}' for p in unresolved))
|
||||
13
merging/pull_request_markings.yaml
Normal file
13
merging/pull_request_markings.yaml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Pull request that I don't plan on merging, or already merged pull request that the script didn't
|
||||
# detect.
|
||||
IgnoreList:
|
||||
# [2154] Added Support for Uwuntu
|
||||
2154: merged
|
||||
# [2156] Update neofetch (for macOS 13)
|
||||
2156: duplicate
|
||||
# [2152] created much cleaner void ascii art
|
||||
2152: merged
|
||||
# [2150] Add macOS 13 to version name list
|
||||
2150: merged
|
||||
# [2092] Update neofetch
|
||||
2092: troll
|
||||
Loading…
Add table
Add a link
Reference in a new issue