-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathprw.py
More file actions
96 lines (85 loc) · 2.54 KB
/
prw.py
File metadata and controls
96 lines (85 loc) · 2.54 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
import os
import click
from src.drivefunc import print_output
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,
):
"""This function checks the valid configuration
and calls the API on the given repository with arguments and options
and also prints the output
"""
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
try:
# read configuration from config.ini file
with open("config.ini", "r") as conf:
token = conf.read()
if len(token) != 40:
raise FileNotFoundError
except:
if flag:
click.secho("Please Verify Your github Token first.!", bold=True, fg="red")
click.echo("Usage : auth <token> ")
else:
repo_n = repos.split("/")
if len(repo_n) < 2:
click.echo(
click.secho("SyntaxError:", fg="red", bold=True)
+ click.echo("invalid syntax for repo : username/repo_name")
)
else:
col = int(list(os.get_terminal_size())[0])
result = run_query(
Queries(f"{repo_n[0]}", f"{repo_n[1]}", state, tag, pages).pulls(),
token,
)
print_output(result, verbose, state, col)
@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 conf:
conf.write(token)
click.secho("Verification Successfull 👍", fg="green", bold=True)
else:
click.secho("Incorrect token please retry..!", fg="red", bold=True)
def start():
"""
prw <command> <argument> [options] [flags]
"""
main()
if __name__ == "__main__":
start()