-
Notifications
You must be signed in to change notification settings - Fork 0
/
jira_query.py
executable file
·76 lines (58 loc) · 1.66 KB
/
jira_query.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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import argparse
import logging
import os
import jinja2
import jira
import yaml
import json
def list_issues(my_jira, jql):
return my_jira.search_issues(jql, maxResults=False)
def main():
parser = argparse.ArgumentParser(
description="Query Jira",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"--config",
default="~/.jira_query.yaml",
help="Config file",
)
parser.add_argument(
"--template",
default="templates/default.md.j2",
help="Jinja2 template",
)
parser.add_argument(
"--debug",
"-d",
action="store_true",
help="Show debug output",
)
parser.add_argument(
"query",
help="Jira query",
)
args = parser.parse_args()
if args.debug:
logging.basicConfig(level=logging.DEBUG)
logging.debug("Argumets are %s" % args)
args.config = os.path.expanduser(args.config)
with open(args.config, "r") as fd:
my_config = yaml.load(fd, Loader=yaml.Loader)
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(args.template))
)
template = env.get_template(os.path.basename(args.template))
my_jira = jira.JIRA(
my_config["server"]["url"],
token_auth=my_config["server"]["auth"]["token_auth"],
)
issues = list_issues(my_jira, args.query)
print(template.render({"issues": issues}))
###for i in issues:
### with open(f"issue-{i.key}.json", "w") as fd:
### json.dump(i.raw, fd, indent=4, sort_keys=False)
if __name__ == "__main__":
main()