-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
94 lines (83 loc) · 2.81 KB
/
main.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
85
86
87
88
89
90
91
92
93
94
import argparse
import os
from jira import JIRA
from dotenv import load_dotenv
from actions.print_issues import print_issues
from actions.fetch_issues import fetch_issues
from actions.select_issue_with_fzf import select_issue_with_fzf
# Constants
ENV_FILE_PATH = os.path.join(os.path.dirname(__file__), ".env")
def get_jira_client(jira_server: str) -> JIRA:
"""Initialise and return the JIRA client."""
return JIRA(options={"server": jira_server}, token_auth=os.getenv("API_TOKEN"))
def main() -> None:
# Load environment vars
load_dotenv(ENV_FILE_PATH)
jira_server = os.getenv("JIRA_SERVER")
# Initialise JIRA client
jira_client = get_jira_client(jira_server=jira_server)
# Parse arguments
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--fzf", action="store_true", help="Pipe output to fzf")
parser.add_argument(
"-s",
"--sort",
action="store_true",
help="Sort issues by last updated in descending order",
)
parser.add_argument(
"-t",
"--time",
type=str,
help="Filter issues updated within the last [X] time period (e.g., 5d, 2w, 1m)",
)
parser.add_argument(
"-v", "--verbose", action="store_true", help="Enable verbose output"
)
parser.add_argument(
"-r", "--resolved", action="store_true", help="Fetch all resolved issues"
)
parser.add_argument(
"-a", "--all", action="store_true", help="Fetch all issues ever assigned to you"
)
parser.add_argument(
"-as",
"--assignee",
type=str,
default=jira_client.current_user(),
help='Specify an assignee username to filter issues assigned to them. Pass "none" to remove assignee filter entirely',
)
parser.add_argument(
"-rep",
"--reporter",
nargs="?",
const=jira_client.current_user(),
help="Specify a reporter username to filter issues reported by them. If used without a value, defaults to the current user.",
)
parser.add_argument(
"-m",
"--max",
type=int,
default=200,
help="Specify the max amount of issues to fetch (default is 200)",
)
args = parser.parse_args()
# Fetch issues
issues = fetch_issues(
jira_client,
sort_by_updated=args.sort,
time=args.time,
resolved=args.resolved,
verbose=args.verbose,
all_issues=args.all,
assignee=args.assignee.lower(),
reporter=args.reporter.lower() if args.reporter else None,
max_results=args.max,
)
# Display issues or select with fzf
if args.fzf:
select_issue_with_fzf(jira_server=jira_server, issues=issues)
else:
print_issues(jira_server=jira_server, issues=issues, verbose=args.verbose)
if __name__ == "__main__":
main()