-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprw.py
84 lines (73 loc) · 2.87 KB
/
prw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import click
import requests
from src.extracktor import json_extract
from src.graphqlapi import Queries
from src.prapi import run_query
@click.group()
def main():
"""
Work with GitHub pull requests.\n
prw <command> <argument> [options] [flags]
"""
@main.command()
@click.option('-t', '--tag', type=str, help="Search pull request by tag[case sensitive]")
@click.option('-s', '--state', type=click.Choice(['open', 'closed', 'merged']), required=True, help="Show recent merged pull request")
@click.option('-v', '--verbose', is_flag=True, help="enable verbose mode")
@click.option('-p', '--pages', type=int, default=1, help="Show result up to pages")
@click.argument('repos', type=str, required=True)
def repo(repos, state, pages, tag=None, verbose=False, ):
if pages > 3:
click.secho("You can not see more than 3 pages.!", fg='red', bold=True)
return
pages = pages*30
state = state.upper()
flag = True
stcolor = {"OPEN": "green", "CLOSED": "red", "MERGED": "yellow"}
try:
with open('config.ini', 'r') as cf:
token = cf.read()
if len(token) != 40:
raise Exception
except:
if flag:
click.secho('Please Verify Your github Token first.!',
bold=True, fg='red')
click.echo('Usage : auth <token> ')
else:
r = repos.split("/")
if len(r) < 2:
click.echo(click.secho("SyntaxError:", fg='red', bold=True) +
click.echo('invalid syntax for repo : username/repo_name'))
return
else:
result = run_query(
Queries(f"{r[0]}", f"{r[1]}", state, tag, pages).pulls(), token)
if verbose:
print("This feature has not been added yet..comming soon")
else:
click.secho(state, fg=stcolor[state], bold=True)
for i in result['data']['repository']['pullRequests']['nodes']:
number = json_extract(i, 'number')
title = json_extract(i, 'title')
totalCount = json_extract(i, 'totalCount')
lname = json_extract(i, 'name')
click.secho(
f"#{number[0]} ", fg=stcolor[state], bold=True, nl=False)
print(
f"Title :{title[0]} ----------> Comments :{totalCount[0]} ---------> labels{lname}")
@main.command()
@click.argument('token')
def auth(token):
""" Verify Api with GitHub token\n
example: prw.py auth <token>
"""
if len(token) == 40:
with open('config.ini', 'w') as cf:
cf.write(token)
click.secho('Verification Successfull 👍', fg='green', bold=True)
else:
click.secho('Incorrect token please retry..!', fg='red', bold=True)
def start():
main(obj={})
if __name__ == '__main__':
start()