-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcodebase
More file actions
executable file
·81 lines (61 loc) · 1.98 KB
/
Copy pathcodebase
File metadata and controls
executable file
·81 lines (61 loc) · 1.98 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
#!/usr/bin/env python
import argparse
import logging
import pprint
from terminaltables import AsciiTable
from codebase.client import CodeBaseAPI
logger = logging.getLogger(__name__)
"""
Simple command-line interface to the Codebase API. Example usages:
codebase myproject all_notes 6
codebase myproject search "status:new"
Arguments:
1. project name
2. api function name
3. args to pass to the api function
Search:
codebase my_project search "status:code complete"
"""
def get_search_table_data(response):
table_headers = [
'#',
'Summary',
'Assignee',
]
return [table_headers] + [
[ticket['ticket']['ticket_id'], ticket['ticket']['summary'], ticket['ticket']['assignee']]
for ticket in response
]
def available_commands():
return [
name
for name in dir(CodeBaseAPI)
if name[0] != '_' and name[0].islower()
]
def main():
parser = argparse.ArgumentParser(description='Codebase command-line interface')
parser.add_argument('project', help='Codebase project name')
parser.add_argument('command', choices=available_commands(), help='A Codebase API command')
parser.add_argument('search_term', type=str, help='A Codebase API command')
args = parser.parse_args()
project = args.project
command = args.command
search_term = args.search_term
codebase = CodeBaseAPI(project=project)
try:
if command == 'search' and ':' in search_term:
k, v = search_term.split(':')
response = getattr(codebase, command)(**{k: v})
table_data = get_search_table_data(response)
table = AsciiTable(table_data)
print table.table
else:
response = getattr(codebase, command)()
pprint.pprint(response)
except Exception as e:
logger.error(e)
print('Error for [project] {} [command] {} [args] {}'.format(
project, command, args
))
if __name__ == "__main__":
main()