Last active
June 15, 2024 09:26
-
-
Save phwelo/3500783cd9f8652ed0dbd472b7139b00 to your computer and use it in GitHub Desktop.
jifi rofi jira menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from jira import JIRA | |
from rofi import Rofi | |
from subprocess import Popen, DEVNULL | |
r = Rofi() | |
browser_path = "vivaldi-stable" | |
jira_uri = 'https://company.atlassian.net' | |
api_token = 'https://id.atlassian.com/manage/api-tokens' # go here and generate one | |
username = '[email protected]' | |
project = 'XYZK' | |
auth_jira = JIRA(jira_uri, basic_auth=(username, api_token)) | |
project_query = 'project=' + project | |
issues = auth_jira.search_issues(project_query) | |
rofi_list = [] | |
for issue in issues: | |
rofi_list.append(issue.key + ':' + issue.fields.summary) | |
index, key = r.select('What Issue?', rofi_list, rofi_args=['-i']) | |
if index < 0: | |
exit(1) | |
ticket_number = rofi_list[index].split(":")[0] | |
uri = auth_jira.issue(ticket_number).permalink() | |
Popen(['nohup', browser_path, uri], stdout=DEVNULL, stderr=DEVNULL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from jira import JIRA | |
from rofi import Rofi | |
from subprocess import Popen, DEVNULL | |
import asyncio | |
# make our rofi object | |
r = Rofi() | |
# defaults | |
browser_path = "vivaldi-stable" | |
jira_uri = 'https://company.atlassian.net' | |
api_token = 'https://id.atlassian.com/manage/api-tokens' # go here and generate one | |
username = '[email protected]' | |
project = 'XYZK' | |
menu_choices = ['all board tickets', 'triage incoming issues', 'my mine assigned tickets'] | |
assigned_user = username.split('@')[0] | |
triage_label = 'Triage' | |
def jira_auth(uri, user, token): | |
return JIRA(jira_uri, basic_auth=(username, api_token)) | |
async def async_runner(): | |
coroutines = [ | |
get_jira_issues(project), | |
rofi_frontmenu(menu_choices) | |
] | |
results = await asyncio.gather(*coroutines) | |
return results | |
@asyncio.coroutine | |
async def get_jira_issues(project): | |
'''search out our project's tickets''' | |
return auth_jira.search_issues('project=' + project) | |
def rofi_choose_issue(issues): | |
'''generate the rofi menu and accept user's input''' | |
def rofi_prompt(query, list_items): | |
return r.select(query, list_items, rofi_args=['-i']) | |
rofi_list = [] | |
for issue in issues: | |
rofi_list.append(issue.key + ':' + issue.fields.summary) | |
index, ___ = rofi_prompt('Which Issue?', rofi_list) | |
# if rofi was cancelled, fail gracefully | |
exit(1) if index < 0 else None | |
# only return the part containing ticket number | |
return rofi_list[index].split(":")[0] | |
def browse_uri(uri, browser_path): | |
'''take the browser and the uri and make it happen''' | |
Popen(['nohup', browser_path, uri], stdout=DEVNULL, stderr=DEVNULL) | |
@asyncio.coroutine | |
async def rofi_frontmenu(choices): | |
return r.select('Main Menu', choices, rofi_args=['-i']) | |
def choose_query(index, tickets): | |
options = { | |
0:all_board_tickets(tickets), | |
1:triage_incoming_issues(tickets), | |
2:my_assigned_tickets(tickets) | |
} | |
return options[index] | |
def triage_incoming_issues(tickets): | |
triage_tix = [] | |
for ticket in tickets: | |
if triage_label in ticket.__dict__['raw']['fields']['status']['name']: | |
triage_tix.append(ticket) | |
return [triage_tix] | |
def my_assigned_tickets(tickets): | |
assigned_tix = [] | |
for ticket in tickets: | |
if ticket.__dict__['raw']['fields'].get('assignee'): | |
if ticket.__dict__['raw']['fields']['assignee']['name'] in assigned_user: | |
assigned_tix.append(ticket) | |
return [assigned_tix] | |
# just here for good looks | |
def all_board_tickets(tickets): | |
return [tickets] | |
if __name__== "__main__": | |
global auth_jira | |
auth_jira = JIRA(jira_uri, basic_auth=(username, api_token)) | |
loop = asyncio.get_event_loop() | |
result = loop.run_until_complete(async_runner()) | |
loop.close() | |
# the loop returns an array of the async def's return values | |
# so we end up doing this goofy reference below | |
refined_list = choose_query(result[1][0], result[0]) | |
ticket_number = rofi_choose_issue(refined_list[0]) | |
uri = auth_jira.issue(ticket_number).permalink() | |
browse_uri(uri, browser_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added a second version using a primary menu along with asyncio to expand functionality and mask the long load time of API data. Now feels more responsive, though still loads slow initially.