Add JQLPrompt class
This commit is contained in:
parent
1e2ff25411
commit
bc2fad47e2
|
@ -47,7 +47,7 @@ class JQLLexer(RegexLexer):
|
||||||
r"(?i)\b(?:Assignee|affectedVersion|Attachments|Category|Comment|Component|Created|createdDate|"
|
r"(?i)\b(?:Assignee|affectedVersion|Attachments|Category|Comment|Component|Created|createdDate|"
|
||||||
r"Creator|Description|Due|duedate|Filter|fixVersion|issuekey|issuetype|issueLinkType|Labels|"
|
r"Creator|Description|Due|duedate|Filter|fixVersion|issuekey|issuetype|issueLinkType|Labels|"
|
||||||
r"lastViewed|Priority|Project|Reporter|Resolved|Sprint|Status|statusCategory|Summary|Text|"
|
r"lastViewed|Priority|Project|Reporter|Resolved|Sprint|Status|statusCategory|Summary|Text|"
|
||||||
r"timespent|Voter|Watcher|affectedVersion)\b",
|
r"timespent|Voter|Watcher)\b",
|
||||||
Name.Attribute,
|
Name.Attribute,
|
||||||
),
|
),
|
||||||
(r"(?i)(=|!=|<|>|<=|>=|~|!~|IN|NOT IN|IS|IS NOT|WAS|WAS IN|WAS NOT IN|WAS NOT)", Operator),
|
(r"(?i)(=|!=|<|>|<=|>=|~|!~|IN|NOT IN|IS|IS NOT|WAS|WAS IN|WAS NOT IN|WAS NOT)", Operator),
|
||||||
|
@ -137,7 +137,7 @@ completions = {
|
||||||
"THIS",
|
"THIS",
|
||||||
"TO",
|
"TO",
|
||||||
"WILL",
|
"WILL",
|
||||||
"WITH",
|
"WITH"
|
||||||
],
|
],
|
||||||
"Functions": [
|
"Functions": [
|
||||||
"issueHistory",
|
"issueHistory",
|
||||||
|
@ -157,7 +157,7 @@ completions = {
|
||||||
"startOfMonth",
|
"startOfMonth",
|
||||||
"endOfMonth",
|
"endOfMonth",
|
||||||
"startOfYear",
|
"startOfYear",
|
||||||
"endOfYear",
|
"endOfYear"
|
||||||
],
|
],
|
||||||
"Attributes": [
|
"Attributes": [
|
||||||
"assignee",
|
"assignee",
|
||||||
|
@ -186,7 +186,7 @@ completions = {
|
||||||
"text",
|
"text",
|
||||||
"timespent",
|
"timespent",
|
||||||
"voter",
|
"voter",
|
||||||
"watcher",
|
"watcher"
|
||||||
],
|
],
|
||||||
"Operators": [
|
"Operators": [
|
||||||
"=",
|
"=",
|
||||||
|
@ -204,7 +204,7 @@ completions = {
|
||||||
"WAS",
|
"WAS",
|
||||||
"WAS IN",
|
"WAS IN",
|
||||||
"WAS NOT IN",
|
"WAS NOT IN",
|
||||||
"WAS NOT",
|
"WAS NOT"
|
||||||
],
|
],
|
||||||
"Projects": [
|
"Projects": [
|
||||||
"QUANTUM",
|
"QUANTUM",
|
||||||
|
@ -216,8 +216,8 @@ completions = {
|
||||||
"COSMIC",
|
"COSMIC",
|
||||||
"LUNAR",
|
"LUNAR",
|
||||||
"ASTRAL",
|
"ASTRAL",
|
||||||
"PHOTON",
|
"PHOTON"
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -274,25 +274,6 @@ class JQLCompleter(Completer):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
query_count = 0
|
|
||||||
|
|
||||||
|
|
||||||
def get_query_count():
|
|
||||||
return [("class:bottom-toolbar", f"Query count: {query_count}")]
|
|
||||||
|
|
||||||
|
|
||||||
def create_jql_prompt_session(jira):
|
|
||||||
completer = JQLCompleter(completions)
|
|
||||||
return PromptSession(
|
|
||||||
lexer=PygmentsLexer(JQLLexer),
|
|
||||||
style=nord_style,
|
|
||||||
completer=completer,
|
|
||||||
validator=JQLValidator(jira),
|
|
||||||
rprompt="[b] Back [exit] Exit",
|
|
||||||
bottom_toolbar=get_query_count,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def load_config():
|
def load_config():
|
||||||
with open("config.json") as json_file:
|
with open("config.json") as json_file:
|
||||||
try:
|
try:
|
||||||
|
@ -306,38 +287,65 @@ def load_config():
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
class JQLPrompt:
|
||||||
global query_count
|
def __init__(self, jira, console):
|
||||||
config = load_config()
|
self.jira = jira
|
||||||
console = Console(color_system="truecolor")
|
self.console = console
|
||||||
jira = JIRA(server=config["server"], basic_auth=(config["username"], config["token"]))
|
self.session = self.create_jql_prompt_session()
|
||||||
jql = JQLPrinter(console)
|
self.jql = JQLPrinter(console)
|
||||||
session = create_jql_prompt_session(jira)
|
self.query_count = 0
|
||||||
while True:
|
|
||||||
try:
|
def get_query_count(self):
|
||||||
user_input = session.prompt("Enter JQL: ", validate_while_typing=False)
|
space = self.console.width // 4
|
||||||
|
query_count_str = f"Query count: {self.query_count}"
|
||||||
|
plain_text = f"{query_count_str:^{space}}{query_count_str:^{space}}{query_count_str:^{space}}{query_count_str:^{space}}"
|
||||||
|
return [("bg:#2E3440 #D8DEE9", plain_text)]
|
||||||
|
|
||||||
|
def create_jql_prompt_session(self):
|
||||||
|
completer = JQLCompleter(completions)
|
||||||
|
return PromptSession(
|
||||||
|
lexer=PygmentsLexer(JQLLexer),
|
||||||
|
style=nord_style,
|
||||||
|
completer=completer,
|
||||||
|
validator=JQLValidator(self.jira),
|
||||||
|
rprompt="[b] Back [exit] Exit",
|
||||||
|
bottom_toolbar=self.get_query_count,
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_input(self):
|
||||||
|
user_input = self.session.prompt("Enter JQL: ", validate_while_typing=False)
|
||||||
if user_input.lower() == "b":
|
if user_input.lower() == "b":
|
||||||
continue
|
return
|
||||||
if user_input.lower() == "exit":
|
if user_input.lower() == "exit":
|
||||||
break
|
exit(0)
|
||||||
issues = jira.search_issues(user_input)
|
issues = self.jira.search_issues(user_input)
|
||||||
if issues:
|
if issues:
|
||||||
query_count += 1
|
self.query_count += 1
|
||||||
console.print(
|
self.console.print(
|
||||||
RichText.assemble(
|
RichText.assemble(
|
||||||
(f"[+] Found {len(issues)} issues from JQL query: ", "green bold"),
|
(f"[+] Found {len(issues)} issues from JQL query: ", "green bold"),
|
||||||
jql.pygments_to_rich(user_input),
|
self.jql.pygments_to_rich(user_input),
|
||||||
),
|
),
|
||||||
end="",
|
end="",
|
||||||
)
|
)
|
||||||
for issue in issues:
|
for issue in issues:
|
||||||
console.print(f"{issue.key}: {issue.fields.summary}")
|
self.console.print(f"{issue.key}: {issue.fields.summary}")
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
def run(self):
|
||||||
continue
|
while True:
|
||||||
except EOFError:
|
try:
|
||||||
|
self.get_input()
|
||||||
|
except (EOFError, KeyboardInterrupt):
|
||||||
break
|
break
|
||||||
console.print("Goodbye!", style="#BF616A bold")
|
self.console.print("Goodbye!", style="#BF616A bold")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
config = load_config()
|
||||||
|
console = Console(color_system="truecolor")
|
||||||
|
jira = JIRA(server=config["server"], basic_auth=(config["username"], config["token"]))
|
||||||
|
prompt = JQLPrompt(jira, console)
|
||||||
|
prompt.run()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue